Module:BassaridMarketActivity: Difference between revisions
From MicrasWiki
Jump to navigationJump to search
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..." |
NewZimiaGov (talk | contribs) No edit summary |
||
| Line 30: | Line 30: | ||
-- Initial figures for Regional Investors | -- Initial figures for Regional Investors | ||
local investors = { | local investors = { | ||
{name = "Vaeringheim Regional Investor | {name = "Vaeringheim Regional Investor", stocks = 17424}, | ||
{name = "Alpazkigz Regional Investor | {name = "Alpazkigz Regional Investor", stocks = 16214}, | ||
{name = "Odiferia Regional Investor | {name = "Odiferia Regional Investor", stocks = 14718}, | ||
{name = "Hafaan Regional Investor | {name = "Hafaan Regional Investor", stocks = 3630}, | ||
{name = "Jeseri Regional Investor | {name = "Jeseri Regional Investor", stocks = 1870}, | ||
{name = "Hatch Ministry Regional Investor | {name = "Hatch Ministry Regional Investor", stocks = 7810}, | ||
{name = "New South Jangsong Division | {name = "New South Jangsong Division", stocks = 11085}, | ||
{name = "Haifan Bassaridia Division | {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 | -- Function to simulate daily stock activity | ||
| Line 57: | Line 68: | ||
local buyStocks, sellStocks = simulateDailyActivity(investor) | local buyStocks, sellStocks = simulateDailyActivity(investor) | ||
local stocksAtEnd = investor.stocks | local stocksAtEnd = investor.stocks | ||
local tier = determineTier(stocksAtEnd) | |||
wikitable = wikitable .. string.format("|-\n| %s || %s || %s || %d || %d || %d || %d\n", | wikitable = wikitable .. string.format("|-\n| %s || %s || %s || %d || %d || %d || %d\n", | ||
date, investor.name, | date, investor.name, tier, stocksAtStart, buyStocks, sellStocks, stocksAtEnd) | ||
end | end | ||
Revision as of 07:23, 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\n"
for _, investor in ipairs(investors) do
local stocksAtStart = investor.stocks
local buyStocks, sellStocks = simulateDailyActivity(investor)
local stocksAtEnd = investor.stocks
local tier = determineTier(stocksAtEnd)
wikitable = wikitable .. string.format("|-\n| %s || %s || %s || %d || %d || %d || %d\n",
date, investor.name, tier, stocksAtStart, buyStocks, sellStocks, stocksAtEnd)
end
wikitable = wikitable .. "|}"
return wikitable
end
return p