Module:GeneralPortTransportLog: Difference between revisions
From MicrasWiki
Jump to navigationJump to search
NewZimiaGov (talk | contribs) Created page with "-- Module:GeneralPortTransportLog local p = {} local function getCurrentDate() local startDate = os.time({year = 1999, month = 8, day = 6}) local currentDate = os.time() local daysPerYear = 183 local totalDaysElapsed = math.floor((currentDate - startDate) / 86400) local year = math.floor(totalDaysElapsed / daysPerYear) local day = (totalDaysElapsed % daysPerYear) + 1 return year, day end local function randomChoice(t) return t[math.rando..." |
NewZimiaGov (talk | contribs) No edit summary |
||
| Line 4: | Line 4: | ||
local function getCurrentDate() | local function getCurrentDate() | ||
local startDate = os.time({year = 1999, month = 8, day = 6}) | local startDate = os.time({year = 1999, month = 8, day = 6}) | ||
local secondsInDay = 86400 | |||
local daysPerYear = 183 | |||
local currentDate = os.time() | local currentDate = os.time() | ||
local totalDaysElapsed = math.floor((currentDate - startDate) / secondsInDay) | |||
local totalDaysElapsed = math.floor((currentDate - startDate) / | |||
local | local yearFraction = totalDaysElapsed / daysPerYear | ||
local | local psscYear = math.floor(yearFraction) | ||
local dayOfYear = math.floor((yearFraction - psscYear) * daysPerYear) + 1 | |||
return psscYear, dayOfYear | |||
return | |||
end | end | ||
Revision as of 22:44, 23 April 2025
Documentation for this module may be created at Module:GeneralPortTransportLog/doc
-- Module:GeneralPortTransportLog
local p = {}
local function 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
function p.generateTransportLog()
local year, day = getCurrentDate()
local dateStr = string.format("Day %d, Y.%d", day, year)
local terminals = {"North Terminal", "South Terminal", "Island Terminal", "Drydock Freight Hub"}
local railLoads = {}
for _, terminal in ipairs(terminals) do
table.insert(railLoads, string.format("%s: %d carloads", terminal, math.random(100, 400)))
end
local arcologyShuttles = math.random(30, 90)
local maglevCycles = math.random(50, 120)
local log = "{| class=\"wikitable\" style=\"width:100%\"\n"
log = log .. string.format("! colspan=2 | General Port of Lake Morovia – Transport Outflows Log (%s)\n", dateStr)
log = log .. "|-\n"
log = log .. string.format("| '''Freight Rail Carloads''' || <ul><li>%s</li></ul>\n", table.concat(railLoads, "</li><li>"))
log = log .. "|-\n"
log = log .. string.format("| '''Arcological Logistics Movements''' || %d shuttles\n", arcologyShuttles)
log = log .. "|-\n"
log = log .. string.format("| '''Maglev Transfer Cycles''' || %d departures\n", maglevCycles)
log = log .. "|}"
return log
end
function p.dailyTransportSummary()
local year, day = getCurrentDate()
local header = string.format("'''General Port of Lake Morovia: Transport Log – Day %d, Year %d PSSC'''\n", day, year)
return header .. p.generateTransportLog()
end
return p