Module:GeneralPortWeather: Difference between revisions

From MicrasWiki
Jump to navigationJump to search
NewZimiaGov (talk | contribs)
No edit summary
NewZimiaGov (talk | contribs)
No edit summary
 
Line 1: Line 1:
-- Module:GeneralPortWeatherLog
local p = {}
local p = {}


local function getCurrentDate()
-- 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 daysPerYear = 183
     local totalDaysElapsed = math.floor((currentDate - startDate) / secondsInDay)
     local totalDaysElapsed = math.floor((currentDate - startDate) / 86400)
 
     local year = math.floor(totalDaysElapsed / daysPerYear)
    local yearFraction = totalDaysElapsed / daysPerYear
     local day = (totalDaysElapsed % daysPerYear) + 1
     local psscYear = math.floor(yearFraction)
     return year, day
     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


-- Forecast string based on daily seed
local function getVaeringheimForecastString()
local function getVaeringheimForecastString()
     local date = os.date("*t")
     local date = os.date("*t")
Line 34: Line 41:
         "Early morning seasonal storms and lake-driven floods may develop"
         "Early morning seasonal storms and lake-driven floods may develop"
     }
     }
     return climateEvents[math.random(#climateEvents)]
     return climateEvents[math.random(#climateEvents)]
end
end


-- Generate the weather log table
function p.generateWeatherLog()
function p.generateWeatherLog()
     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)


     local conditions = getVaeringheimForecastString()
     local conditions = getVaeringheimForecastString()
     local wind = randomChoice({"Calm", "Breezy", "Moderate", "Strong", "Gusty"})
     local wind = randomChoice({ "Calm", "Breezy", "Moderate", "Strong", "Gusty" })
     local precipitationImpact = (conditions:lower():find("rain") or conditions:lower():find("storm") or conditions:lower():find("drizzle")) and "Delays in loading/unloading" or "No significant impact"
     local precipitationImpact =
     local fog = randomChoice({"None", "Light Haze", "Heavy Fog"})
        (conditions:lower():find("rain") or conditions:lower():find("storm") or conditions:lower():find("drizzle"))
     local navalImpact = (fog == "Heavy Fog") and "Severe restrictions on naval operations" or (fog == "Light Haze" and "Caution advised for navigation" or "Clear visibility")
        and "Delays in loading/unloading" or "No significant impact"
     local hazard = randomChoice({"None", "Toxic Algae Bloom Detected", "Industrial Runoff Warning", "Oil Slick Monitored", "Chemical Discharge Alert"})
 
     local toxicBloom = hazard == "Toxic Algae Bloom Detected" and "Active bloom in Lake Morovia. Environmental control in effect." or "No bloom present"
     local fog = randomChoice({ "None", "Light Haze", "Heavy Fog" })
     local containment = randomChoice({"None", "Activated containment barriers", "Limited zone quarantines", "Full spill containment deployed"})
     local navalImpact = (fog == "Heavy Fog") and "Severe restrictions on naval operations"
        or (fog == "Light Haze" and "Caution advised for navigation" or "Clear visibility")
 
     local hazard = randomChoice({ "None", "Toxic Algae Bloom Detected", "Industrial Runoff Warning", "Oil Slick Monitored", "Chemical Discharge Alert" })
     local toxicBloom = (hazard == "Toxic Algae Bloom Detected") and "Active bloom in Lake Morovia. Environmental control in effect." or "No bloom present"
     local containment = randomChoice({ "None", "Activated containment barriers", "Limited zone quarantines", "Full spill containment deployed" })


     local log = "{| class=\"wikitable\" style=\"width:100%\"\n"
     local log = "{| class=\"wikitable\" style=\"width:100%\"\n"
Line 73: Line 87:
end
end


-- Entry point for daily output
function p.dailyWeatherSummary()
function p.dailyWeatherSummary()
     local year, day = getCurrentDate()
     local year, day = p.getCurrentDate()
     local header = string.format("'''General Port of Lake Morovia: Environmental Log – Day %d, Year %d PSSC'''\n", day, year)
     local header = string.format("'''General Port of Lake Morovia: Environmental Log – Day %d, Year %d PSSC'''\n", day, year)
     return header .. p.generateWeatherLog()
     return header .. p.generateWeatherLog()

Latest revision as of 23:10, 23 April 2025

Documentation for this module may be created at Module:GeneralPortWeather/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

-- Forecast string based on daily seed
local function getVaeringheimForecastString()
    local date = os.date("*t")
    local seed = date.year * 1000 + date.yday
    math.randomseed(seed)

    local climateEvents = {
        "Morning drizzle and warm afternoon sunshine",
        "Mild thunderstorm building by midday",
        "Patchy fog at dawn, clearing toward lunch",
        "Light rain with sunny breaks after noon",
        "Gentle breezes, blossoming warmth, low humidity",
        "Scattered clouds with a brief shower by dusk",
        "Humid sunrise, comfortable high around midday",
        "Overcast for part of the day, mild temperatures",
        "Warm breezes carrying faint floral scents",
        "Partial sun, warm with a slight chance of rain",
        "Early morning seasonal storms and lake-driven floods may develop"
    }

    return climateEvents[math.random(#climateEvents)]
end

-- Generate the weather log table
function p.generateWeatherLog()
    local year, day = p.getCurrentDate()
    local dateStr = string.format("Day %d, Y.%d", day, year)

    local conditions = getVaeringheimForecastString()
    local wind = randomChoice({ "Calm", "Breezy", "Moderate", "Strong", "Gusty" })
    local precipitationImpact =
        (conditions:lower():find("rain") or conditions:lower():find("storm") or conditions:lower():find("drizzle"))
        and "Delays in loading/unloading" or "No significant impact"

    local fog = randomChoice({ "None", "Light Haze", "Heavy Fog" })
    local navalImpact = (fog == "Heavy Fog") and "Severe restrictions on naval operations"
        or (fog == "Light Haze" and "Caution advised for navigation" or "Clear visibility")

    local hazard = randomChoice({ "None", "Toxic Algae Bloom Detected", "Industrial Runoff Warning", "Oil Slick Monitored", "Chemical Discharge Alert" })
    local toxicBloom = (hazard == "Toxic Algae Bloom Detected") and "Active bloom in Lake Morovia. Environmental control in effect." or "No bloom present"
    local containment = randomChoice({ "None", "Activated containment barriers", "Limited zone quarantines", "Full spill containment deployed" })

    local log = "{| class=\"wikitable\" style=\"width:100%\"\n"
    log = log .. string.format("! colspan=2 | General Port of Lake Morovia – Environmental Conditions Log (%s)\n", dateStr)
    log = log .. "|-\n"
    log = log .. string.format("| '''General Conditions''' || %s\n", conditions)
    log = log .. "|-\n"
    log = log .. string.format("| '''Wind Speed''' || %s\n", wind)
    log = log .. "|-\n"
    log = log .. string.format("| '''Precipitation Impact''' || %s\n", precipitationImpact)
    log = log .. "|-\n"
    log = log .. string.format("| '''Fog / Haze''' || %s\n", fog)
    log = log .. "|-\n"
    log = log .. string.format("| '''Naval Visibility Conditions''' || %s\n", navalImpact)
    log = log .. "|-\n"
    log = log .. string.format("| '''Environmental Hazard Alert''' || %s\n", hazard)
    log = log .. "|-\n"
    log = log .. string.format("| '''Toxic Bloom Status''' || %s\n", toxicBloom)
    log = log .. "|-\n"
    log = log .. string.format("| '''Containment Protocols''' || %s\n", containment)
    log = log .. "|}"

    return log
end

-- Entry point for daily output
function p.dailyWeatherSummary()
    local year, day = p.getCurrentDate()
    local header = string.format("'''General Port of Lake Morovia: Environmental Log – Day %d, Year %d PSSC'''\n", day, year)
    return header .. p.generateWeatherLog()
end

return p