Module:BassaridEmployment: Difference between revisions

From MicrasWiki
Jump to navigationJump to search
NewZimiaGov (talk | contribs)
No edit summary
NewZimiaGov (talk | contribs)
No edit summary
 
(23 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {}
local p = {}
local market = require("Module:BassaridMarketActivity")
local CITY_POP = {
["Vaeringheim"] = 20887650.86,
["Lunalis Sancta"] = 7832869.07,
["Luminaria"] = 6382335.99,
["Serena"] = 6672442.61,
["Symphonara"] = 4351592.87,
["Aurelia"] = 3771379.63,
["Sylvapolis"] = 3481276.21,
["Delphica"] = 2030743.12,
["Catonis Atrium"] = 1682617.10,
["Ferrum Citadel"] = 928339.26,
["Pyralis"] = 12965917.88,
["Nexa"] = 7979025.10,
["Saluria"] = 7729680.74,
["Acheron"] = 4238856.91,
["Koinonía"] = 5485581.50,
["Aureum"] = 4488201.27,
["Aetherium"] = 3740168.19,
["Erythros"] = 3241479.47,
["Somniumpolis"] = 16035032.55,
["Hafaan"] = 3568579.65,
["Jeseri"] = 2430778.52,
["Skýrophos"] = 5132630.96,
["Bjornopolis"] = 4016840.25,
["Aegerheim"] = 3347368.98,
["Norsolyra"] = 2901052.70,
["Thorsalon"] = 2454736.41,
["Myrene"] = 1338945.70,
["Ephyra"] = 1115790.71,
["Thyrea"] = 892632.57,
["Pelagia"] = 669474.43,
["Halicarn"] = 446316.28,
["Keybir-Aviv"] = 4592562.31,
["Tel-Amin"] = 4155174.90,
["Jogi"] = 3936483.03,
["Lewisburg"] = 3280401.91,
["Diamandis"] = 2843014.50,
["Thermosalem"] = 1312160.40,
["Akróstadium"] = 1093466.69,
["Lykopolis"] = 437387.41,
["Sufriya"] = 218693.71,
["Riddersborg"] = 11757190.77,
["Ardclach"] = 5426395.09,
["Ourid"] = 31826487.08,
["Bashkim"] = 23046766.50
}
-- Default sector shares of the employed population.
-- These should sum to 1.00.
local SECTOR_EMPLOYMENT_SHARE = {
agriculture = 0.27,
industry = 0.31,
services = 0.42
}
local MOD = 2147483647
local A  = 1103515245
local C  = 12345
local function hashString(s)
s = tostring(s or "")
local h = 0
for i = 1, #s do
h = (h * 31 + s:byte(i)) % MOD
end
return h
end
local function lcg(seed)
seed = seed % MOD
return function()
seed = (A * seed + C) % MOD
return seed
end
end
local function randUnit(nextInt)
return (nextInt() % 100000) / 100000
end
local function clamp(x, lo, hi)
if x < lo then return lo end
if x > hi then return hi end
return x
end
local function round(num)
return math.floor(num + 0.5)
end


local function getCurrentDate()
local function 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 secondsInDay = 86400
    local daysPerYear = 183
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)
end
 
local function normalizeSectorKey(sector)
sector = tostring(sector or "agriculture"):lower()
if sector == "agriculture" or sector == "ag" then
return "agriculture"
elseif sector == "industry" or sector == "manufacturing" or sector == "manf" then
return "industry"
elseif sector == "services" or sector == "serv" then
return "services"
end
return nil
end


    local currentDate = os.time()
local function getSectorModule(sector)
    local totalDaysElapsed = math.floor((currentDate - startDate) / secondsInDay)
local key = normalizeSectorKey(sector)
if key == "agriculture" then
return require("Module:AutoUpdateAgPrices"), "Agriculture", key
elseif key == "industry" then
return require("Module:AutoUpdateManfPrices"), "Mining / Manufacturing / Energy", key
elseif key == "services" then
return require("Module:AutoUpdateServPrices"), "Services", key
end
return nil, nil, nil
end


    local yearFraction = totalDaysElapsed / daysPerYear
local function getEmploymentSignal(city, cache)
    local psscYear = math.floor(yearFraction)
city = city or "Vaeringheim"
    local dayOfYear = math.floor((yearFraction - psscYear) * daysPerYear) + 1
if cache[city] then
return cache[city]
end


    local month, dayOfMonth
local sig
    if dayOfYear <= 61 then
if market.getEmploymentSignals then
        month = 1
sig = market.getEmploymentSignals(city)
        dayOfMonth = dayOfYear
else
    elseif dayOfYear <= 122 then
sig = { marketScore = 0, volatility = 0 }
        month = 2
end
        dayOfMonth = dayOfYear - 61
    else
        month = 3
        dayOfMonth = dayOfYear - 122
    end


    return string.format("%d/%d/%d [[PSSC]]", dayOfMonth, month, psscYear), dayOfMonth, month
cache[city] = sig
return sig
end
end


local population = 55499301
local function computeWeights(companies)
local unemploymentRate = 0.04 -- Thriving economy with a 4% unemployment rate
local total = 0
local employedPopulation = math.floor(population * (1 - unemploymentRate))
for _, co in ipairs(companies) do
local cityPop = CITY_POP[co.city] or 1000000
local cityFactor = math.max(0.60, math.min(1.50, cityPop / 5000000))
local weight = (co.count or 1) * math.max(0.01, co.avgBase or 0.01) * cityFactor
co.weight = weight
total = total + weight
end
 
if total <= 0 then
local evenWeight = 1 / math.max(1, #companies)
for _, co in ipairs(companies) do
co.weight = evenWeight
end
else
for _, co in ipairs(companies) do
co.weight = co.weight / total
end
end
end
 
function p.generateTable(frame)
frame = frame or {}
local args = (frame.getParent and frame:getParent() and frame:getParent().args) or {}
local fargs = frame.args or {}
 
local sectorArg = fargs.sector or args.sector or "agriculture"
local population = tonumber(fargs.population or args.population) or 293833483.50
local unemploymentRate = tonumber(fargs.unemployment or args.unemployment) or 0.04
 
local sectorModule, sectorLabel, sectorKey = getSectorModule(sectorArg)
if not sectorModule then
return "Invalid sector. Use agriculture, industry, or services."
end
if not sectorModule.getCompanyEmploymentInputs then
return "This sector module does not expose getCompanyEmploymentInputs() yet."
end
 
-- Optional per-sector overrides
local agShare  = tonumber(fargs.ag_share or args.ag_share) or SECTOR_EMPLOYMENT_SHARE.agriculture
local indShare  = tonumber(fargs.ind_share or args.ind_share) or SECTOR_EMPLOYMENT_SHARE.industry
local servShare = tonumber(fargs.serv_share or args.serv_share) or SECTOR_EMPLOYMENT_SHARE.services
 
local sectorShareMap = {
agriculture = agShare,
industry = indShare,
services = servShare
}
 
local sectorShare = sectorShareMap[sectorKey] or 0.33
sectorShare = clamp(sectorShare, 0, 1)


-- Companies and their employment percentages (as a fraction of the employed population)
local employedPopulation = math.floor(population * (1 - unemploymentRate))
local companies = {
local sectorEmploymentPool = math.floor(employedPopulation * sectorShare)
    {name = "Lake Morovia Blockade Fund", employmentPercentage = 0.0300, previousEmployees = 1587000, employees = 1900000},
 
    {name = "Gladeseed Farmers' Union", employmentPercentage = 0.1205, previousEmployees = 6348000, employees = 5800000},
local dateString = getCurrentDate()
    {name = "Atterian Cattle Drivers", employmentPercentage = 0.0502, previousEmployees = 2645000, employees = 2000000},
local localTime = os.date("*t")
    {name = "Roving Wind Farm Corporation", employmentPercentage = 0.0210, previousEmployees = 1058000, employees = 1250000},
local dailySeed = localTime.year * 1000 + localTime.yday
    {name = "Baratar Corporation", employmentPercentage = 0.0401, previousEmployees = 2116000, employees = 2300000},
 
    {name = "Noctic Fleet", employmentPercentage = 0.0603, previousEmployees = 3174000, employees = 4000000},
local companies = sectorModule.getCompanyEmploymentInputs()
    {name = "Keepers of the Bloodbaths of Laprind", employmentPercentage = 0.0105, previousEmployees = 529000, employees = 420000},
computeWeights(companies)
    {name = "Jogiani Merchants of Manwine", employmentPercentage = 0.0208, previousEmployees = 1058000, employees = 990000},
 
    {name = "Keepers of the Grove of Zoe Elm", employmentPercentage = 0.0112, previousEmployees = 529000, employees = 620000},
table.sort(companies, function(a, b) return a.name < b.name end)
    {name = "Plains of Jogi", employmentPercentage = 0.0807, previousEmployees = 4232000, employees = 5000000},
 
    {name = "Ale of the Night Central Brewery", employmentPercentage = 0.0201, previousEmployees = 1058000, employees = 1100000},
local signalCache = {}
    {name = "Camel Herders of the Jangsong Province", employmentPercentage = 0.0306, previousEmployees = 1587000, employees = 1750000},
local out = {}
    {name = "Thalassian Temple Granite Export Cooperative", employmentPercentage = 0.0310, previousEmployees = 1587000, employees = 1800000},
out[#out + 1] = '{| class="wikitable sortable"\n'
    {name = "East Keltian Iron Company", employmentPercentage = 0.0415, previousEmployees = 2116000, employees = 2300000},
out[#out + 1] = '! Date !! Sector !! Company !! City !! Price Change !! Sector Share !! Previous Employees !! Current Employees !! Change\n'
    {name = "Mylecian Coal Ports", employmentPercentage = 0.0317, previousEmployees = 1587000, employees = 1700000},
 
    {name = "Merchants of the Valley of Diamonds", employmentPercentage = 0.0102, previousEmployees = 529000, employees = 550000},
local totalEmployed = 0
    {name = "Maritime Guild of the Cult of Maskmakers", employmentPercentage = 0.0109, previousEmployees = 529000, employees = 450000},
 
    {name = "Hatch Ministry", employmentPercentage = 0.0203, previousEmployees = 1058000, employees = 1000000},
for _, co in ipairs(companies) do
    {name = "Anterran Imports and Services", employmentPercentage = 0.0113, previousEmployees = 529000, employees = 600000},
local baseEmployees = round(sectorEmploymentPool * co.weight)
    {name = "East Keltian Timber Company", employmentPercentage = 0.0312, previousEmployees = 1587000, employees = 1800000},
    {name = "Grand Cave Bee Meadery", employmentPercentage = 0.0215, previousEmployees = 1058000, employees = 1250000},
    {name = "Merchant Guild of the Poppy Goddess", employmentPercentage = 0.0111, previousEmployees = 529000, employees = 530000},
    {name = "Cinnamon Plains of Rouge", employmentPercentage = 0.0218, previousEmployees = 1058000, employees = 1200000},
    {name = "Seamstresses of Rouge", employmentPercentage = 0.0114, previousEmployees = 529000, employees = 600000},
    {name = "Salurian Temple of Sacred Horehound", employmentPercentage = 0.0212, previousEmployees = 1058000, employees = 1100000},
    {name = "Suncliff Fisheries", employmentPercentage = 0.0309, previousEmployees = 1587000, employees = 1800000},
    {name = "Bird Keepers of Saluria", employmentPercentage = 0.0108, previousEmployees = 529000, employees = 450000},
    {name = "Velvet Homestead", employmentPercentage = 0.0110, previousEmployees = 529000, employees = 550000},
    {name = "Hunters of the Giant Fanged Penguin", employmentPercentage = 0.0116, previousEmployees = 529000, employees = 600000},
    {name = "Professional Pillarion League", employmentPercentage = 0.0052, previousEmployees = 264500, employees = 220000},
    {name = "La Sái Ebile", employmentPercentage = 0.0104, previousEmployees = 529000, employees = 490000},
    {name = "Temple Bank of the Reformed Stripping Path", employmentPercentage = 0.0118, previousEmployees = 529000, employees = 530000},
    {name = "Market Hanavusu", employmentPercentage = 0.0157, previousEmployees = 793500, employees = 820000},
    {name = "Couriers of the Lizard Queen", employmentPercentage = 0.0117, previousEmployees = 529000, employees = 500000},
    {name = "Temple University of Delphica", employmentPercentage = 0.0209, previousEmployees = 1058000, employees = 1250000},
    {name = "Trans-Morovian Railway Company", employmentPercentage = 0.0155, previousEmployees = 793500, employees = 850000}
}


-- Function to simulate daily employment changes with a maximum fluctuation of 25%
local sig = getEmploymentSignal(co.city, signalCache)
local function simulateDailyChange(company)
local nextInt = lcg(dailySeed + hashString((co.name or "") .. "|" .. (co.city or "")))
    local changeFactor = math.random(-25, 25) / 100 -- Random change of up to +/- 25%
local jitter = (randUnit(nextInt) - 0.5) * 0.04
    local potentialEmployees = company.previousEmployees + math.floor(company.previousEmployees * changeFactor)
local priceEffect = (tonumber(co.pctChange) or 0) * 0.18 / 100
    company.employees = math.max(1, potentialEmployees) -- Ensure at least 1 employee
local marketEffect = (sig.marketScore or 0) * 0.60
local volDrag = (sig.volatility or 0) * 0.02


    local change = "Increased"
local netEffect = clamp(priceEffect + marketEffect + jitter - volDrag, -0.10, 0.10)
    if company.employees < company.previousEmployees then
local currEmployees = round(baseEmployees * (1 + netEffect))
        change = "Decreased"
if currEmployees < 1 then currEmployees = 1 end
    elseif company.employees == company.previousEmployees then
        change = "No Change"
    end


    company.previousEmployees = company.employees -- Update previous employees for next simulation
local changeText = "Same"
    return company.previousEmployees, company.employees, change
local rowStyle = ' style="background-color:#f3f3f3;"'
end
if currEmployees > baseEmployees then
changeText = "Increased"
rowStyle = ' style="background-color:#d8f0d2;"'
elseif currEmployees < baseEmployees then
changeText = "Decreased"
rowStyle = ' style="background-color:#f8d7d7;"'
end


function p.generateTable()
totalEmployed = totalEmployed + currEmployees
    local date, _, _ = getCurrentDate()
    local totalEmployed = 0
    local wikitable = "{| class=\"wikitable\"\n! Date (Day/Month/Year [[PSSC]]) !! Company !! Employment Percentage !! Previous Employees !! Current Employees !! Change\n"


    for _, company in ipairs(companies) do
out[#out + 1] = string.format(
        local previousEmployees, currentEmployees, change = simulateDailyChange(company)
'|-%s\n| %s || %s || %s || %s || %+0.2f%% || %.1f%% || %d || %d || %s\n',
        totalEmployed = totalEmployed + currentEmployees
rowStyle,
        wikitable = wikitable .. string.format("|-\n| %s || %s || %.2f%% || %d || %d || %s\n",
dateString,
            date, company.name, company.employmentPercentage * 100, previousEmployees, currentEmployees, change)
sectorLabel,
    end
co.name,
co.city or "",
co.pctChange or 0,
(co.weight * 100),
baseEmployees,
currEmployees,
changeText
)
end


    local totalUnemployed = population - totalEmployed
local totalUnemployed = math.max(0, math.floor(population - totalEmployed))
    wikitable = wikitable .. string.format("|-\n| Total Employed || || || || %d || \n| Total Unemployed || || || || %d || \n|}", totalEmployed, totalUnemployed)
out[#out + 1] = string.format('|-\n! colspan="7" | Sector Employment Pool || %d || \n', sectorEmploymentPool)
out[#out + 1] = string.format('|-\n! colspan="7" | Total Employed (this sector) || %d || \n', totalEmployed)
out[#out + 1] = string.format('|-\n! colspan="7" | Total Unemployed (whole population reference) || %d || \n', totalUnemployed)
out[#out + 1] = '|}'


    return wikitable
return table.concat(out)
end
end


return p
return p

Latest revision as of 18:33, 20 March 2026

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

local p = {}

local market = require("Module:BassaridMarketActivity")

local CITY_POP = {
	["Vaeringheim"] = 20887650.86,
	["Lunalis Sancta"] = 7832869.07,
	["Luminaria"] = 6382335.99,
	["Serena"] = 6672442.61,
	["Symphonara"] = 4351592.87,
	["Aurelia"] = 3771379.63,
	["Sylvapolis"] = 3481276.21,
	["Delphica"] = 2030743.12,
	["Catonis Atrium"] = 1682617.10,
	["Ferrum Citadel"] = 928339.26,
	["Pyralis"] = 12965917.88,
	["Nexa"] = 7979025.10,
	["Saluria"] = 7729680.74,
	["Acheron"] = 4238856.91,
	["Koinonía"] = 5485581.50,
	["Aureum"] = 4488201.27,
	["Aetherium"] = 3740168.19,
	["Erythros"] = 3241479.47,
	["Somniumpolis"] = 16035032.55,
	["Hafaan"] = 3568579.65,
	["Jeseri"] = 2430778.52,
	["Skýrophos"] = 5132630.96,
	["Bjornopolis"] = 4016840.25,
	["Aegerheim"] = 3347368.98,
	["Norsolyra"] = 2901052.70,
	["Thorsalon"] = 2454736.41,
	["Myrene"] = 1338945.70,
	["Ephyra"] = 1115790.71,
	["Thyrea"] = 892632.57,
	["Pelagia"] = 669474.43,
	["Halicarn"] = 446316.28,
	["Keybir-Aviv"] = 4592562.31,
	["Tel-Amin"] = 4155174.90,
	["Jogi"] = 3936483.03,
	["Lewisburg"] = 3280401.91,
	["Diamandis"] = 2843014.50,
	["Thermosalem"] = 1312160.40,
	["Akróstadium"] = 1093466.69,
	["Lykopolis"] = 437387.41,
	["Sufriya"] = 218693.71,
	["Riddersborg"] = 11757190.77,
	["Ardclach"] = 5426395.09,
	["Ourid"] = 31826487.08,
	["Bashkim"] = 23046766.50
}

-- Default sector shares of the employed population.
-- These should sum to 1.00.
local SECTOR_EMPLOYMENT_SHARE = {
	agriculture = 0.27,
	industry = 0.31,
	services = 0.42
}

local MOD = 2147483647
local A   = 1103515245
local C   = 12345

local function hashString(s)
	s = tostring(s or "")
	local h = 0
	for i = 1, #s do
		h = (h * 31 + s:byte(i)) % MOD
	end
	return h
end

local function lcg(seed)
	seed = seed % MOD
	return function()
		seed = (A * seed + C) % MOD
		return seed
	end
end

local function randUnit(nextInt)
	return (nextInt() % 100000) / 100000
end

local function clamp(x, lo, hi)
	if x < lo then return lo end
	if x > hi then return hi end
	return x
end

local function round(num)
	return math.floor(num + 0.5)
end

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)
end

local function normalizeSectorKey(sector)
	sector = tostring(sector or "agriculture"):lower()
	if sector == "agriculture" or sector == "ag" then
		return "agriculture"
	elseif sector == "industry" or sector == "manufacturing" or sector == "manf" then
		return "industry"
	elseif sector == "services" or sector == "serv" then
		return "services"
	end
	return nil
end

local function getSectorModule(sector)
	local key = normalizeSectorKey(sector)
	if key == "agriculture" then
		return require("Module:AutoUpdateAgPrices"), "Agriculture", key
	elseif key == "industry" then
		return require("Module:AutoUpdateManfPrices"), "Mining / Manufacturing / Energy", key
	elseif key == "services" then
		return require("Module:AutoUpdateServPrices"), "Services", key
	end
	return nil, nil, nil
end

local function getEmploymentSignal(city, cache)
	city = city or "Vaeringheim"
	if cache[city] then
		return cache[city]
	end

	local sig
	if market.getEmploymentSignals then
		sig = market.getEmploymentSignals(city)
	else
		sig = { marketScore = 0, volatility = 0 }
	end

	cache[city] = sig
	return sig
end

local function computeWeights(companies)
	local total = 0
	for _, co in ipairs(companies) do
		local cityPop = CITY_POP[co.city] or 1000000
		local cityFactor = math.max(0.60, math.min(1.50, cityPop / 5000000))
		local weight = (co.count or 1) * math.max(0.01, co.avgBase or 0.01) * cityFactor
		co.weight = weight
		total = total + weight
	end

	if total <= 0 then
		local evenWeight = 1 / math.max(1, #companies)
		for _, co in ipairs(companies) do
			co.weight = evenWeight
		end
	else
		for _, co in ipairs(companies) do
			co.weight = co.weight / total
		end
	end
end

function p.generateTable(frame)
	frame = frame or {}
	local args = (frame.getParent and frame:getParent() and frame:getParent().args) or {}
	local fargs = frame.args or {}

	local sectorArg = fargs.sector or args.sector or "agriculture"
	local population = tonumber(fargs.population or args.population) or 293833483.50
	local unemploymentRate = tonumber(fargs.unemployment or args.unemployment) or 0.04

	local sectorModule, sectorLabel, sectorKey = getSectorModule(sectorArg)
	if not sectorModule then
		return "Invalid sector. Use agriculture, industry, or services."
	end
	if not sectorModule.getCompanyEmploymentInputs then
		return "This sector module does not expose getCompanyEmploymentInputs() yet."
	end

	-- Optional per-sector overrides
	local agShare   = tonumber(fargs.ag_share or args.ag_share) or SECTOR_EMPLOYMENT_SHARE.agriculture
	local indShare  = tonumber(fargs.ind_share or args.ind_share) or SECTOR_EMPLOYMENT_SHARE.industry
	local servShare = tonumber(fargs.serv_share or args.serv_share) or SECTOR_EMPLOYMENT_SHARE.services

	local sectorShareMap = {
		agriculture = agShare,
		industry = indShare,
		services = servShare
	}

	local sectorShare = sectorShareMap[sectorKey] or 0.33
	sectorShare = clamp(sectorShare, 0, 1)

	local employedPopulation = math.floor(population * (1 - unemploymentRate))
	local sectorEmploymentPool = math.floor(employedPopulation * sectorShare)

	local dateString = getCurrentDate()
	local localTime = os.date("*t")
	local dailySeed = localTime.year * 1000 + localTime.yday

	local companies = sectorModule.getCompanyEmploymentInputs()
	computeWeights(companies)

	table.sort(companies, function(a, b) return a.name < b.name end)

	local signalCache = {}
	local out = {}
	out[#out + 1] = '{| class="wikitable sortable"\n'
	out[#out + 1] = '! Date !! Sector !! Company !! City !! Price Change !! Sector Share !! Previous Employees !! Current Employees !! Change\n'

	local totalEmployed = 0

	for _, co in ipairs(companies) do
		local baseEmployees = round(sectorEmploymentPool * co.weight)

		local sig = getEmploymentSignal(co.city, signalCache)
		local nextInt = lcg(dailySeed + hashString((co.name or "") .. "|" .. (co.city or "")))
		local jitter = (randUnit(nextInt) - 0.5) * 0.04
		local priceEffect = (tonumber(co.pctChange) or 0) * 0.18 / 100
		local marketEffect = (sig.marketScore or 0) * 0.60
		local volDrag = (sig.volatility or 0) * 0.02

		local netEffect = clamp(priceEffect + marketEffect + jitter - volDrag, -0.10, 0.10)
		local currEmployees = round(baseEmployees * (1 + netEffect))
		if currEmployees < 1 then currEmployees = 1 end

		local changeText = "Same"
		local rowStyle = ' style="background-color:#f3f3f3;"'
		if currEmployees > baseEmployees then
			changeText = "Increased"
			rowStyle = ' style="background-color:#d8f0d2;"'
		elseif currEmployees < baseEmployees then
			changeText = "Decreased"
			rowStyle = ' style="background-color:#f8d7d7;"'
		end

		totalEmployed = totalEmployed + currEmployees

		out[#out + 1] = string.format(
			'|-%s\n| %s || %s || %s || %s || %+0.2f%% || %.1f%% || %d || %d || %s\n',
			rowStyle,
			dateString,
			sectorLabel,
			co.name,
			co.city or "",
			co.pctChange or 0,
			(co.weight * 100),
			baseEmployees,
			currEmployees,
			changeText
		)
	end

	local totalUnemployed = math.max(0, math.floor(population - totalEmployed))
	out[#out + 1] = string.format('|-\n! colspan="7" | Sector Employment Pool || %d || \n', sectorEmploymentPool)
	out[#out + 1] = string.format('|-\n! colspan="7" | Total Employed (this sector) || %d || \n', totalEmployed)
	out[#out + 1] = string.format('|-\n! colspan="7" | Total Unemployed (whole population reference) || %d || \n', totalUnemployed)
	out[#out + 1] = '|}'

	return table.concat(out)
end

return p