Module:BassaridMarketActivity: Difference between revisions

From MicrasWiki
Jump to navigationJump to search
NewZimiaGov (talk | contribs)
No edit summary
NewZimiaGov (talk | contribs)
No edit summary
Tag: Manual revert
Line 28: Line 28:
end
end


local marketHistory = {}
-- Initial figures for Regional Investors
 
local function updateMarketHistory(date, investorName, stocks)
    if not marketHistory[investorName] then
        marketHistory[investorName] = {}
    end
    table.insert(marketHistory[investorName], {date = date, stocks = stocks})
end
 
local function generateGraph()
    if next(marketHistory) == nil then
        return "<script>Graph data is missing</script>"
    end
 
    local traces = {}
 
    for investorName, data in pairs(marketHistory) do
        local x = {}
        local y = {}
 
        for _, entry in ipairs(data) do
            table.insert(x, string.format("'%s'", entry.date))
            table.insert(y, entry.stocks)
        end
 
        table.insert(traces, string.format([[
            {
                x: [%s],
                y: [%s],
                mode: 'lines+markers',
                name: '%s'
            }
        ]], table.concat(x, ", "), table.concat(y, ", "), investorName))
    end
 
    return [[
        <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
        <div id="marketGraph"></div>
        <script>
            var data = [ ]] .. table.concat(traces, ", ") .. [[ ];
            var layout = {
                title: 'Investor Stocks Over Time',
                xaxis: {title: 'Date'},
                yaxis: {title: 'Stocks'}
            };
            Plotly.newPlot('marketGraph', data, layout);
        </script>
    ]]
end
 
local investors = {
local investors = {
     {name = "Vaeringheim Regional Investor", stocks = 17424},
     {name = "Vaeringheim Regional Investor", stocks = 17424},
Line 89: Line 40:
}
}


-- Possible reasons for increase or decrease, specifically tied to the General Port
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 in the port's performance.",
    "Completion of a new shipping lane connecting Nexa to the General Port increased activity.",
    "Successful negotiations with Erythros merchants expanded trade opportunities.",
    "The recent Festival of Light in Vaeringheim drove significant port activity.",
    "High attendance at the Bassaridia Trade Symposium enhanced the port's reputation.",
    "Discovery of new mineral resources near Acheron increased export potential through the port.",
    "A surge in ceremonial wine exports from the Blood Vineyards of the Far North bolstered port operations.",
    "Efficient cargo handling innovations improved investor sentiment at the General Port.",
    "Seasonal agricultural exports from the Plains of Jogi saw a sharp increase.",
    "High sales of pearl and abalone products boosted port activity.",
    "Introduction of luxury goods from Tel-Amin attracted high-end investors.",
    "The expansion of the General Port's capacity in Suncliff enhanced its competitiveness.",
    "Improved relations with Maskmakers Guild merchants stabilized trade routes.",
    "An increase in fishing yields around Lake Morovia led to greater port activity.",
    "Enhanced security measures at the General Port reduced piracy concerns.",
    "Growing cultural appreciation for sacred Horehound exports boosted regional confidence.",
    "Trade agreements with neighboring cities, including Saluria, expanded port usage.",
    "High demand for silk and luxury textiles from Seamstresses of Rouge improved port revenue.",
    "The Moonlit Tide celebration increased ceremonial goods traffic through the port.",
    "Launch of new Garganid fertilizer shipments attracted agricultural investors.",
    "Rising global interest in sacred resin exports enhanced the port's activity.",
    "Successful marketing campaigns highlighted the General Port's strategic importance.",
    "Completion of high-speed rail connections to key cities improved trade efficiency at the port."
}
local decreaseReasons = {
    "Pirate raids in the Strait of Haifa disrupted shipments to the General Port.",
    "Unfavorable weather conditions delayed agricultural exports from the Plains of Jogi.",
    "Labor shortages in the General Port caused delays in cargo handling.",
    "A major fire in Salurian sacred groves reduced resin exports through the port.",
    "Rising costs of Noctic-Rabrev cultivation impacted investor confidence.",
    "Unrest in Jangsong Province disrupted camel meat shipments to the port.",
    "Currency fluctuations in Vaeringheim affected trade stability at the General Port.",
    "Economic sanctions on neighboring cities reduced export activity.",
    "Decline in ceremonial artifact production reduced goods traffic through the port.",
    "Cultural disputes over Horehound cultivation caused delays in exports.",
    "Counterfeit relics discovered in Nexa harmed the port's reputation.",
    "High demand for fishing yields outpaced supply, reducing exports through the port.",
    "Decline in pearl quality from Anterran sources lowered investor interest.",
    "Shortage of ceremonial wine from the Blood Vineyards of the Far North hurt exports.",
    "Unrest among Maskmaker merchants disrupted key trade agreements.",
    "Reduced demand for silk textiles from the Seamstresses of Rouge impacted port activity.",
    "Collapse of a trade agreement with Tel-Amin reduced port volume.",
    "Seasonal labor shortages in agricultural hubs decreased port shipments.",
    "Disruptions in Suncliff Fisheries slowed aquatic exports through the port.",
    "Discovery of alternative shipping routes bypassed the General Port.",
    "Economic downturn in Lunalis Sancta affected investor interest.",
    "Unresolved piracy concerns in Haifan waters harmed trade confidence.",
    "Failure to secure key trade deals during the Bassaridia Trade Symposium reduced traffic.",
    "Natural disasters near Acheron destroyed key trade routes to the port.",
    "Sabotage of port infrastructure caused significant delays in shipments."
}
-- Function to determine tier based on Stocks at End
local function determineTier(stocksAtEnd)
    if stocksAtEnd > 12500 then
        return "Tier I"
    elseif stocksAtEnd >= 5000 and stocksAtEnd <= 12500 then
        return "Tier II"
    else
        return "Tier III"
    end
end
-- Function to simulate daily stock activity
local function simulateDailyActivity(investor)
local function simulateDailyActivity(investor)
     local buyStocks = math.random(0, 500)
     local buyStocks = math.random(0, 500)
Line 97: Line 117:
end
end


function p.generateGraph()
-- Function to generate a reason for change
     local date = getCurrentDate()
local function getReason(change)
    if change == "Increased" then
        return increaseReasons[math.random(#increaseReasons)]
    elseif change == "Decreased" then
        return decreaseReasons[math.random(#decreaseReasons)]
    else
        return "Market activity remained stable."
    end
end
 
function p.generateTable()
     local date, _, _ = getCurrentDate()
    local totalMarketValueAtStart = 0
    local totalMarketValueAtEnd = 0
    local totalBoughtValue = 0
    local totalSoldValue = 0
    local stockPrice = 30 -- Stock price in Polis
 
    local wikitable = "{| class=\"wikitable\"\n! Date (Day/Month/Year [[PSSC]]) !! Investor !! Tier !! Stocks at Start !! Value at Start !! Stocks Bought !! Value of Stocks Bought !! Stocks Sold !! Value of Stocks Sold !! Stocks at End !! Value at End !! Change !! Reason\n"


     for _, investor in ipairs(investors) do
     for _, investor in ipairs(investors) do
         simulateDailyActivity(investor)
         local stocksAtStart = investor.stocks
         updateMarketHistory(date, investor.name, investor.stocks)
        local valueAtStart = stocksAtStart * stockPrice
        local buyStocks, sellStocks = simulateDailyActivity(investor)
         local valueBought = buyStocks * stockPrice
        local valueSold = sellStocks * stockPrice
        local stocksAtEnd = investor.stocks
        local valueAtEnd = stocksAtEnd * stockPrice
        local tier = determineTier(stocksAtEnd)
        local change = "Increased"
 
        if stocksAtEnd < stocksAtStart then
            change = "Decreased"
        elseif stocksAtEnd == stocksAtStart then
            change = "No Change"
        end
 
        local reason = getReason(change)
 
        totalMarketValueAtStart = totalMarketValueAtStart + valueAtStart
        totalMarketValueAtEnd = totalMarketValueAtEnd + valueAtEnd
        totalBoughtValue = totalBoughtValue + valueBought
        totalSoldValue = totalSoldValue + valueSold
 
        wikitable = wikitable .. string.format("|-\n| %s || %s || %s || %d || %d Polis || %d || %d Polis || %d || %d Polis || %d || %d Polis || %s || %s\n",
            date, investor.name, tier, stocksAtStart, valueAtStart, buyStocks, valueBought, sellStocks, valueSold, stocksAtEnd, valueAtEnd, change, reason)
     end
     end


     return generateGraph()
     wikitable = wikitable .. string.format("|-\n| colspan=5 | Total Market Value at Start || %d Polis || %d Polis || %d Polis || %d Polis || ||\n",
        totalMarketValueAtStart, totalBoughtValue, totalSoldValue, totalMarketValueAtEnd)
    wikitable = wikitable .. "|}"
    return wikitable
end
end


return p
return p

Revision as of 20:56, 25 December 2024

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

local p = {}

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

-- Initial figures for Regional Investors
local investors = {
    {name = "Vaeringheim Regional Investor", stocks = 17424},
    {name = "Alpazkigz Regional Investor", stocks = 16214},
    {name = "Odiferia Regional Investor", stocks = 14718},
    {name = "Hafaan Regional Investor", stocks = 3630},
    {name = "Jeseri Regional Investor", stocks = 1870},
    {name = "Hatch Ministry Regional Investor", stocks = 7810},
    {name = "New South Jangsong Division", stocks = 11085},
    {name = "Haifan Bassaridia Division", stocks = 12500},
}

-- Possible reasons for increase or decrease, specifically tied to the General Port
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 in the port's performance.",
    "Completion of a new shipping lane connecting Nexa to the General Port increased activity.",
    "Successful negotiations with Erythros merchants expanded trade opportunities.",
    "The recent Festival of Light in Vaeringheim drove significant port activity.",
    "High attendance at the Bassaridia Trade Symposium enhanced the port's reputation.",
    "Discovery of new mineral resources near Acheron increased export potential through the port.",
    "A surge in ceremonial wine exports from the Blood Vineyards of the Far North bolstered port operations.",
    "Efficient cargo handling innovations improved investor sentiment at the General Port.",
    "Seasonal agricultural exports from the Plains of Jogi saw a sharp increase.",
    "High sales of pearl and abalone products boosted port activity.",
    "Introduction of luxury goods from Tel-Amin attracted high-end investors.",
    "The expansion of the General Port's capacity in Suncliff enhanced its competitiveness.",
    "Improved relations with Maskmakers Guild merchants stabilized trade routes.",
    "An increase in fishing yields around Lake Morovia led to greater port activity.",
    "Enhanced security measures at the General Port reduced piracy concerns.",
    "Growing cultural appreciation for sacred Horehound exports boosted regional confidence.",
    "Trade agreements with neighboring cities, including Saluria, expanded port usage.",
    "High demand for silk and luxury textiles from Seamstresses of Rouge improved port revenue.",
    "The Moonlit Tide celebration increased ceremonial goods traffic through the port.",
    "Launch of new Garganid fertilizer shipments attracted agricultural investors.",
    "Rising global interest in sacred resin exports enhanced the port's activity.",
    "Successful marketing campaigns highlighted the General Port's strategic importance.",
    "Completion of high-speed rail connections to key cities improved trade efficiency at the port."
}

local decreaseReasons = {
    "Pirate raids in the Strait of Haifa disrupted shipments to the General Port.",
    "Unfavorable weather conditions delayed agricultural exports from the Plains of Jogi.",
    "Labor shortages in the General Port caused delays in cargo handling.",
    "A major fire in Salurian sacred groves reduced resin exports through the port.",
    "Rising costs of Noctic-Rabrev cultivation impacted investor confidence.",
    "Unrest in Jangsong Province disrupted camel meat shipments to the port.",
    "Currency fluctuations in Vaeringheim affected trade stability at the General Port.",
    "Economic sanctions on neighboring cities reduced export activity.",
    "Decline in ceremonial artifact production reduced goods traffic through the port.",
    "Cultural disputes over Horehound cultivation caused delays in exports.",
    "Counterfeit relics discovered in Nexa harmed the port's reputation.",
    "High demand for fishing yields outpaced supply, reducing exports through the port.",
    "Decline in pearl quality from Anterran sources lowered investor interest.",
    "Shortage of ceremonial wine from the Blood Vineyards of the Far North hurt exports.",
    "Unrest among Maskmaker merchants disrupted key trade agreements.",
    "Reduced demand for silk textiles from the Seamstresses of Rouge impacted port activity.",
    "Collapse of a trade agreement with Tel-Amin reduced port volume.",
    "Seasonal labor shortages in agricultural hubs decreased port shipments.",
    "Disruptions in Suncliff Fisheries slowed aquatic exports through the port.",
    "Discovery of alternative shipping routes bypassed the General Port.",
    "Economic downturn in Lunalis Sancta affected investor interest.",
    "Unresolved piracy concerns in Haifan waters harmed trade confidence.",
    "Failure to secure key trade deals during the Bassaridia Trade Symposium reduced traffic.",
    "Natural disasters near Acheron destroyed key trade routes to the port.",
    "Sabotage of port infrastructure caused significant delays in shipments."
}

-- Function to determine tier based on Stocks at End
local function determineTier(stocksAtEnd)
    if stocksAtEnd > 12500 then
        return "Tier I"
    elseif stocksAtEnd >= 5000 and stocksAtEnd <= 12500 then
        return "Tier II"
    else
        return "Tier III"
    end
end

-- Function to simulate daily stock activity
local function simulateDailyActivity(investor)
    local buyStocks = math.random(0, 500)
    local sellStocks = math.random(0, 500)

    investor.stocks = investor.stocks + buyStocks - sellStocks
    return buyStocks, sellStocks
end

-- Function to generate a reason for change
local function getReason(change)
    if change == "Increased" then
        return increaseReasons[math.random(#increaseReasons)]
    elseif change == "Decreased" then
        return decreaseReasons[math.random(#decreaseReasons)]
    else
        return "Market activity remained stable."
    end
end

function p.generateTable()
    local date, _, _ = getCurrentDate()
    local totalMarketValueAtStart = 0
    local totalMarketValueAtEnd = 0
    local totalBoughtValue = 0
    local totalSoldValue = 0
    local stockPrice = 30 -- Stock price in Polis

    local wikitable = "{| class=\"wikitable\"\n! Date (Day/Month/Year [[PSSC]]) !! Investor !! Tier !! Stocks at Start !! Value at Start !! Stocks Bought !! Value of Stocks Bought !! Stocks Sold !! Value of Stocks Sold !! Stocks at End !! Value at End !! Change !! Reason\n"

    for _, investor in ipairs(investors) do
        local stocksAtStart = investor.stocks
        local valueAtStart = stocksAtStart * stockPrice
        local buyStocks, sellStocks = simulateDailyActivity(investor)
        local valueBought = buyStocks * stockPrice
        local valueSold = sellStocks * stockPrice
        local stocksAtEnd = investor.stocks
        local valueAtEnd = stocksAtEnd * stockPrice
        local tier = determineTier(stocksAtEnd)
        local change = "Increased"

        if stocksAtEnd < stocksAtStart then
            change = "Decreased"
        elseif stocksAtEnd == stocksAtStart then
            change = "No Change"
        end

        local reason = getReason(change)

        totalMarketValueAtStart = totalMarketValueAtStart + valueAtStart
        totalMarketValueAtEnd = totalMarketValueAtEnd + valueAtEnd
        totalBoughtValue = totalBoughtValue + valueBought
        totalSoldValue = totalSoldValue + valueSold

        wikitable = wikitable .. string.format("|-\n| %s || %s || %s || %d || %d Polis || %d || %d Polis || %d || %d Polis || %d || %d Polis || %s || %s\n",
            date, investor.name, tier, stocksAtStart, valueAtStart, buyStocks, valueBought, sellStocks, valueSold, stocksAtEnd, valueAtEnd, change, reason)
    end

    wikitable = wikitable .. string.format("|-\n| colspan=5 | Total Market Value at Start || %d Polis || %d Polis || %d Polis || %d Polis || ||\n",
        totalMarketValueAtStart, totalBoughtValue, totalSoldValue, totalMarketValueAtEnd)
    wikitable = wikitable .. "|}"
    return wikitable
end

return p