Module:Calculator/ETA: Difference between revisions

no edit summary
m (Fix erroneous calculation of time remainder)
No edit summary
 
(8 intermediate revisions by the same user not shown)
Line 2: Line 2:


local MEXP = require('Module:Experience')
local MEXP = require('Module:Experience')
local shared = require('Module:Shared')
local number = require('Module:Number')
local TimeSpan = require('Module:TimeSpan')


function p._formatTime(timeInHundredths)
local function formatTime(seconds)
    local sec = math.floor(timeInHundredths / 100)
local timespan = TimeSpan.fromSeconds(seconds)
    local min = math.floor(timeInHundredths / 60000)
return timespan:toStringLong()
    local hrs = math.floor(timeInHundredths / 360000)
    local days = math.floor(timeInHundredths / (360000 * 24))
 
if days == 0 then
return string.format("%02dh %02dm %02ds", hrs % 24, min % 60, sec % 60)
else
return string.format("%d days %02dh %02dm %02ds", days, hrs % 24, min % 60, sec % 60)
end
end
end


function p._addTableRow(tbl, c1, c2)
local function addTableRow(tbl, c1, c2)
tbl:tag("tr")
tbl:tag("tr")
:tag("th"):wikitext(c1)
:tag("th"):wikitext(c1)
Line 25: Line 18:
end
end


function p._calc(currentExp, targetLvl, expPerAction, actionTime)
local function calc(currentExp, targetLvl, expPerAction, actionTime)
-- ActionTime is represented in hundreds of a second.
local actionsPerHour = math.floor(3600 / actionTime)
-- 1.6 seconds = 160
local actionsPerHour = math.floor(360000 / actionTime)
local targetExp = MEXP.expForLevel(targetLvl)
local targetExp = MEXP.expForLevel(targetLvl)
local expRemaining = math.max(targetExp - currentExp, 0)
local expRemaining = math.max(targetExp - currentExp, 0)
local expPerHour = math.floor(3600 / actionTime * expPerAction)
local actionsToTarget = math.ceil(expRemaining / expPerAction)
local actionsToTarget = math.ceil(expRemaining / expPerAction)
Line 38: Line 30:
         :addClass("wikitable sticky-header text-align-right align-left-1")
         :addClass("wikitable sticky-header text-align-right align-left-1")


p._addTableRow(tbl, "Current Experience", shared.formatnum(currentExp))
addTableRow(tbl, "Current Experience", number.formatnum(currentExp))
p._addTableRow(tbl, "Target Level", targetLvl)
addTableRow(tbl, "Target Level", targetLvl)
p._addTableRow(tbl, "Target Experience", shared.formatnum(targetExp))
addTableRow(tbl, "Target Experience", number.formatnum(targetExp))
p._addTableRow(tbl, "Experience Remaining", shared.formatnum(expRemaining))
addTableRow(tbl, "Experience Remaining", number.formatnum(expRemaining))
p._addTableRow(tbl, "Actions Left", shared.formatnum(actionsToTarget))
addTableRow(tbl, "Experience Per Hour", number.formatnum(expPerHour))
p._addTableRow(tbl, "Time Left", p._formatTime(timeToTarget))
addTableRow(tbl, "Actions Left", number.formatnum(actionsToTarget))
addTableRow(tbl, "Time Left", formatTime(timeToTarget))


     return tostring(tbl)
     return tostring(tbl)
Line 55: Line 48:
local args = frame:getParent().args
local args = frame:getParent().args
local currentExp = shared.toNumberOrDefault(args.currentExp, 0)
local currentExp = number.parseNumber(args.currentExp)
local currentLvl = shared.toNumberOrDefault(args.currentLvl, 0)
local currentLvl = number.toNumberOrDefault(args.currentLvl, 0)


local targetLvl = shared.toNumberOrError(args.targetLvl)
local targetLvl = number.toNumberOrError(args.targetLvl)
local actionExp = shared.toNumberOrError(args.actionExp)
local actionExp = number.toNumberOrError(args.actionExp)
local actionTime = shared.toNumberOrError(args.actionTime)
local actionTime = number.toNumberOrError(args.actionTime)


-- Check Exp param for validity first, then Lvl
-- Check Exp param for validity first, then Lvl
Line 67: Line 60:
end
end
return p._calc(currentExp, targetLvl, actionExp, actionTime)
return calc(currentExp, targetLvl, actionExp, actionTime)
end
end


return p
return p
1,029

edits