Module:Calculator/ItemEconomy: Difference between revisions

m
Return table to represent data
m (Fix nil handling of input parameter)
m (Return table to represent data)
Line 41: Line 41:


return estimatedOutput, rowModifier > baseModifier
return estimatedOutput, rowModifier > baseModifier
end
local function addTableRow(tbl, c1, c2)
tbl:tag("tr")
:tag("th"):wikitext(c1)
:tag("td"):wikitext(c2)
return tbl
end
local function calculateFactor(a, b)
    local highest = math.max(a, b)
    local lowest = math.min(a, b)
    if lowest == 0 then
    -- This shouldn't ever be possible!
        error("Div by zero")
    end
    local factor = highest / lowest
    return string.format("%.2f", factor)
end
local function createTable(userAmount, calcAmount, useRoW, ecoType)
local tbl = mw.html.create("table")
:addClass("wikitable sticky-header text-align-right align-left-1")
if ecoType == ECOIN then
addTableRow(tbl, "Desired Output", userAmount)
addTableRow(tbl, "Estimated Input", calcAmount)
else
addTableRow(tbl, "Starting Items", userAmount)
addTableRow(tbl, "Estimated Output", calcAmount)
end
addTableRow(tbl, "Economy Factor", calculateFactor(userAmount, calcAmount))
addTableRow(tbl, "[[Ring of Wealth]] benefits", useRoW)
end
end


Line 49: Line 86:


function p._main(args)
function p._main(args)
local itemAmount = targetAmount
local itemAmount = args.targetAmount
local economyType = parseEconomy(args.economyType)
local economyType = parseEconomy(args.economyType)
Line 64: Line 101:
result, row = calculateInput(itemAmount, pChance, dChance, eChance)
result, row = calculateInput(itemAmount, pChance, dChance, eChance)
end
end
 
return result, row
local tbl = createTable(itemAmount, result, row, economyType)
       
    return tostring(tbl)
end
end


return p
return p
2,875

edits