Module:BassaridEmployment: Difference between revisions
From MicrasWiki
Jump to navigationJump to search
NewZimiaGov (talk | contribs) No edit summary |
NewZimiaGov (talk | contribs) No edit summary |
||
| Line 14: | Line 14: | ||
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 | ||
local month, dayOfMonth | local month, dayOfMonth | ||
if dayOfYear <= 61 then | if dayOfYear <= 61 then | ||
month = 1 | month = 1; dayOfMonth = dayOfYear | ||
elseif dayOfYear <= 122 then | elseif dayOfYear <= 122 then | ||
month = 2 | month = 2; dayOfMonth = dayOfYear - 61 | ||
else | else | ||
month = 3 | month = 3; dayOfMonth = dayOfYear - 122 | ||
end | end | ||
| Line 35: | Line 32: | ||
-- 2. Basic Setup | -- 2. Basic Setup | ||
--------------------------------------------------------- | --------------------------------------------------------- | ||
local population = 55499301 | local population = 55499301 | ||
local unemploymentRate = 0.04 -- 4% unemployment | local unemploymentRate = 0.04 -- 4% unemployment | ||
local employedPopulation = math.floor(population * (1 - unemploymentRate)) | local employedPopulation = math.floor(population * (1 - unemploymentRate)) | ||
| Line 42: | Line 39: | ||
local companies = { | local companies = { | ||
{name = "Lake Morovia Blockade Fund", employmentPercentage = 0.0300}, | {name = "Lake Morovia Blockade Fund", employmentPercentage = 0.0300}, | ||
{name = "Gladeseed Farmers' Union", employmentPercentage = 0.1205}, | {name = "Gladeseed Farmers' Union", employmentPercentage = 0.1205}, | ||
{name = "Atterian Cattle Drivers", employmentPercentage = 0.0502}, | {name = "Atterian Cattle Drivers", employmentPercentage = 0.0502}, | ||
{name = "Roving Wind Farm Corporation", employmentPercentage = 0.0210}, | {name = "Roving Wind Farm Corporation", employmentPercentage = 0.0210}, | ||
{name = "Baratar Corporation", employmentPercentage = 0.0401}, | {name = "Baratar Corporation", employmentPercentage = 0.0401}, | ||
{name = "Noctic Fleet", employmentPercentage = 0.0603}, | {name = "Noctic Fleet", employmentPercentage = 0.0603}, | ||
{name = "Keepers of the Bloodbaths of Laprind", employmentPercentage = 0.0105}, | {name = "Keepers of the Bloodbaths of Laprind", employmentPercentage = 0.0105}, | ||
{name = "Jogiani Merchants of Manwine", employmentPercentage = 0.0208}, | {name = "Jogiani Merchants of Manwine", employmentPercentage = 0.0208}, | ||
{name = "Keepers of the Grove of Zoe Elm", employmentPercentage = 0.0112}, | {name = "Keepers of the Grove of Zoe Elm",employmentPercentage = 0.0112}, | ||
{name = "Plains of Jogi", employmentPercentage = 0.0807}, | {name = "Plains of Jogi", employmentPercentage = 0.0807}, | ||
{name = "Ale of the Night Central Brewery", employmentPercentage = 0.0201}, | {name = "Ale of the Night Central Brewery", employmentPercentage = 0.0201}, | ||
{name = "Camel Herders of the Jangsong Province", employmentPercentage = 0.0306}, | {name = "Camel Herders of the Jangsong Province", employmentPercentage = 0.0306}, | ||
{name = "Thalassian Temple Granite Export Cooperative", employmentPercentage = 0.0310}, | {name = "Thalassian Temple Granite Export Cooperative", employmentPercentage = 0.0310}, | ||
{name = "East Keltian Iron Company", employmentPercentage = 0.0415}, | {name = "East Keltian Iron Company", employmentPercentage = 0.0415}, | ||
{name = "Mylecian Coal Ports", employmentPercentage = 0.0317}, | {name = "Mylecian Coal Ports", employmentPercentage = 0.0317}, | ||
{name = "Merchants of the Valley of Diamonds", employmentPercentage = 0.0102}, | {name = "Merchants of the Valley of Diamonds", employmentPercentage = 0.0102}, | ||
{name = "Maritime Guild of the Cult of Maskmakers", employmentPercentage = 0.0109}, | {name = "Maritime Guild of the Cult of Maskmakers", employmentPercentage = 0.0109}, | ||
{name = "Hatch Ministry", employmentPercentage = 0.0203}, | {name = "Hatch Ministry", employmentPercentage = 0.0203}, | ||
{name = "Anterran Imports and Services", employmentPercentage = 0.0113}, | {name = "Anterran Imports and Services", employmentPercentage = 0.0113}, | ||
{name = "East Keltian Timber Company", employmentPercentage = 0.0312}, | {name = "East Keltian Timber Company", employmentPercentage = 0.0312}, | ||
{name = "Grand Cave Bee Meadery", employmentPercentage = 0.0215}, | {name = "Grand Cave Bee Meadery", employmentPercentage = 0.0215}, | ||
{name = "Merchant Guild of the Poppy Goddess", employmentPercentage = 0.0111}, | {name = "Merchant Guild of the Poppy Goddess", employmentPercentage = 0.0111}, | ||
{name = "Cinnamon Plains of Rouge", employmentPercentage = 0.0218}, | {name = "Cinnamon Plains of Rouge", employmentPercentage = 0.0218}, | ||
{name = "Seamstresses of Rouge", employmentPercentage = 0.0114}, | {name = "Seamstresses of Rouge", employmentPercentage = 0.0114}, | ||
{name = "Salurian Temple of Sacred Horehound", employmentPercentage = 0.0212}, | {name = "Salurian Temple of Sacred Horehound", employmentPercentage = 0.0212}, | ||
{name = "Suncliff Fisheries", employmentPercentage = 0.0309}, | {name = "Suncliff Fisheries", employmentPercentage = 0.0309}, | ||
{name = "Bird Keepers of Saluria", employmentPercentage = 0.0108}, | {name = "Bird Keepers of Saluria", employmentPercentage = 0.0108}, | ||
{name = "Velvet Homestead", employmentPercentage = 0.0110}, | {name = "Velvet Homestead", employmentPercentage = 0.0110}, | ||
{name = "Hunters of the Giant Fanged Penguin", employmentPercentage = 0.0116}, | {name = "Hunters of the Giant Fanged Penguin", employmentPercentage = 0.0116}, | ||
{name = "Professional Pillarion League", employmentPercentage = 0.0052}, | {name = "Professional Pillarion League", employmentPercentage = 0.0052}, | ||
{name = "La Sái Ebile", employmentPercentage = 0.0104}, | {name = "La Sái Ebile", employmentPercentage = 0.0104}, | ||
{name = "Temple Bank of the Reformed Stripping Path", employmentPercentage = 0.0118}, | {name = "Temple Bank of the Reformed Stripping Path", employmentPercentage = 0.0118}, | ||
{name = "Market Hanavusu", employmentPercentage = 0.0157}, | {name = "Market Hanavusu", employmentPercentage = 0.0157}, | ||
{name = "Couriers of the Lizard Queen", employmentPercentage = 0.0117}, | {name = "Couriers of the Lizard Queen", employmentPercentage = 0.0117}, | ||
{name = "Temple University of Delphica", employmentPercentage = 0.0209}, | {name = "Temple University of Delphica", employmentPercentage = 0.0209}, | ||
{name = "Trans-Morovian Railway Company", employmentPercentage = 0.0155} | {name = "Trans-Morovian Railway Company", employmentPercentage = 0.0155}, | ||
} | } | ||
| Line 85: | Line 82: | ||
local function calculateEmployees(company) | local function calculateEmployees(company) | ||
local currentEmployees = math.floor(employedPopulation * company.employmentPercentage) | local currentEmployees = math.floor(employedPopulation * company.employmentPercentage) | ||
local maxChange = math.floor(currentEmployees * 0.25) | local maxChange = math.floor(currentEmployees * 0.25) | ||
local changeAmount = math.random(-maxChange, maxChange) | local changeAmount = math.random(-maxChange, maxChange) | ||
local newEmployees = math.max(1, currentEmployees + changeAmount) | local newEmployees = math.max(1, currentEmployees + changeAmount) | ||
return currentEmployees, newEmployees | return currentEmployees, newEmployees | ||
end | end | ||
| Line 95: | Line 92: | ||
-- Seeds randomness by the day so that results are | -- Seeds randomness by the day so that results are | ||
-- stable for that day but refresh the next day. | -- stable for that day but refresh the next day. | ||
-- Rows colored: | |||
-- • Increase ⇒ light blue | |||
-- • Same ⇒ light green | |||
-- • Decrease ⇒ light red | |||
--------------------------------------------------------- | --------------------------------------------------------- | ||
function p.generateTable() | function p.generateTable() | ||
-- (A) | -- (A) Seed daily randomness | ||
local localTime = os.date("*t") | local localTime = os.date("*t") | ||
math.randomseed(localTime.year * 1000 + localTime.yday) | |||
-- (B) Get | -- (B) Get date | ||
local date, _, _ = getCurrentDate() | local date, _, _ = getCurrentDate() | ||
-- (C) Table header | |||
local wikitable = "{| class=\"wikitable\"\n" | |||
.. "! Date !! Company !! Employment % !! Previous Employees !! Current Employees !! Change\n" | |||
local totalEmployed = 0 | local totalEmployed = 0 | ||
-- ( | -- (D) Per-company rows | ||
for _, company in ipairs(companies) do | for _, company in ipairs(companies) do | ||
local | local prevE, currE = calculateEmployees(company) | ||
local | local changeType | ||
if currE > prevE then | |||
changeType = "Increased" | |||
elseif currE < prevE then | |||
changeType = "Decreased" | |||
else | |||
changeType = "Same" | |||
end | |||
-- choose row color | |||
local rowStyle | |||
if changeType == "Increased" then | |||
rowStyle = ' style="background-color:lightblue;"' | |||
elseif changeType == "Same" then | |||
rowStyle = ' style="background-color:lightgreen;"' | |||
else | |||
rowStyle = ' style="background-color:#ffcccb;"' | |||
end | |||
totalEmployed = totalEmployed + currE | |||
wikitable = wikitable .. string.format( | wikitable = wikitable .. string.format( | ||
"|-\n| %s || %s || %.2f%% || %d || %d || %s\n", | "|-%s\n| %s || %s || %.2f%% || %d || %d || %s\n", | ||
rowStyle, | |||
date, | date, | ||
company.name, | company.name, | ||
company.employmentPercentage * 100, | company.employmentPercentage * 100, | ||
prevE, | |||
currE, | |||
changeType | |||
) | ) | ||
end | end | ||
-- ( | -- (E) Totals row | ||
local totalUnemployed = population - totalEmployed | local totalUnemployed = population - totalEmployed | ||
wikitable = wikitable | wikitable = wikitable | ||
.. string.format("|-\n| Total Employed || || || || %d ||\n", totalEmployed) | .. string.format("|-\n| Total Employed || || || || %d ||\n", totalEmployed) | ||
.. string.format("|-\n| Total Unemployed || || || || %d ||\n|}", totalUnemployed) | .. string.format("|-\n| Total Unemployed || || || || %d ||\n|}", totalUnemployed) | ||
Revision as of 15:59, 22 April 2025
Documentation for this module may be created at Module:BassaridEmployment/doc
local p = {}
---------------------------------------------------------
-- 1. getCurrentDate
-- Returns a date string in PSSC format, plus day/month
---------------------------------------------------------
local function 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
local month, dayOfMonth
if dayOfYear <= 61 then
month = 1; dayOfMonth = dayOfYear
elseif dayOfYear <= 122 then
month = 2; dayOfMonth = dayOfYear - 61
else
month = 3; dayOfMonth = dayOfYear - 122
end
return string.format("%d/%d/%d [[PSSC]]", dayOfMonth, month, psscYear), dayOfMonth, month
end
---------------------------------------------------------
-- 2. Basic Setup
---------------------------------------------------------
local population = 55499301
local unemploymentRate = 0.04 -- 4% unemployment
local employedPopulation = math.floor(population * (1 - unemploymentRate))
-- Company table and their employment percentages
local companies = {
{name = "Lake Morovia Blockade Fund", employmentPercentage = 0.0300},
{name = "Gladeseed Farmers' Union", employmentPercentage = 0.1205},
{name = "Atterian Cattle Drivers", employmentPercentage = 0.0502},
{name = "Roving Wind Farm Corporation", employmentPercentage = 0.0210},
{name = "Baratar Corporation", employmentPercentage = 0.0401},
{name = "Noctic Fleet", employmentPercentage = 0.0603},
{name = "Keepers of the Bloodbaths of Laprind", employmentPercentage = 0.0105},
{name = "Jogiani Merchants of Manwine", employmentPercentage = 0.0208},
{name = "Keepers of the Grove of Zoe Elm",employmentPercentage = 0.0112},
{name = "Plains of Jogi", employmentPercentage = 0.0807},
{name = "Ale of the Night Central Brewery", employmentPercentage = 0.0201},
{name = "Camel Herders of the Jangsong Province", employmentPercentage = 0.0306},
{name = "Thalassian Temple Granite Export Cooperative", employmentPercentage = 0.0310},
{name = "East Keltian Iron Company", employmentPercentage = 0.0415},
{name = "Mylecian Coal Ports", employmentPercentage = 0.0317},
{name = "Merchants of the Valley of Diamonds", employmentPercentage = 0.0102},
{name = "Maritime Guild of the Cult of Maskmakers", employmentPercentage = 0.0109},
{name = "Hatch Ministry", employmentPercentage = 0.0203},
{name = "Anterran Imports and Services", employmentPercentage = 0.0113},
{name = "East Keltian Timber Company", employmentPercentage = 0.0312},
{name = "Grand Cave Bee Meadery", employmentPercentage = 0.0215},
{name = "Merchant Guild of the Poppy Goddess", employmentPercentage = 0.0111},
{name = "Cinnamon Plains of Rouge", employmentPercentage = 0.0218},
{name = "Seamstresses of Rouge", employmentPercentage = 0.0114},
{name = "Salurian Temple of Sacred Horehound", employmentPercentage = 0.0212},
{name = "Suncliff Fisheries", employmentPercentage = 0.0309},
{name = "Bird Keepers of Saluria", employmentPercentage = 0.0108},
{name = "Velvet Homestead", employmentPercentage = 0.0110},
{name = "Hunters of the Giant Fanged Penguin", employmentPercentage = 0.0116},
{name = "Professional Pillarion League", employmentPercentage = 0.0052},
{name = "La Sái Ebile", employmentPercentage = 0.0104},
{name = "Temple Bank of the Reformed Stripping Path", employmentPercentage = 0.0118},
{name = "Market Hanavusu", employmentPercentage = 0.0157},
{name = "Couriers of the Lizard Queen", employmentPercentage = 0.0117},
{name = "Temple University of Delphica", employmentPercentage = 0.0209},
{name = "Trans-Morovian Railway Company", employmentPercentage = 0.0155},
}
---------------------------------------------------------
-- 3. Random Variation
-- Up to ±25% daily shift in each company's employees
---------------------------------------------------------
local function calculateEmployees(company)
local currentEmployees = math.floor(employedPopulation * company.employmentPercentage)
local maxChange = math.floor(currentEmployees * 0.25)
local changeAmount = math.random(-maxChange, maxChange)
local newEmployees = math.max(1, currentEmployees + changeAmount)
return currentEmployees, newEmployees
end
---------------------------------------------------------
-- 4. generateTable
-- Seeds randomness by the day so that results are
-- stable for that day but refresh the next day.
-- Rows colored:
-- • Increase ⇒ light blue
-- • Same ⇒ light green
-- • Decrease ⇒ light red
---------------------------------------------------------
function p.generateTable()
-- (A) Seed daily randomness
local localTime = os.date("*t")
math.randomseed(localTime.year * 1000 + localTime.yday)
-- (B) Get date
local date, _, _ = getCurrentDate()
-- (C) Table header
local wikitable = "{| class=\"wikitable\"\n"
.. "! Date !! Company !! Employment % !! Previous Employees !! Current Employees !! Change\n"
local totalEmployed = 0
-- (D) Per-company rows
for _, company in ipairs(companies) do
local prevE, currE = calculateEmployees(company)
local changeType
if currE > prevE then
changeType = "Increased"
elseif currE < prevE then
changeType = "Decreased"
else
changeType = "Same"
end
-- choose row color
local rowStyle
if changeType == "Increased" then
rowStyle = ' style="background-color:lightblue;"'
elseif changeType == "Same" then
rowStyle = ' style="background-color:lightgreen;"'
else
rowStyle = ' style="background-color:#ffcccb;"'
end
totalEmployed = totalEmployed + currE
wikitable = wikitable .. string.format(
"|-%s\n| %s || %s || %.2f%% || %d || %d || %s\n",
rowStyle,
date,
company.name,
company.employmentPercentage * 100,
prevE,
currE,
changeType
)
end
-- (E) Totals row
local totalUnemployed = population - totalEmployed
wikitable = wikitable
.. string.format("|-\n| Total Employed || || || || %d ||\n", totalEmployed)
.. string.format("|-\n| Total Unemployed || || || || %d ||\n|}", totalUnemployed)
return wikitable
end
return p