Module:Test: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
-- This is a Lua module for MediaWiki | |||
-- It provides functionality to calculate percentages of a number | |||
-- Create a table to hold the functions | -- Create a table to hold the functions | ||
local Test = {} | local Test = {} | ||
Line 9: | Line 12: | ||
-- Parsing the drop rate | -- Parsing the drop rate | ||
local numerator, denominator = dropRate:match("(%d+)/(%d+)") | local numerator, denominator = dropRate:match("(%d+)/(%d+)") | ||
denominator = tonumber(denominator) or 1 -- Convert denominator to a number or default to 1 | |||
local percentages = {} | local percentages = {} | ||
Line 15: | Line 18: | ||
table.insert(percentages, dropRate) | table.insert(percentages, dropRate) | ||
-- Donator (90% of original drop rate) | -- Donator (90% of original drop rate) | ||
local | local donator = string.format("%d/%d", denominator - math.ceil(denominator * 0.1), denominator) | ||
table.insert(percentages, donator) | table.insert(percentages, donator) | ||
-- Super donator (80% of original drop rate) | -- Super donator (80% of original drop rate) | ||
local | local superDonator = string.format("%d/%d", denominator - math.ceil(denominator * 0.2), denominator) | ||
table.insert(percentages, superDonator) | table.insert(percentages, superDonator) | ||
-- Extreme donator (70% of original drop rate) | -- Extreme donator (70% of original drop rate) | ||
local | local extremeDonator = string.format("%d/%d", denominator - math.ceil(denominator * 0.3), denominator) | ||
table.insert(percentages, extremeDonator) | table.insert(percentages, extremeDonator) | ||
Revision as of 22:56, 3 April 2024
Documentation for this module may be created at Module:Test/doc
-- This is a Lua module for MediaWiki
-- It provides functionality to calculate percentages of a number
-- Create a table to hold the functions
local Test = {}
-- Function to calculate percentages
function Test.calculatePercentages(frame)
local args = frame.args
local dropRate = args[1] or "0/1" -- Extract the drop rate from the args, default to "0/1"
-- Parsing the drop rate
local numerator, denominator = dropRate:match("(%d+)/(%d+)")
denominator = tonumber(denominator) or 1 -- Convert denominator to a number or default to 1
local percentages = {}
-- Original number
table.insert(percentages, dropRate)
-- Donator (90% of original drop rate)
local donator = string.format("%d/%d", denominator - math.ceil(denominator * 0.1), denominator)
table.insert(percentages, donator)
-- Super donator (80% of original drop rate)
local superDonator = string.format("%d/%d", denominator - math.ceil(denominator * 0.2), denominator)
table.insert(percentages, superDonator)
-- Extreme donator (70% of original drop rate)
local extremeDonator = string.format("%d/%d", denominator - math.ceil(denominator * 0.3), denominator)
table.insert(percentages, extremeDonator)
-- Custom labels
local labels = {"Drop Rate", "Donator", "Super donator", "Extreme donator"}
-- Format the result as a table
local resultTable = "{| class=\"wikitable\"\n"
resultTable = resultTable .. "! " .. table.concat(labels, " !! ") .. "\n|-\n"
resultTable = resultTable .. "| " .. table.concat(percentages, " || ") .. "\n|}"
return resultTable
end
-- Export the module
return Test