Module:GeneralPortDailyLog

From MicrasWiki
Revision as of 19:26, 23 April 2025 by NewZimiaGov (talk | contribs) (Created page with "-- 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 year = math.floor(totalDaysElapsed / daysPerYear) local day = (totalDaysElapsed % daysPerYear) + 1 return year, day end local function randomChoice(t) return t[math.random(#t...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Documentation for this module may be created at Module:GeneralPortDailyLog/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 year = math.floor(totalDaysElapsed / daysPerYear)
    local day = (totalDaysElapsed % daysPerYear) + 1
    return year, day
end

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

function p.generateEnergyLog()
    local year, day = getCurrentDate()
    local dateStr = string.format("Day %d, Y.%d", day, year)

    local weather = randomChoice({"Clear", "Breezy", "Windy", "Stormy", "Calm"})
    local windEfficiency = {
        Clear = 0.6,
        Breezy = 0.75,
        Windy = 1.0,
        Stormy = 1.2,
        Calm = 0.3
    }

    local windBase = 200
    local windOutput = windBase * windEfficiency[weather] * 4
    local fusionOutput = 600 * 3
    local geothermalBase = 150
    local totalOutput = windOutput + fusionOutput + geothermalBase

    local demand = math.random(1400, 2000)
    local rerouting = demand > totalOutput and "Activated" or "Not Required"
    local backupProtocol = demand > totalOutput + 100 and "Backup Generator Online" or "Normal Status"

    local log = "{| class=\"wikitable\" style=\"width:100%\"\n"
    log = log .. string.format("! colspan=2 | General Port of Lake Morovia – Energy Systems Log (%s)\n", dateStr)
    log = log .. "|-\n"
    log = log .. string.format("| '''Weather Conditions''' || %s\n", weather)
    log = log .. "|-\n"
    log = log .. string.format("| '''Wind Farm Output''' || %.2f MW\n", windOutput)
    log = log .. "|-\n"
    log = log .. string.format("| '''Fusion Substation Output''' || %.2f MW\n", fusionOutput)
    log = log .. "|-\n"
    log = log .. string.format("| '''Geothermal Plant Output''' || %.2f MW\n", geothermalBase)
    log = log .. "|-\n"
    log = log .. string.format("| '''Total Power Generated''' || %.2f MW\n", totalOutput)
    log = log .. "|-\n"
    log = log .. string.format("| '''Port Power Demand''' || %d MW\n", demand)
    log = log .. "|-\n"
    log = log .. string.format("| '''Energy Rerouting''' || %s\n", rerouting)
    log = log .. "|-\n"
    log = log .. string.format("| '''Backup Protocol Status''' || %s\n", backupProtocol)
    log = log .. "|}"

    return log
end

function p.dailyEnergySummary()
    local year, day = getCurrentDate()
    local header = string.format("'''General Port of Lake Morovia: Energy Log – Day %d, Year %d PSSC'''\n", day, year)
    return header .. p.generateEnergyLog()
end

return p