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


     for _, investor in ipairs(investors) do
     for _, investor in ipairs(investors) do
Line 69: Line 69:
         local stocksAtEnd = investor.stocks
         local stocksAtEnd = investor.stocks
         local tier = determineTier(stocksAtEnd)
         local tier = determineTier(stocksAtEnd)
        local change = "Increased"


         wikitable = wikitable .. string.format("|-\n| %s || %s || %s || %d || %d || %d || %d\n",
        if stocksAtEnd < stocksAtStart then
             date, investor.name, tier, stocksAtStart, buyStocks, sellStocks, stocksAtEnd)
            change = "Decreased"
        elseif stocksAtEnd == stocksAtStart then
            change = "No Change"
        end
 
         wikitable = wikitable .. string.format("|-\n| %s || %s || %s || %d || %d || %d || %d || %s\n",
             date, investor.name, tier, stocksAtStart, buyStocks, sellStocks, stocksAtEnd, change)
     end
     end



Revision as of 07:25, 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},
}

-- 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 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 !! Change\n"

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

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

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

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

return p