Module:Test
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+)")
local number = tonumber(numerator) / tonumber(denominator) or 0 -- Calculate the fraction
local percentages = {}
-- Original number
table.insert(percentages, dropRate)
-- Donator
local donator = tostring(math.ceil(number * 0.9)) .. "/" .. denominator
table.insert(percentages, donator)
-- Super donator
local superDonator = tostring(math.ceil(number * 0.8)) .. "/" .. denominator
table.insert(percentages, superDonator)
-- Extreme donator
local extremeDonator = tostring(math.ceil(number * 0.7)) .. "/" .. 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