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 2: Line 2:
local p = {}
local p = {}


-- Date generation logic
local function getCurrentDate()
function p.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 currentDate = os.time()
     local daysPerYear = 183
     local daysPerYear = 183
 
     local totalDaysElapsed = math.floor((currentDate - startDate) / 86400)
    local currentDate = os.time()
     local totalDaysElapsed = math.floor((currentDate - startDate) / secondsInDay)
 
     local yearFraction = totalDaysElapsed / daysPerYear
     local yearFraction = totalDaysElapsed / daysPerYear
     local psscYear = math.floor(yearFraction)
     local psscYear = math.floor(yearFraction)
     local dayOfYear = math.floor((yearFraction - psscYear) * daysPerYear) + 1
     local dayOfYear = math.floor((yearFraction - psscYear) * daysPerYear) + 1
     return psscYear, dayOfYear
     return psscYear, dayOfYear
end
end


-- Random helper
local function randomChoice(t)
local function randomChoice(t)
     return t[math.random(#t)]
     return t[math.random(#t)]
end
end


-- Generate simulated ship operations as a wiki table with errors and date
local function getSampleCargoList()
    return {
        Agricultural = {
            "Rice", "Wheat", "Edible Algae", "Shrimp", "Anterran Spicy Onion",
            "Queen's Garlic", "Camel Milk", "Morovian Water Buffalo Beef"
        },
        ["Mining/Manufacturing"] = {
            "Steel", "Coal", "Iron", "Copper", "Concrete",
            "Mens' Boots", "Gold Necklaces", "Robes"
        },
        Services = {
            "Missionaries of the Order Aurora Mystica", "Faces", "Credit Hours",
            "Plunder", "Spies", "Circuses", "Performances"
        }
    }
end
 
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 errorTypes = {
     local errorTypes = {
         "Cargo Mislabeling",
         "Cargo Mislabeling", "Improper Documentation", "Surveillance Anomaly",
        "Improper Documentation",
         "Inspection Failure", "Unregistered Ritual Cargo"
        "Surveillance Anomaly",
         "Inspection Failure",
        "Unregistered Ritual Cargo"
     }
     }
   
 
     local year, day = p.getCurrentDate()
     local year, day = getCurrentDate()
     local dateStr = string.format("Day %d, Y.%d", day, year)
     local dateStr = string.format("Day %d, Y.%d", day, year)
    local output = "{| class=\"wikitable sortable\"\n! Date !! Vessel ID !! Type !! Berth !! TEUs !! Tonnage (tons) !! Cargo Type !! Specific Cargo !! Queue Time (hrs) !! Turnaround Time (hrs) !! Error Type"


     local output = "{| class=\"wikitable sortable\"\n! Date !! Vessel ID !! Type !! Berth !! TEUs !! Tonnage (tons) !! Cargo Type !! Queue Time (hrs) !! Turnaround Time (hrs) !! Error Type"
     local cargoLists = getSampleCargoList()
    local num_ships = math.random(50, 80)


    local num_ships = math.random(50, 80)
     for i = 1, num_ships do
     for i = 1, num_ships do
         local vessel_id = "VM-" .. tostring(1000 + i)
         local vessel_id = "VM-" .. tostring(1000 + i)
Line 47: Line 55:
         local teus = math.random(100, 1000)
         local teus = math.random(100, 1000)
         local tonnage = string.format("%.2f", math.random() * 19000 + 1000)
         local tonnage = string.format("%.2f", math.random() * 19000 + 1000)
         local cargo = randomChoice(cargoTypes)
         local cargoCategory = randomChoice(cargoTypes)
        local specificCargo = randomChoice(cargoLists[cargoCategory])
         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 hasError = math.random() < 0.2
         local hasError = math.random() < 0.2
         local errorStatus = hasError and randomChoice(errorTypes) or "None"
         local errorStatus = hasError and randomChoice(errorTypes) or "None"
        local rowStyle = hasError and " style=\"background-color:#fdd;\"" or ""


         local row = string.format("\n| %s || %s || %s || %d || %d || %s || %s || %s || %s",
         local row = string.format("\n| %s || %s || %s || %d || %d || %s || %s || %s || %s || %s",
             dateStr, vessel_id, v_type, berth, teus, tonnage, cargo, queue, turnaround)
             dateStr, vessel_id, v_type, berth, teus, tonnage, cargoCategory,
            specificCargo, queue, turnaround)


         if hasError then
         output = output .. string.format("\n|- %s%s || %s", rowStyle, row, errorStatus)
            output = output .. string.format("\n|- style=\"background-color:#fdd;\"%s || %s", row, errorStatus)
        else
            output = output .. string.format("\n|-%s || %s", row, errorStatus)
        end
     end
     end


     output = output .. "\n|}"
     output = output .. "\n|}"
     output = output .. "\n\n'''Error Key:'''\n"
     output = output .. "\n\n'''Error Key:'''\n"
     output = output .. "* '''Cargo Mislabeling:''' Mismatch between manifest and actual goods\n"
     output = output .. "* '''Cargo Mislabeling:''' Mismatch between manifest and actual goods\n"
Line 76: Line 81:
end
end


-- Main report (text-only)
function p.dailyReport()
function p.dailyReport()
     local year, day = p.getCurrentDate()
     local year, day = getCurrentDate()
     local header = string.format("'''General Port of Lake Morovia: Operational Log – Day %d, Year %d PSSC'''\n", day, year)
     local header = string.format("'''General Port of Lake Morovia: Operational Log – Day %d, Year %d PSSC'''\n", day, year)
     return header .. p.generateShipTable()
     return header .. p.generateShipTable()

Revision as of 16:01, 23 April 2025

Documentation for this module may be created at Module:GeneralPortOperations/doc

-- Module:GeneralPortDailyLog
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 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

local function getSampleCargoList()
    return {
        Agricultural = {
            "Rice", "Wheat", "Edible Algae", "Shrimp", "Anterran Spicy Onion",
            "Queen's Garlic", "Camel Milk", "Morovian Water Buffalo Beef"
        },
        ["Mining/Manufacturing"] = {
            "Steel", "Coal", "Iron", "Copper", "Concrete",
            "Mens' Boots", "Gold Necklaces", "Robes"
        },
        Services = {
            "Missionaries of the Order Aurora Mystica", "Faces", "Credit Hours",
            "Plunder", "Spies", "Circuses", "Performances"
        }
    }
end

function p.generateShipTable()
    local vesselTypes = {'Cargo', 'Military', 'Ritual', 'Privateer'}
    local cargoTypes = {'Agricultural', 'Mining/Manufacturing', 'Services'}
    local errorTypes = {
        "Cargo Mislabeling", "Improper Documentation", "Surveillance Anomaly",
        "Inspection Failure", "Unregistered Ritual Cargo"
    }

    local year, day = getCurrentDate()
    local dateStr = string.format("Day %d, Y.%d", day, year)
    local output = "{| class=\"wikitable sortable\"\n! Date !! Vessel ID !! Type !! Berth !! TEUs !! Tonnage (tons) !! Cargo Type !! Specific Cargo !! Queue Time (hrs) !! Turnaround Time (hrs) !! Error Type"

    local cargoLists = getSampleCargoList()
    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 cargoCategory = randomChoice(cargoTypes)
        local specificCargo = randomChoice(cargoLists[cargoCategory])
        local queue = string.format("%.2f", math.random() * 5.5 + 0.5)
        local turnaround = string.format("%.2f", math.random() * 32 + 4)
        local hasError = math.random() < 0.2
        local errorStatus = hasError and randomChoice(errorTypes) or "None"
        local rowStyle = hasError and " style=\"background-color:#fdd;\"" or ""

        local row = string.format("\n| %s || %s || %s || %d || %d || %s || %s || %s || %s || %s",
            dateStr, vessel_id, v_type, berth, teus, tonnage, cargoCategory,
            specificCargo, queue, turnaround)

        output = output .. string.format("\n|- %s%s || %s", rowStyle, row, errorStatus)
    end

    output = output .. "\n|}"
    output = output .. "\n\n'''Error Key:'''\n"
    output = output .. "* '''Cargo Mislabeling:''' Mismatch between manifest and actual goods\n"
    output = output .. "* '''Improper Documentation:''' Missing or outdated transit papers\n"
    output = output .. "* '''Surveillance Anomaly:''' Unexpected heat or movement signature\n"
    output = output .. "* '''Inspection Failure:''' Failed customs or hatch review\n"
    output = output .. "* '''Unregistered Ritual Cargo:''' Religious items not pre-cleared by the Temple Bank\n"

    return output
end

function p.dailyReport()
    local year, day = 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