Module:GeneralPortMarketLog: Difference between revisions

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


-- 1) Date logic unchanged...
-- 1) Date logic
function p.getCurrentDate()
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 secondsInDay = 86400
     local daysPerYear = 183
     local daysPerYear   = 183


     local currentDate = os.time()
     local currentDate       = os.time()
     local totalDaysElapsed = math.floor((currentDate - startDate) / secondsInDay)
     local totalDaysElapsed = math.floor((currentDate - startDate) / secondsInDay)


     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


     return psscYear, dayOfYear
     return psscYear, dayOfYear
end
end


-- 2) Helpers unchanged...
-- 2) Random choice helper
local function randomChoice(t)
local function randomChoice(t)
     return t[math.random(#t)]
     return t[math.random(#t)]
end
end


-- 3) Global price helpers unchanged...
-- 3) Shared price shift
-- [getGlobalClosePrice(), getInvestorClosingValues() as before]
local function getGlobalClosePrice()
    local date      = os.date("*t")
    local dailySeed = date.year * 1000 + date.yday
    math.randomseed(dailySeed)
    local priceShift = math.random(-3, 3)
    return 30 + priceShift, priceShift
end


-- 4) NATIONAL POPULATION CONSTANT
-- 4) Investor closing values
local nationalPopulation = 82,545,451  -- total population of the nation
local function getInvestorClosingValues()
    local companies = {
        {name = "Vaeringheim Regional Investor", shares = 17424},
        {name = "Alpazkigz Regional Investor", shares = 16214},
        {name = "Odiferia Regional Investor", shares = 14718},
        {name = "Hafaan Regional Investor", shares = 3630},
        {name = "Jeseri Regional Investor", shares = 1870},
        {name = "Hatch Ministry Regional Investor", shares = 7810},
        {name = "New South Jangsong Division", shares = 11085},
        {name = "Haifan Bassaridia Division", shares = 12500}
    }


    local closePrice = getGlobalClosePrice()
    local closing    = {}
    for _, c in ipairs(companies) do
        table.insert(closing, {
            name  = c.name,
            value = c.shares * closePrice
        })
    end
    table.sort(closing, function(a, b) return a.value > b.value end)
    return closing, closePrice
end
-- 5) National population constant
local nationalPopulation = 82,545,451  -- total population
-- 6) Main log generator
function p.generateMarketLog()
function p.generateMarketLog()
     local year, day = p.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)


     -- closingData, closePrice, priceChange, regionalReport, stock flows, etc. unchanged...
     -- get stock data
    local closingData, closePrice = getInvestorClosingValues()
    local priceChange             = closePrice - 30


     -- STIPEND VOUCHERS REDEEMED
     -- stipend redemption: between 0.05% and 0.20% of population
    -- Use between 0.05% and 0.20% of the national population each day:
     local minRedemption = math.floor(nationalPopulation * 0.0005)
     local minRedemption = math.floor(nationalPopulation * 0.0005)
     local maxRedemption = math.floor(nationalPopulation * 0.0020)
     local maxRedemption = math.floor(nationalPopulation * 0.0020)
     local stipendRedemption = math.random(minRedemption, maxRedemption)
     local stipendRedemption = math.random(minRedemption, maxRedemption)


     -- COMMODITY VOLUME unchanged or adjust similarly if desired
     -- commodity redemption volume
     local commodityVolume = math.random(3000, 4000)
     local commodityVolume = math.random(3000, 4000)


     -- ...rest of your data gathering...
     -- regional report
    local regionalReport = randomChoice({
        "Vaeringheim Regional Investor signals stable growth.",
        "Somniumpolis reports surge in logistics volume.",
        "Delphica trade volumes trending downward slightly.",
        "Keybir-Aviv reports spike in demand for security equipment.",
        "Ephyra surplus noted in cold storage capacity."
    })


     -- BUILD WIKITABLE
     -- stock flows
    local stockInflows  = math.random(2000, 8000)
    local stockOutflows = math.random(2000, 8000)
    local netFlow      = stockInflows - stockOutflows
    local tradeStatus  = netFlow > 0 and "Surplus" or "Shortage"
 
    -- pick some exporters
    local companies = {
        "Lake Morovia Blockade Fund", "Gladeseed Farmers' Union", "Atterian Cattle Drivers Company",
        "Roving Wind Farm Corporation", "Baratar Corporation", "Noctic Fleet",
        "Keepers of the Bloodbaths of Laprind", "Jogiani Merchants of Manwine", "Keepers of the Grove of Zoe Elm",
        "Plains of Jogi", "Ale of the Night Central Brewery", "Camel Herders of the Jangsong Province",
        "Thalassian Temple Granite Export Cooperative", "East Keltian Iron Company", "Mylecian Coal Ports",
        "Merchants of the Valley of Diamonds", "Maritime Guild of the Cult of Maskmakers", "Hatch Ministry",
        "Anterran Imports and Services", "East Keltian Timber Company", "Grand Cave Bee Meadery",
        "Merchant Guild of the Poppy Goddess", "Cinnamon Plains of Rouge", "Velvet Homestead",
        "Seamstresses of Rouge", "Ergonian Spy Agency", "Commune of the Garganid Apostles",
        "Oceanic Boot Company", "Temple Bank of the Reformed Stripping Path", "Salurian Temple of Sacred Horehound",
        "Couriers of the Lizard Queen", "Temple University of Delphica", "Shï Collective",
        "Bulhanu Ranchers' Association", "Suncliff Fisheries", "Order of the Sphinx",
        "Ministers of Mistress Mugwort", "Blood Vineyards of the Far North", "Norsolyrian Wisp Rice Farmers Association",
        "La Sái Ebile", "Market Hanavusu", "Giid-Lisea Ranching Import Company",
        "Bird Keepers of Saluria", "Trans-Morovian Railway Company", "Hunters of the Giant Fanged Penguin",
        "Hellhound Breeders of Dragevik", "Somniant Stock Fund", "Aminian Coffee Company",
        "Knights Castle Reindeer Herders", "Lindley Whaling Company", "Copper Mines of Southern Jogi"
    }
    local exports = {}
    for _ = 1, 10 do
        table.insert(exports, randomChoice(companies))
    end
 
    -- build import list from closingData
    local imports = {}
    for _, data in ipairs(closingData) do
        table.insert(imports, string.format("%s (%.2f Poli)", data.name, data.value))
    end
 
    -- construct the wikitext
     local log = "{| class=\"wikitable\" style=\"width:100%\"\n"
     local log = "{| class=\"wikitable\" style=\"width:100%\"\n"
     log = log .. string.format("! colspan=2 | General Port of Lake Morovia – Market Activity Log (%s)\n", dateStr)
     log = log .. string.format("! colspan=2 | General Port of Lake Morovia – Market Activity Log (%s)\n", dateStr)
Line 53: Line 130:
     log = log .. "|-\n"
     log = log .. "|-\n"
     log = log .. string.format("| '''Commodity Redemption Volume''' || %d tons\n", commodityVolume)
     log = log .. string.format("| '''Commodity Redemption Volume''' || %d tons\n", commodityVolume)
     -- [and the rest of the table as before]
     log = log .. "|-\n"
    log = log .. string.format("| '''Pricing Index Change''' || %+d%%\n", priceChange)
    log = log .. "|-\n"
    log = log .. string.format("| '''Regional Investor Report''' || %s\n", regionalReport)
    log = log .. "|-\n"
    log = log .. string.format("| '''Stock Inflows''' || %d tons\n", stockInflows)
    log = log .. "|-\n"
    log = log .. string.format("| '''Stock Outflows''' || %d tons\n", stockOutflows)
    log = log .. "|-\n"
    log = log .. string.format("| '''Net Trade Flow''' || %s (%+d tons)\n", tradeStatus, netFlow)
    log = log .. "|-\n"
    log = log .. string.format("| '''Top 10 Exporters''' || <ol><li>%s</li></ol>\n", table.concat(exports, "</li><li>"))
    log = log .. "|-\n"
    log = log .. string.format("| '''Top 10 Importers (Regional Investors by Share Value)''' || <ol><li>%s</li></ol>\n", table.concat(imports, "</li><li>"))
    log = log .. "|}"


     return log
     return log
end
end


-- dailyMarketSummary() and return p unchanged
-- 7) Daily summary wrapper
function p.dailyMarketSummary()
    local year, day = p.getCurrentDate()
    local header = string.format("'''General Port of Lake Morovia: Market Log – Day %d, Year %d PSSC'''\n", day, year)
    return header .. p.generateMarketLog()
end
 
-- **Crucial:** return the export table
return p

Revision as of 06:21, 26 April 2025

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

-- Module:GeneralPortMarketLog
local p = {}

-- 1) Date 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

-- 2) Random choice helper
local function randomChoice(t)
    return t[math.random(#t)]
end

-- 3) Shared price shift
local function getGlobalClosePrice()
    local date      = os.date("*t")
    local dailySeed = date.year * 1000 + date.yday
    math.randomseed(dailySeed)
    local priceShift = math.random(-3, 3)
    return 30 + priceShift, priceShift
end

-- 4) Investor closing values
local function getInvestorClosingValues()
    local companies = {
        {name = "Vaeringheim Regional Investor", shares = 17424},
        {name = "Alpazkigz Regional Investor", shares = 16214},
        {name = "Odiferia Regional Investor", shares = 14718},
        {name = "Hafaan Regional Investor", shares = 3630},
        {name = "Jeseri Regional Investor", shares = 1870},
        {name = "Hatch Ministry Regional Investor", shares = 7810},
        {name = "New South Jangsong Division", shares = 11085},
        {name = "Haifan Bassaridia Division", shares = 12500}
    }

    local closePrice = getGlobalClosePrice()
    local closing    = {}
    for _, c in ipairs(companies) do
        table.insert(closing, {
            name  = c.name,
            value = c.shares * closePrice
        })
    end
    table.sort(closing, function(a, b) return a.value > b.value end)
    return closing, closePrice
end

-- 5) National population constant
local nationalPopulation = 82,545,451  -- total population

-- 6) Main log generator
function p.generateMarketLog()
    local year, day = p.getCurrentDate()
    local dateStr  = string.format("Day %d, Y.%d", day, year)

    -- get stock data
    local closingData, closePrice = getInvestorClosingValues()
    local priceChange             = closePrice - 30

    -- stipend redemption: between 0.05% and 0.20% of population
    local minRedemption = math.floor(nationalPopulation * 0.0005)
    local maxRedemption = math.floor(nationalPopulation * 0.0020)
    local stipendRedemption = math.random(minRedemption, maxRedemption)

    -- commodity redemption volume
    local commodityVolume = math.random(3000, 4000)

    -- regional report
    local regionalReport = randomChoice({
        "Vaeringheim Regional Investor signals stable growth.",
        "Somniumpolis reports surge in logistics volume.",
        "Delphica trade volumes trending downward slightly.",
        "Keybir-Aviv reports spike in demand for security equipment.",
        "Ephyra surplus noted in cold storage capacity."
    })

    -- stock flows
    local stockInflows  = math.random(2000, 8000)
    local stockOutflows = math.random(2000, 8000)
    local netFlow       = stockInflows - stockOutflows
    local tradeStatus   = netFlow > 0 and "Surplus" or "Shortage"

    -- pick some exporters
    local companies = {
        "Lake Morovia Blockade Fund", "Gladeseed Farmers' Union", "Atterian Cattle Drivers Company",
        "Roving Wind Farm Corporation", "Baratar Corporation", "Noctic Fleet",
        "Keepers of the Bloodbaths of Laprind", "Jogiani Merchants of Manwine", "Keepers of the Grove of Zoe Elm",
        "Plains of Jogi", "Ale of the Night Central Brewery", "Camel Herders of the Jangsong Province",
        "Thalassian Temple Granite Export Cooperative", "East Keltian Iron Company", "Mylecian Coal Ports",
        "Merchants of the Valley of Diamonds", "Maritime Guild of the Cult of Maskmakers", "Hatch Ministry",
        "Anterran Imports and Services", "East Keltian Timber Company", "Grand Cave Bee Meadery",
        "Merchant Guild of the Poppy Goddess", "Cinnamon Plains of Rouge", "Velvet Homestead",
        "Seamstresses of Rouge", "Ergonian Spy Agency", "Commune of the Garganid Apostles",
        "Oceanic Boot Company", "Temple Bank of the Reformed Stripping Path", "Salurian Temple of Sacred Horehound",
        "Couriers of the Lizard Queen", "Temple University of Delphica", "Shï Collective",
        "Bulhanu Ranchers' Association", "Suncliff Fisheries", "Order of the Sphinx",
        "Ministers of Mistress Mugwort", "Blood Vineyards of the Far North", "Norsolyrian Wisp Rice Farmers Association",
        "La Sái Ebile", "Market Hanavusu", "Giid-Lisea Ranching Import Company",
        "Bird Keepers of Saluria", "Trans-Morovian Railway Company", "Hunters of the Giant Fanged Penguin",
        "Hellhound Breeders of Dragevik", "Somniant Stock Fund", "Aminian Coffee Company",
        "Knights Castle Reindeer Herders", "Lindley Whaling Company", "Copper Mines of Southern Jogi"
    }
    local exports = {}
    for _ = 1, 10 do
        table.insert(exports, randomChoice(companies))
    end

    -- build import list from closingData
    local imports = {}
    for _, data in ipairs(closingData) do
        table.insert(imports, string.format("%s (%.2f Poli)", data.name, data.value))
    end

    -- construct the wikitext
    local log = "{| class=\"wikitable\" style=\"width:100%\"\n"
    log = log .. string.format("! colspan=2 | General Port of Lake Morovia – Market Activity Log (%s)\n", dateStr)
    log = log .. "|-\n"
    log = log .. string.format("| '''Stipend Vouchers Redeemed''' || %d Poli\n", stipendRedemption)
    log = log .. "|-\n"
    log = log .. string.format("| '''Commodity Redemption Volume''' || %d tons\n", commodityVolume)
    log = log .. "|-\n"
    log = log .. string.format("| '''Pricing Index Change''' || %+d%%\n", priceChange)
    log = log .. "|-\n"
    log = log .. string.format("| '''Regional Investor Report''' || %s\n", regionalReport)
    log = log .. "|-\n"
    log = log .. string.format("| '''Stock Inflows''' || %d tons\n", stockInflows)
    log = log .. "|-\n"
    log = log .. string.format("| '''Stock Outflows''' || %d tons\n", stockOutflows)
    log = log .. "|-\n"
    log = log .. string.format("| '''Net Trade Flow''' || %s (%+d tons)\n", tradeStatus, netFlow)
    log = log .. "|-\n"
    log = log .. string.format("| '''Top 10 Exporters''' || <ol><li>%s</li></ol>\n", table.concat(exports, "</li><li>"))
    log = log .. "|-\n"
    log = log .. string.format("| '''Top 10 Importers (Regional Investors by Share Value)''' || <ol><li>%s</li></ol>\n", table.concat(imports, "</li><li>"))
    log = log .. "|}"

    return log
end

-- 7) Daily summary wrapper
function p.dailyMarketSummary()
    local year, day = p.getCurrentDate()
    local header = string.format("'''General Port of Lake Morovia: Market Log – Day %d, Year %d PSSC'''\n", day, year)
    return header .. p.generateMarketLog()
end

-- **Crucial:** return the export table
return p