Module:BassaridMarketActivity: Difference between revisions

From MicrasWiki
Jump to navigationJump to search
NewZimiaGov (talk | contribs)
No edit summary
NewZimiaGov (talk | contribs)
No edit summary
Line 137: Line 137:
         name  = "General Fund of the Imperial Federation (Imperial Federation)",
         name  = "General Fund of the Imperial Federation (Imperial Federation)",
         stocks = 876
         stocks = 876
    },
{
        symbol = "POCO",
        name  = "Port of Corumia (Bassaridia Vaeringheim)",
        stocks = 16054
    },
{
        symbol = "EURA",
        name  = "Port of Euranidom (Bassaridia Vaeringheim)",
        stocks = 15559
    },
{
        symbol = "POSK",
        name  = "Port of Southern Keltiania (Bassaridia Vaeringheim)",
        stocks = 17101
     },
     },
}
}

Revision as of 17:55, 5 June 2025

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

---------------------------------------------------------
-- Module: BassaridiaStockMarketTable
-- 
-- Produces a "stock table" using the same daily logic,
-- randomization, 30% cap, and reason pools as your
-- original "BassaridiaDailyInvestorTable" script.
-- 
-- The key fix here is: we generate valid wikitext
-- rows for each entry so that the table actually shows up.
---------------------------------------------------------

local p = {}

---------------------------------------------------------
-- 1) Date logic, same as original
---------------------------------------------------------
local function getDailyDate()
    local startDate = os.time({year = 1999, month = 8, day = 6})
    local secondsInDay = 86400
    local daysPerYear = 183

    local now = os.time()
    local totalDaysElapsed = math.floor((now - 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

    local dateString = string.format("%d/%d/%d PSSC", dayOfMonth, month, psscYear)
    return dateString, dayOfYear
end

---------------------------------------------------------
-- 2) Data: Tickers/Companies (same stock counts)
---------------------------------------------------------
local companies = {
    {
        flag = [[File:VaeringheimDivisionFlag.png|25px]],
        symbol = "VREG",
        name   = "Vaeringheim Regional Investor (Bassaridia Vaeringheim)",
        stocks = 17424
    },
    {
        flag = [[File:AlpazkigzDivisionFlag.png|25px]],
        symbol = "ALPK",
        name   = "Alpazkigz Regional Investor (Bassaridia Vaeringheim)",
        stocks = 16214
    },
    {
        flag = [[File:OdiferiaFlag.png|25px]],
        symbol = "ODFR",
        name   = "Odiferia Regional Investor (Bassaridia Vaeringheim)",
        stocks = 14718
    },
    {
        flag = [[File:HafaanFlag.png|25px]],
        symbol = "HAFA",
        name   = "Hafaan Regional Investor (Bassaridia Vaeringheim)",
        stocks = 3630
    },
    {
        flag = [[File:JeseriFlag.png|25px]],
        symbol = "JESR",
        name   = "Jeseri Regional Investor (Bassaridia Vaeringheim)",
        stocks = 1870
    },
    {
        flag = [[File:HatchMinistryFlag.png|25px]],
        symbol = "HMIN",
        name   = "Hatch Ministry Regional Investor (Bassaridia Vaeringheim)",
        stocks = 7810
    },
    {
        flag = [[File:NewSouthJangsongFlag.png|25px]],
        symbol = "JANG",
        name   = "New South Jangsong Division (Bassaridia Vaeringheim)",
        stocks = 11085
    },
    {
        flag = [[File:HaifaDivisionFlag.png|25px]],
        symbol = "HBAS",
        name   = "Haifan Bassaridia Division (Bassaridia Vaeringheim)",
        stocks = 12500
    },
    {
        flag = [[File:BassaridianNormarkFlagB.png|25px]],
        symbol = "BSNO",
        name   = "Bassaridian Normark (Bassaridia Vaeringheim)",
        stocks = 8852
    },
 {
        flag = [[File:Kingdom of Moorland flag.png|25px]],
        symbol = "SMOR",
        name   = "Sovereign Moorland Fund (Moorland)",
        stocks = 10546
    },
 {
        symbol = "SVWF",
        name   = "Sovereign Wealth Fund (Imperial Federation)",
        stocks = 827
    },
 {
        symbol = "ADRS",
        name   = "Adrestia Wealth Fund (Imperial Federation)",
        stocks = 7456
    },
 {
        symbol = "HAIF",
        name   = "Haifa Wealth Wealth Fund (Imperial Federation)",
        stocks = 10183
    },

 { 
        symbol = "STRC",
        name   = "Strait of Haifa Corporation (Imperial Federation)",
        stocks = 4493
    },
 { 
        symbol = "BIND",
        name   = "Baicha Heavy Industries (Imperial Federation)",
        stocks = 21183
    },
 { 
        symbol = "GFIF",
        name   = "General Fund of the Imperial Federation (Imperial Federation)",
        stocks = 876
    },
 { 
        symbol = "POCO",
        name   = "Port of Corumia (Bassaridia Vaeringheim)",
        stocks = 16054
    },
 { 
        symbol = "EURA",
        name   = "Port of Euranidom (Bassaridia Vaeringheim)",
        stocks = 15559
    },
 { 
        symbol = "POSK",
        name   = "Port of Southern Keltiania (Bassaridia Vaeringheim)",
        stocks = 17101
    },
}

---------------------------------------------------------
-- 3) Reasons: identical to original
---------------------------------------------------------
local increaseReasons = {
    "Improved logistics at the General Port attracted new investors.",
    "An influx of goods from Delphica boosted trade volume at the port.",
    "High demand for Noctic-Rabrev exports raised investor confidence.",
    "Completion of a new shipping lane connecting Nexa increased activity.",
    "Successful negotiations with Erythros merchants expanded trade.",
    "Festival of Light in Vaeringheim drove significant port activity.",
    "High attendance at the Bassaridia Trade Symposium enhanced reputation.",
    "Discovery of new mineral resources near Acheron increased export potential.",
    "A surge in ceremonial wine exports from the Blood Vineyards bolstered ops.",
    "Efficient cargo handling improvements boosted investor sentiment.",
    "Seasonal agricultural exports from Jogi saw a sharp increase.",
    "High sales of pearl and abalone products boosted port traffic.",
    "Luxury goods from Tel-Amin attracted new high-end investors.",
    "Port capacity expansion in Suncliff improved competitiveness.",
    "Improved relations with Maskmakers Guild stabilized trade routes.",
    "Increased fishing yields around Lake Morovia led to more port activity.",
    "Enhanced security measures at the Port reduced piracy concerns.",
    "Cultural appreciation for Horehound exports boosted confidence.",
    "Trade deals with Saluria expanded port usage significantly.",
    "Demand for silk from the Seamstresses of Rouge improved port revenue.",
    "Moonlit Tide celebrations increased ceremonial goods traffic.",
    "Launch of new Garganid fertilizer shipments attracted agriculture investors.",
    "Global interest in sacred resin exports enhanced shipments.",
    "Marketing campaign highlighted the Port's strategic location.",
    "Completion of high-speed rail connections boosted trade efficiency.",
    "Launch of eco-friendly shipping initiatives attracted global partnerships.",
    "Discovery of rare gemstones near Lake Morovia boosted export activity.",
    "Expansion of refrigerated shipping services opened new perishable markets.",
    "Introduction of automation technology improved cargo processing speeds.",
    "Partnerships with Aurelia’s gold traders expanded high-value exports.",
    "Promotion of Bassaridian craftsmanship increased demand for artisan goods.",
    "Hosting the International Maritime Summit enhanced port prestige.",
    "Revival of ancient trade routes through Nexa increased traffic flow.",
    "Surge in demand for Bassaridian spices and aromatics in global markets.",
    "Successful lobbying for lower tariffs improved competitiveness."
}

local decreaseReasons = {
    "Pirate raids in the Strait of Haifa disrupted shipments to the Port.",
    "Unfavorable weather delayed agriculture exports from Plains of Jogi.",
    "Labor shortages in the Port caused cargo-handling delays.",
    "A major fire in Salurian sacred groves reduced resin exports.",
    "Rising costs of Noctic-Rabrev cultivation hurt confidence.",
    "Unrest in Jangsong Province disrupted camel meat shipments.",
    "Currency fluctuations in Vaeringheim affected stability.",
    "Economic sanctions on neighbors reduced export activity.",
    "Decline in ceremonial artifact production lowered traffic.",
    "Cultural disputes over Horehound caused export delays.",
    "Counterfeit relics in Nexa harmed the port's reputation.",
    "Fishing yields were outpaced by demand, reducing shipments.",
    "Decline in pearl quality from Anterran sources lowered interest.",
    "Shortage of ceremonial wine from Blood Vineyards cut exports.",
    "Unrest among Maskmaker merchants disrupted trade agreements.",
    "Less demand for silk from Seamstresses of Rouge impacted flows.",
    "Collapse of trade agreement with Tel-Amin lowered volume.",
    "Seasonal labor shortages shrank port shipments significantly.",
    "Disruptions in Suncliff Fisheries slowed aquatic exports.",
    "Alternative shipping routes bypassed the Port altogether.",
    "Economic downturn in Lunalis Sancta reduced investor interest.",
    "Lingering piracy concerns in Haifan waters harmed confidence.",
    "Failure at Bassaridia Trade Symposium lowered traffic.",
    "Natural disasters near Acheron destroyed key routes.",
    "Sabotage of port infrastructure caused shipping delays.",
    "Political unrest in Delphica disrupted key supply lines.",
    "Drought in Jogi impacted seasonal agricultural yields.",
    "Industrial disputes in Nexa delayed mineral shipments.",
    "Spread of disease among sea cows affected meat exports.",
    "Loss of a major trade partner due to diplomatic tensions.",
    "Contamination of sacred resin shipments led to export bans.",
    "Competing ports in nearby regions diverted trade flows.",
    "Global recession reduced overall demand for luxury goods.",
    "Infrastructure failure in Vaeringheim caused extended delays.",
    "Disruption of shipping lanes due to geopolitical conflict.",
    "Corruption scandals involving port officials reduced trust."
}

---------------------------------------------------------
-- 4) Utility: pop a unique reason
---------------------------------------------------------
local function popUniqueReason(list)
    if #list == 0 then
        return "(No reason: out of reasons!)"
    end
    local i = math.random(#list)
    local r = list[i]
    table.remove(list, i)
    return r
end

---------------------------------------------------------
-- 5) Half up, half down
---------------------------------------------------------
local function assignUpDown(count)
    local half = math.floor(count / 2)
    local arr = {}
    for i = 1, half do
        arr[#arr+1] = "Inc"
    end
    for i = half+1, count do
        arr[#arr+1] = "Dec"
    end
    -- shuffle
    for i = #arr, 2, -1 do
        local j = math.random(i)
        arr[i], arr[j] = arr[j], arr[i]
    end
    return arr
end

---------------------------------------------------------
-- 6) Main function: produce the table
---------------------------------------------------------
function p.generateTable(frame)
    -- Seed
    local dateString, dayOfYear = getDailyDate()
    local localTime = os.date("*t")
    local dailySeed = localTime.year * 1000 + localTime.yday
    math.randomseed(dailySeed)

    -- Copy reasons
    local incPool = {}
    for _, r in ipairs(increaseReasons) do incPool[#incPool+1] = r end
    local decPool = {}
    for _, r in ipairs(decreaseReasons) do decPool[#decPool+1] = r end

    local n = #companies
    local directions = assignUpDown(n)

    -- In the original script, each share was valued at 30 Polis
    local sharePrice = 30

    -- Start building the table output
    local out = {}
    table.insert(out, '{| class="wikitable" style="text-align:center; width:100%;"')
    -- Header row (one line, with !! for separate columns)
    table.insert(out, '|-')
    table.insert(out, '! Date !! Symbol !! Company !! Open (Polis) !! Close (Polis) !! Volume !! Change !! Change % !! Reason')

    -- Generate each row
    for i, co in ipairs(companies) do
        local direction = directions[i]
        local stocksStart = co.stocks

        local maxDelta = math.floor(stocksStart * 0.3)
        if maxDelta < 1 then maxDelta = 1 end

        local buy, sell = 0, 0
        if direction == "Inc" then
            buy  = math.random(1, maxDelta)
            sell = math.random(0, buy - 1)
        else
            sell = math.random(1, maxDelta)
            buy  = math.random(0, sell - 1)
        end

        local stocksEnd = stocksStart + buy - sell

        -- Convert to Polis
        local openVal  = stocksStart * sharePrice
        local closeVal = stocksEnd   * sharePrice

        -- Volume => total shares traded
        local volume = buy + sell

        -- Daily change (Polis)
        local changeVal = closeVal - openVal

        -- Change %
        local pctChange = 0
        if openVal > 0 then
            pctChange = (changeVal / openVal) * 100
        end

        -- Reason
        local reason
        if changeVal > 0 then
            reason = popUniqueReason(incPool)
        elseif changeVal < 0 then
            reason = popUniqueReason(decPool)
        else
            -- if no net difference, pick from inc pool
            reason = popUniqueReason(incPool)
        end

        -- Build one row (cells separated by "||")
        local row = table.concat({
            '|-',
            string.format('| %s || %s || %s || %d || %d || %d || %+d || %.2f%% || %s',
                dateString,         -- e.g. "22/01/2025 PSSC"
                co.symbol,
                co.name,
                openVal,
                closeVal,
                volume,
                changeVal,
                pctChange,
                reason
            )
        }, '\n')  -- newline between |- and the row data

        table.insert(out, row)
    end

    table.insert(out, '|}')
    return table.concat(out, '\n')
end

return p