Module:GeneralPortDailyLog: Difference between revisions
From MicrasWiki
Jump to navigationJump to search
NewZimiaGov (talk | contribs) Undo revision 359891 by NewZimiaGov (talk) Tag: Undo |
NewZimiaGov (talk | contribs) No edit summary |
||
| (5 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
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 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) | ||
return | local dayOfYear = math.floor((yearFraction - psscYear) * daysPerYear) + 1 | ||
return psscYear, dayOfYear | |||
end | end | ||
-- Random selection utility | |||
local function randomChoice(t) | local function randomChoice(t) | ||
return t[math.random(#t)] | return t[math.random(#t)] | ||
end | end | ||
-- Generate daily energy system log | |||
function p.generateEnergyLog() | function p.generateEnergyLog() | ||
local year, day = getCurrentDate() | local year, day = p.getCurrentDate() | ||
local dateStr = string.format("Day %d, Y.%d", day, year) | local dateStr = string.format("Day %d, Y.%d", day, year) | ||
| Line 62: | Line 69: | ||
end | end | ||
-- Main function to output summary | |||
function p.dailyEnergySummary() | function p.dailyEnergySummary() | ||
local year, day = getCurrentDate() | local year, day = p.getCurrentDate() | ||
local header = string.format("'''General Port of Lake Morovia: Energy Log – Day %d, Year %d PSSC'''\n", day, year) | local header = string.format("'''General Port of Lake Morovia: Energy Log – Day %d, Year %d PSSC'''\n", day, year) | ||
return header .. p.generateEnergyLog() | return header .. p.generateEnergyLog() | ||
Latest revision as of 22:52, 23 April 2025
Documentation for this module may be created at Module:GeneralPortDailyLog/doc
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 selection utility
local function randomChoice(t)
return t[math.random(#t)]
end
-- Generate daily energy system log
function p.generateEnergyLog()
local year, day = p.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
-- Main function to output summary
function p.dailyEnergySummary()
local year, day = p.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