Module:GeneralPortCargoLog: Difference between revisions
From MicrasWiki
Jump to navigationJump to search
NewZimiaGov (talk | contribs) No edit summary |
NewZimiaGov (talk | contribs) No edit summary |
||
| Line 2: | Line 2: | ||
local p = {} | local p = {} | ||
-- Date generation logic | |||
function p.getCurrentDate() | |||
local startDate = os.time({year = 1999, month = 8, day = 6}) | local startDate = os.time({year = 1999, month = 8, day = 6}) | ||
local | local secondsInDay = 86400 | ||
local daysPerYear = 183 | local daysPerYear = 183 | ||
local totalDaysElapsed = math.floor((currentDate - startDate) / | |||
local | local currentDate = os.time() | ||
local | local totalDaysElapsed = math.floor((currentDate - startDate) / secondsInDay) | ||
return | |||
local yearFraction = totalDaysElapsed / daysPerYear | |||
local psscYear = math.floor(yearFraction) | |||
local dayOfYear = math.floor((yearFraction - psscYear) * daysPerYear) + 1 | |||
return psscYear, dayOfYear | |||
end | end | ||
Revision as of 22:41, 23 April 2025
Documentation for this module may be created at Module:GeneralPortCargoLog/doc
-- Module:GeneralPortCargoLog
local p = {}
-- Date generation logic
function p.getCurrentDate()
local startDate = os.time({year = 1999, month = 8, day = 6})
local secondsInDay = 86400
local daysPerYear = 183
local currentDate = os.time()
local totalDaysElapsed = math.floor((currentDate - startDate) / secondsInDay)
local yearFraction = totalDaysElapsed / daysPerYear
local psscYear = math.floor(yearFraction)
local dayOfYear = math.floor((yearFraction - psscYear) * daysPerYear) + 1
return psscYear, dayOfYear
end
local function randomChoice(t)
return t[math.random(#t)]
end
function p.generateCargoLog()
local year, day = getCurrentDate()
local dateStr = string.format("Day %d, Y.%d", day, year)
local containerCraneOps = math.random(300, 700)
local bulkOps = math.random(100, 300)
local liquidOps = math.random(80, 250)
local avgTurnaroundTime = math.random(12, 36) + math.random()
local log = "{| class=\"wikitable\" style=\"width:100%\"\n"
log = log .. string.format("! colspan=2 | General Port of Lake Morovia – Cargo Handling Log (%s)\n", dateStr)
log = log .. "|-\n"
log = log .. string.format("| '''Container Crane Operations''' || %d moves\n", containerCraneOps)
log = log .. "|-\n"
log = log .. string.format("| '''Bulk Cargo Handled''' || %d tons\n", bulkOps)
log = log .. "|-\n"
log = log .. string.format("| '''Liquid Cargo Handled''' || %d tons\n", liquidOps)
log = log .. "|-\n"
log = log .. string.format("| '''Average Turnaround Time''' || %.2f hours\n", avgTurnaroundTime)
log = log .. "|}"
return log
end
function p.dailyCargoSummary()
local year, day = getCurrentDate()
local header = string.format("'''General Port of Lake Morovia: Cargo Log – Day %d, Year %d PSSC'''\n", day, year)
return header .. p.generateCargoLog()
end
return p