Module:GeneralPortOperations: Difference between revisions
From MicrasWiki
Jump to navigationJump to search
NewZimiaGov (talk | contribs) No edit summary |
NewZimiaGov (talk | contribs) No edit summary |
||
| Line 23: | Line 23: | ||
end | end | ||
-- Generate simulated ship operations as a wiki table | -- Generate simulated ship operations as a wiki table with errors and date | ||
function p.generateShipTable() | function p.generateShipTable() | ||
local vesselTypes = {'Cargo', 'Military', 'Ritual', 'Privateer'} | local vesselTypes = {'Cargo', 'Military', 'Ritual', 'Privateer'} | ||
local cargoTypes = {'Agricultural', 'Mining/Manufacturing', 'Services'} | local cargoTypes = {'Agricultural', 'Mining/Manufacturing', 'Services'} | ||
local | local errorTypes = { | ||
"None", | |||
"Cargo Mislabeling", | |||
"Improper Documentation", | |||
"Surveillance Anomaly", | |||
"Inspection Failure", | |||
"Unregistered Ritual Cargo" | |||
} | |||
local year, day = p.getCurrentDate() | |||
local dateStr = string.format("Day %d, Y.%d", day, year) | |||
local num_ships = math.random(50, 80) | local table = "{| class=\"wikitable sortable\"\n! Date !! Vessel ID !! Type !! Berth !! TEUs !! Tonnage (tons) !! Cargo Type !! Queue Time (hrs) !! Turnaround Time (hrs) !! Error Status" | ||
for i = 1, num_ships do | |||
local num_ships = math.random(50, 80) | |||
for i = 1, num_ships do | |||
local vessel_id = "VM-" .. tostring(1000 + i) | local vessel_id = "VM-" .. tostring(1000 + i) | ||
local v_type = randomChoice(vesselTypes) | local v_type = randomChoice(vesselTypes) | ||
| Line 39: | Line 51: | ||
local queue = string.format("%.2f", math.random() * 5.5 + 0.5) | local queue = string.format("%.2f", math.random() * 5.5 + 0.5) | ||
local turnaround = string.format("%.2f", math.random() * 32 + 4) | local turnaround = string.format("%.2f", math.random() * 32 + 4) | ||
local errorStatus = randomChoice(errorTypes) | |||
local rowStyle = "" | |||
if errorStatus ~= "None" then | |||
rowStyle = " style=\"background-color:#fdd;\"" | |||
end | |||
table = table .. string.format("\n|-\n| %s || %s || %d || %d || %s || %s || %s || %s", | table = table .. string.format("\n|- %s\n| %s || %s || %s || %d || %d || %s || %s || %s || %s", | ||
vessel_id, v_type, berth, teus, tonnage, cargo, queue, turnaround) | rowStyle, dateStr, vessel_id, v_type, berth, teus, tonnage, cargo, queue, turnaround, errorStatus) | ||
end | end | ||
table = table .. "\n|}" | table = table .. "\n|}" | ||
table = table .. "\n\n'''Error Key:'''\n" | |||
table = table .. "* '''Cargo Mislabeling:''' Mismatch between manifest and actual goods\n" | |||
table = table .. "* '''Improper Documentation:''' Missing or outdated transit papers\n" | |||
table = table .. "* '''Surveillance Anomaly:''' Unexpected heat or movement signature\n" | |||
table = table .. "* '''Inspection Failure:''' Failed customs or hatch review\n" | |||
table = table .. "* '''Unregistered Ritual Cargo:''' Religious items not pre-cleared by the Temple Bank\n" | |||
return table | return table | ||
end | end | ||
Revision as of 15:46, 23 April 2025
Documentation for this module may be created at Module:GeneralPortOperations/doc
-- Module:GeneralPortDailyLog
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
-- Random helper
local function randomChoice(t)
return t[math.random(#t)]
end
-- Generate simulated ship operations as a wiki table with errors and date
function p.generateShipTable()
local vesselTypes = {'Cargo', 'Military', 'Ritual', 'Privateer'}
local cargoTypes = {'Agricultural', 'Mining/Manufacturing', 'Services'}
local errorTypes = {
"None",
"Cargo Mislabeling",
"Improper Documentation",
"Surveillance Anomaly",
"Inspection Failure",
"Unregistered Ritual Cargo"
}
local year, day = p.getCurrentDate()
local dateStr = string.format("Day %d, Y.%d", day, year)
local table = "{| class=\"wikitable sortable\"\n! Date !! Vessel ID !! Type !! Berth !! TEUs !! Tonnage (tons) !! Cargo Type !! Queue Time (hrs) !! Turnaround Time (hrs) !! Error Status"
local num_ships = math.random(50, 80)
for i = 1, num_ships do
local vessel_id = "VM-" .. tostring(1000 + i)
local v_type = randomChoice(vesselTypes)
local berth = math.random(1, 124)
local teus = math.random(100, 1000)
local tonnage = string.format("%.2f", math.random() * 19000 + 1000)
local cargo = randomChoice(cargoTypes)
local queue = string.format("%.2f", math.random() * 5.5 + 0.5)
local turnaround = string.format("%.2f", math.random() * 32 + 4)
local errorStatus = randomChoice(errorTypes)
local rowStyle = ""
if errorStatus ~= "None" then
rowStyle = " style=\"background-color:#fdd;\""
end
table = table .. string.format("\n|- %s\n| %s || %s || %s || %d || %d || %s || %s || %s || %s",
rowStyle, dateStr, vessel_id, v_type, berth, teus, tonnage, cargo, queue, turnaround, errorStatus)
end
table = table .. "\n|}"
table = table .. "\n\n'''Error Key:'''\n"
table = table .. "* '''Cargo Mislabeling:''' Mismatch between manifest and actual goods\n"
table = table .. "* '''Improper Documentation:''' Missing or outdated transit papers\n"
table = table .. "* '''Surveillance Anomaly:''' Unexpected heat or movement signature\n"
table = table .. "* '''Inspection Failure:''' Failed customs or hatch review\n"
table = table .. "* '''Unregistered Ritual Cargo:''' Religious items not pre-cleared by the Temple Bank\n"
return table
end
-- Main report (text-only)
function p.dailyReport()
local year, day = p.getCurrentDate()
local header = string.format("'''General Port of Lake Morovia: Operational Log – Day %d, Year %d PSSC'''\n", day, year)
return header .. p.generateShipTable()
end
return p