Module:Test: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 8: | Line 8: | ||
function Test.calculatePercentages(frame) | function Test.calculatePercentages(frame) | ||
local args = frame.args | local args = frame.args | ||
local | 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 = {} | local percentages = {} | ||
-- Original number | -- Original number | ||
table.insert(percentages, number) | table.insert(percentages, number) | ||
-- | -- Donator | ||
table.insert(percentages, number - (number * 0.10)) | table.insert(percentages, number - (number * 0.10)) | ||
-- | -- Super donator | ||
table.insert(percentages, number - (number * 0.20)) | table.insert(percentages, number - (number * 0.20)) | ||
-- | -- Extreme donator | ||
table.insert(percentages, number - (number * 0.30)) | table.insert(percentages, number - (number * 0.30)) | ||
-- Custom labels | |||
local labels = {"Original", "Donator", "Super donator", "Extreme donator"} | |||
-- Format the result as a table | -- Format the result as a table | ||
local resultTable = "{| class=\"wikitable\"\n" | local resultTable = "{| class=\"wikitable\"\n" | ||
resultTable = resultTable .. "! | resultTable = resultTable .. "! Drop Rate !! " .. table.concat(labels, " !! ") .. "\n|-\n" | ||
resultTable = resultTable .. "| " .. | resultTable = resultTable .. "| " .. dropRate .. " || " .. table.concat(percentages, " || ") .. "\n|}" | ||
return resultTable | return resultTable |
Revision as of 22:49, 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+)")
local number = tonumber(numerator) / tonumber(denominator) or 0 -- Calculate the fraction
local percentages = {}
-- Original number
table.insert(percentages, number)
-- Donator
table.insert(percentages, number - (number * 0.10))
-- Super donator
table.insert(percentages, number - (number * 0.20))
-- Extreme donator
table.insert(percentages, number - (number * 0.30))
-- Custom labels
local labels = {"Original", "Donator", "Super donator", "Extreme donator"}
-- Format the result as a table
local resultTable = "{| class=\"wikitable\"\n"
resultTable = resultTable .. "! Drop Rate !! " .. table.concat(labels, " !! ") .. "\n|-\n"
resultTable = resultTable .. "| " .. dropRate .. " || " .. table.concat(percentages, " || ") .. "\n|}"
return resultTable
end
-- Export the module
return Test