Module:BassaridMarketActivity

From MicrasWiki
Revision as of 07:18, 25 December 2024 by NewZimiaGov (talk | contribs) (Created page with "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 lo...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

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", tier = "Tier I", stocks = 17424},
    {name = "Alpazkigz Regional Investor", tier = "Tier I", stocks = 16214},
    {name = "Odiferia Regional Investor", tier = "Tier I", stocks = 14718},
    {name = "Hafaan Regional Investor", tier = "Tier II", stocks = 3630},
    {name = "Jeseri Regional Investor", tier = "Tier III", stocks = 1870},
    {name = "Hatch Ministry Regional Investor", tier = "Tier II", stocks = 7810},
    {name = "New South Jangsong Division", tier = "Tier II", stocks = 11085},
    {name = "Haifan Bassaridia Division", tier = "Tier II", stocks = 12500},
}

-- 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 p.generateTable()
    local date, _, _ = getCurrentDate()
    local wikitable = "{| class=\"wikitable\"\n! Date (Day/Month/Year [[PSSC]]) !! Investor !! Tier !! Stocks at Start !! Stocks Bought !! Stocks Sold !! Stocks at End\n"

    for _, investor in ipairs(investors) do
        local stocksAtStart = investor.stocks
        local buyStocks, sellStocks = simulateDailyActivity(investor)
        local stocksAtEnd = investor.stocks

        wikitable = wikitable .. string.format("|-\n| %s || %s || %s || %d || %d || %d || %d\n",
            date, investor.name, investor.tier, stocksAtStart, buyStocks, sellStocks, stocksAtEnd)
    end

    wikitable = wikitable .. "|}"
    return wikitable
end

return p