Module:AutoUpdateManfPrices
From MicrasWiki
Documentation for this module may be created at Module:AutoUpdateManfPrices/doc
---------------------------------------------------------
-- Module:DailyPriceTable
-- Generates a daily-updated product table + single-day line graph
-- for differences between base and adjusted prices,
-- with each row colored by price level:
-- • Low => light blue
-- • Standard => light green
-- • High => light red
---------------------------------------------------------
local p = {}
---------------------------------------------------------
-- 1. getCurrentDate
-- Returns today's date in PSSC format (day/month/year),
-- and numeric dayOfMonth/month for further calculations.
---------------------------------------------------------
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
local dateString = string.format("%d/%d/%d [[PSSC]]", dayOfMonth, month, psscYear)
return dateString, dayOfMonth, month
end
---------------------------------------------------------
-- 2. Product Data
---------------------------------------------------------
local products = {
{"Doryon Rifle 7.62×39mm", "Baratar Corporation", 3.15, "units"},
{"Skopion Sniper Rifle 8.6mm with 5x Scope", "Baratar Corporation", 0.45, "units"},
{"Lykastos Pistol 9mm Swampproof", "Baratar Corporation", 3.90, "units"},
{"Kleisthenes Carbine 5.45mm Folding Stock", "Baratar Corporation", 2.25, "units"},
{"Sphex SMG 5.7mm Short Barrel", "Baratar Corporation", 0.27, "units"},
{"Orontes Shotgun 12-Gauge Semi-Auto", "Baratar Corporation", 1.10, "units"},
{"Phokion Sidearm 10mm Officer Issue", "Baratar Corporation", 1.75, "units"},
{"Aurean Carbine 6.5mm Compact", "Baratar Corporation", 2.70, "units"},
{"Thorakitai Field Armor Composite-Plated", "Baratar Corporation", 2.40, "kits"},
{"Cataphract Saddle Harness Reinforced", "Baratar Corporation", 1.85, "sets"},
{"Xyston Utility Pack 14L Pilgrim Model", "Baratar Corporation", 0.95, "packs"},
{"Mycale Boots Knee-High Water-Wicking", "Baratar Corporation", 0.75, "pairs"},
{"Phalanx Scout Cloak Wool Camo", "Baratar Corporation", 1.05, "units"},
{"Tagmata Bandolier with Incense Chamber", "Baratar Corporation", 0.40, "sets"},
{"Myrmex 33cm", "Baratar Corporation", 0.15, "bundles"},
{"Antiope Guard Sash Crimson Embroidered", "Baratar Corporation", 0.22, "bundles"},
{"Thymiari Signal Kit Reedflare Tricolor", "Baratar Corporation", 0.65, "units"},
{"Kapnos Horn Beacon Oil-Based Smoke", "Baratar Corporation", 0.30, "devices"},
{"Myrrhex Grenade Mk.IV Incense Compound", "Baratar Corporation", 0.60, "cases"},
{"Fanarion Torch Dual Beam Ritual Use", "Baratar Corporation", 0.50, "units"},
{"Electricity", "Roving Wind Farm Corporation", 0.064, "megawatts"},
{"Electricity", "Port of Qandra", 0.065, "megawatts"},
{"Electricity", "Bijarian Energy Corporation", 6.783, "megawatts"},
{"Purple Granite", "Thalassian Temples Granite Export Cooperative", 0.036, "blocks"},
{"Iron", "East Keltian Iron Company", 1.692, "tons"},
{"Steel", "East Keltian Iron Company", 2.412, "tons"},
{"Concrete", "East Keltian Iron Company", 6.039, "tons"},
{"Coal", "Mylecian Coal Ports", 0.378, "tons"},
{"Diamonds", "Merchants of the Valley of Diamonds", 0.05, "carats"},
{"Timber", "East Keltian Timber Company", 5.63, "logs"},
{"Mens' Boots", "Onceanic Boot Company", 2.00, "pairs"},
{"Womens' Boots", "Onceanic Boot Company", 3.00, "pairs"},
{"Garganram Sign Plains Fertilizer", "Commune of the Garganid Apostles", 0.60, "tons"},
{"Gold Necklaces", "Shï Collective", 0.15, "pieces"},
{"Gold Rings", "Shï Collective", 0.40, "pieces"},
{"Gold Bracelets", "Shï Collective", 0.27, "pieces"},
{"Gold Earrings", "Shï Collective", 0.65, "pairs"},
{"Robes", "Order of the Sphinx", 1.30, "units"},
{"Dresses", "Order of the Sphinx", 0.65, "units"},
{"Tarnkappes", "Order of the Sphinx", 2.10, "cloaks"},
{"Coats", "Order of the Sphinx", 1.05, "units"},
{"Perfume", "Market Hanavusu", 0.32, "bottles"},
{"Cologne", "Market Hanavusu", 0.45, "bottles"},
{"Incense", "Market Hanavusu", 0.90, "sticks"},
{"Candles", "Market Hanavusu", 0.73, "pieces"},
{"Crude Oil", "Federation of North Brabipant", 1.204, "barrels"},
{"Natural Gas", "Federation of North Brabipant", 0.872, "cubic meters"},
{"Diesel Fuel", "Federation of North Brabipant", 0.633, "barrels"},
{"Jet Fuel", "Federation of North Brabipant", 0.587, "barrels"},
{"Lubricants", "Federation of North Brabipant", 0.419, "liters"},
{"Bitumen", "Federation of North Brabipant", 0.236, "tons"},
{"Propane", "Federation of North Brabipant", 0.482, "cubic meters"},
{"Asphalt Base", "Federation of North Brabipant", 0.329, "tons"},
{"Shale Oil", "Federation of North Brabipant", 0.278, "barrels"},
{"Petroleum Coke", "Federation of North Brabipant", 0.315, "tons"},
{"Industrial Paraffin", "Federation of North Brabipant", 0.298, "tons"},
{"Refined Gasoline", "Federation of North Brabipant", 0.541, "barrels"},
{"Copper", "Copper Mines of Southern Jogi", 2.1, "tons"},
{"Gabion Cages", "Southern Strait Preservation Corporation", .120, "cages"},
{"Reinforced Sea-Wall Panels", "Southern Strait Preservation Corporation", .84, "panels"},
{"Pre-Cast Revetment Blocks", "Southern Strait Preservation Corporation", .260, "blocks"},
{"Groyne Construction Kits", "Southern Strait Preservation Corporation", .47, "kits"},
{"Wave Deflection Barriers", "Southern Strait Preservation Corporation", .312, "meters"},
{"Marine-Grade Fasteners", "Southern Strait Preservation Corporation", .190, "kg"},
{"Erosion Control Mesh", "Southern Strait Preservation Corporation", .405, "square meters"},
{"Bio-Engineered Sediment Traps", "Southern Strait Preservation Corporation", .68, "units"},
{"Concrete Armor Units", "Southern Strait Preservation Corporation", .785, "tons"},
{"Tide-Resistant Fill Aggregate", "Southern Strait Preservation Corporation", .93, "cubic meters"},
{"Foundation Piles (treated timber)", "Southern Strait Preservation Corporation", .415, "meters"},
{"Drainage and Filter Matting", "Southern Strait Preservation Corporation", .102, "rolls"},
{"Timber", "Horned Bear Timber Company", 6.46, "logs"},
{"VX-7 Circuit Board", "Vortelin Electronics", 0.88, "units"},
{"HydraLink Router", "Vortelin Electronics", 1.32, "units"},
{"Vortex Transistor Pack", "Vortelin Electronics", 0.41, "packs"},
{"Redline Fiber Cable", "Vortelin Electronics", 0.29, "meters"},
{"Smart Power Converters", "Vortelin Electronics", 1.74, "units"},
{"Silicon Boards", "Vortelin Electronics", 0.62, "slabs"},
{"Compact Signal Relay", "Vortelin Electronics", 0.55, "units"},
{"CobraSeries Fuse Array", "Vortelin Electronics", 0.17, "units"},
{"LumenTrack LED Driver", "Vortelin Electronics", 0.38, "units"},
{"Verdant Power Cell", "Vortelin Electronics", 3.13, "cells"},
{"Basic Sensor Module", "Vortelin Electronics", 0.46, "units"},
{"Electromechanical Timer", "Vortelin Electronics", 0.63, "units"},
{"Stabilizer Adapter", "Vortelin Electronics", 0.91, "units"},
{"Basic Radio Kit", "Vortelin Electronics", 2.35, "kits"},
{"Circuit Training Kit", "Vortelin Electronics", 2.70, "kits"},
{"Torchleaf Raw Rubber", "Thyrsiad Rubber Company", 0.84, "blocks"},
{"Refined Desert Rubber", "Thyrsiad Rubber Company", 1.27, "rolls"},
{"Rubber Tubing", "Thyrsiad Rubber Company", 0.44, "meters"},
{"Insulated Wire Sheath", "Thyrsiad Rubber Company", 0.38, "meters"},
{"Anti-Vibration Mounts", "Thyrsiad Rubber Company", 0.71, "units"},
{"Thyrsian Sole Sheets", "Thyrsiad Rubber Company", 1.12, "sheets"},
{"High-Tensile Belting", "Thyrsiad Rubber Company", 2.15, "meters"},
{"Waterproof Seals", "Thyrsiad Rubber Company", 0.96, "units"},
{"Torchflex Gaskets", "Thyrsiad Rubber Company", 0.52, "units"},
{"Elastic Fasteners", "Thyrsiad Rubber Company", 0.19, "bundles"},
{"Vehicle Tyres", "Thyrsiad Rubber Company", 4.67, "units"},
{"Artisan Rubber Mats", "Thyrsiad Rubber Company", 1.63, "sheets"},
{"Industrial Hose", "Thyrsiad Rubber Company", 2.94, "meters"},
{"Medical-Grade Latex", "Thyrsiad Rubber Company", 3.85, "liters"},
{"Vulcanized Panels", "Thyrsiad Rubber Company", 2.30, "panels"},
{"Crude Stygium Ore", "Stygium Mines of Acheron", 0.95, "kg"},
{"Washed Stygium Ore", "Stygium Mines of Acheron", 1.10, "kg"},
{"Bloom-Grade Ore (Select Vein)", "Stygium Mines of Acheron", 1.35, "kg"},
{"Black Bloom Resin (Cold-Pressed)", "Stygium Mines of Acheron", 1.85, "kg"},
{"Thermo-Activated Resin Slab", "Stygium Mines of Acheron", 2.10, "kg"},
{"Pulverized Bloom Concentrate", "Stygium Mines of Acheron", 1.60, "kg"},
{"Deep Vein Extract (Stabilized)", "Stygium Mines of Acheron", 2.75, "kg"},
{"Bloom Dust (Industrial Grade)", "Stygium Mines of Acheron", 1.45, "kg"},
{"Stygium Slurry (Moist)", "Stygium Mines of Acheron", 1.55, "kg"},
{"Bloom-Rabrev Composite Ore", "Stygium Mines of Acheron", 2.40, "kg"},
{"Resin Cake (Compressed Transport)", "Stygium Mines of Acheron", 1.70, "kg"},
{"Bloom Suspension (Neutral Carrier)", "Stygium Mines of Acheron", 1.90, "kg"},
{"Crystal Fracture Shards", "Stygium Mines of Acheron", 2.05, "kg"},
{"Eirenarch X Executive Sedan", "Eosphorus Motor Company", 0.42, "units"},
{"Phoræ Vento Urban EV", "Eosphorus Motor Company", 0.79, "units"},
{"Aureline Astra Family Sedan", "Eosphorus Motor Company", 0.55, "units"},
{"Velatrix Solara Performance Coupe", "Eosphorus Motor Company", 0.21, "units"},
{"Kybele Nomad Terrain Wagon", "Eosphorus Motor Company", 0.37, "units"},
{"Lucernae LX Canal Convertible", "Eosphorus Motor Company", 0.12, "units"},
{"Oros Lynceum Crossover SUV", "Eosphorus Motor Company", 0.64, "units"},
{"Mornia Vox Micro EV", "Eosphorus Motor Company", 0.110, "units"},
{"Aulos Estate Touring Wagon", "Eosphorus Motor Company", 0.40, "units"},
{"Helioris Family Minivan", "Eosphorus Motor Company", 0.28, "units"},
{"Aurelia Utility Pick-up", "Eosphorus Motor Company", 0.38, "units"},
{"Class D-92 Morovia Standard", "Eosphorus Motor Company", 0.0175, "units"},
{"Class LX-77 Lucernae Royal", "Eosphorus Motor Company", 0.0075, "units"},
{"Class H-55 Historiatouria", "Eosphorus Motor Company", 0.0210, "units"},
{"Model CV-19 Atosian Vault Hauler", "Eosphorus Motor Company", 0.0038, "units"},
{"Model F-31 Stripping Hauler", "Eosphorus Motor Company", 0.0070, "units"},
{"Model K-04 Courier Starline", "Eosphorus Motor Company", 0.0105, "units"},
{"Model CT-66 Coalborn Tender", "Eosphorus Motor Company", 0.0084, "units"},
{"Model Z-7 Secutor Diplomatic Line", "Eosphorus Motor Company", 0.0060, "units"},
{"Model TM-5 Tetragram Enclave", "Eosphorus Motor Company", 0.0050, "units"},
{"Model PR-1 Adlet Ironhowl", "Eosphorus Motor Company", 0.0042, "units"},
{"Model A-03 Bannerwagon", "Eosphorus Motor Company", 0.0140, "units"},
{"Model V-99 Thunderguard Citadel Train", "Eosphorus Motor Company", 0.00024706, "units"},
{"Kalithros Class Rifle", "Somniant Stock Fund", 0.83, "units"},
{"Delphica Class Grenadier Rifle", "Somniant Stock Fund", 0.249, "units"},
{"Chrysos Class Commando Rifle", "Somniant Stock Fund", 0.124, "units"},
{"Lothaya Class Sniper Rifle", "Somniant Stock Fund", 0.0332, "units"},
{"Erythros Class Pistol", "Somniant Stock Fund", 0.166, "units"},
{"Bubalus XT Class Revolver", "Somniant Stock Fund", 0.95, "units"},
{"Cathartes Class RPG", "Somniant Stock Fund", 0.03, "units"},
{"Harpyia Class Submachine Gun", "Somniant Stock Fund", 0.125, "units"},
{"Strix Class Combat Shotgun", "Somniant Stock Fund", 0.22, "units"},
{"Regavis Class DMR", "Somniant Stock Fund", 0.27, "units"},
{"Aithra Class Howitzer", "Somniant Stock Fund", 0.00170, "units"},
{"Aetheris Class Towed Howitzer", "Somniant Stock Fund", 0.00490, "units"},
{"Iynas Class Field Gun", "Somniant Stock Fund", 0.00420, "units"},
{"300mm Secutor Class Coastal Guns", "Somniant Stock Fund", 0.0033, "guns"},
{"155mm Halicarn Class Self-Propelled Howitzer", "Somniant Stock Fund", 0.0025, "units"},
{"120mm Odiferian Class Mortar Carrier", "Somniant Stock Fund", 0.00160, "units"},
{"Quadwalker \"Horehound\" 4170", "Somniant Stock Fund", 0.0028, "units"},
{"Quadwalker \"Dungbeetle\" 4172", "Somniant Stock Fund", 0.0020, "units"},
{"Quadwalker \"Killbot\" 4200", "Somniant Stock Fund", 0.0041, "units"},
{"Quadwalker \"Oble-Lisea\" 4189", "Somniant Stock Fund", 0.0034, "units"},
{"Nexa Class Advanced Prototype", "Somniant Stock Fund", 0.0067, "units"},
{"Gargani Class Quadwalker", "Somniant Stock Fund", 0.0039, "units"},
{"Makra Class Battle Tank", "Somniant Stock Fund", 0.0083, "units"},
{"Laya Class Heavy Tank", "Somniant Stock Fund", 0.0033, "units"},
{"Arachne Class Light Tank", "Somniant Stock Fund", 0.0099, "units"},
{"Thalassa Class Main Battle Tank", "Somniant Stock Fund", 0.0050, "units"},
{"Syrinx Class Armored Infantry", "Somniant Stock Fund", 0.049, "squads"},
{"Bijarian Command Vehicle", "Somniant Stock Fund", 0.00083, "units"},
{"Onceanic Recon Vehicle", "Somniant Stock Fund", 0.00249, "units"},
{"Ephyra Class Anti-Aircraft Vehicle", "Somniant Stock Fund", 0.00120, "units"},
{"Ampelos Class Armored Recovery Vehicle", "Somniant Stock Fund", 0.0031, "systems"},
{"Penthia Class Bridge-Laying Vehicle", "Somniant Stock Fund", 0.0008, "systems"},
{"Ampelos Class Rail-Laying Engineering Vehicle", "Somniant Stock Fund", 0.0021, "systems"},
{"Corythia Class Dedicated Logistics and Transport Truck", "Somniant Stock Fund", 0.0019, "systems"},
{"Icaria Class Mine-Clearing / Combat Engineering Vehicle", "Somniant Stock Fund", 0.00095, "systems"},
{"Aiji Class Air-Caravan", "Somniant Stock Fund", 0.00013, "ships"},
{"Kalithros-Class Amphibious Airstrip Barge", "Somniant Stock Fund", 0.00021, "ships"},
{"Ferrum Citadel Class Battleship", "Somniant Stock Fund", 0.00009, "ships"},
{"Eidolon Class Cruiser", "Somniant Stock Fund", 0.00020, "ships"},
{"Vaeringheim Class Corvette", "Somniant Stock Fund", 0.00050, "ships"},
{"Sylvapolis Class Frigate", "Somniant Stock Fund", 0.00032, "ships"},
{"Aetherium Class Patrol Ship", "Somniant Stock Fund", 0.00058, "ships"},
{"Atterian Class Combat Ship", "Somniant Stock Fund", 0.00016, "ships"},
{"Xylanda Class Attack Submarine", "Somniant Stock Fund", 0.00025, "ships"},
{"Acheron Class Submersible Destroyer", "Somniant Stock Fund", 0.00016, "ships"},
{"Bijarian Ballistic Missile Submarine", "Somniant Stock Fund", 0.00012, "ships"},
{"Velkara Class Littoral Landing Ship", "Somniant Stock Fund", 0.00026, "ships"},
{"Saluria Class Gunboat", "Somniant Stock Fund", 0.00041, "ships"},
{"Cetus Class Attack Craft", "Somniant Stock Fund", 0.00050, "ships"},
{"Odobenus Class Minelayer", "Somniant Stock Fund", 0.0003, "ships"},
{"Cetomagna Class Minehunter", "Somniant Stock Fund", 0.0003, "ships"},
{"Aithra Class Proximity Aircraft", "Somniant Stock Fund", 0.00083, "aircraft"},
{"Orphali Class Tanker Aircraft", "Somniant Stock Fund", 0.00044, "aircraft"},
{"Ventiflor Eye Class AEW&C Aircraft", "Somniant Stock Fund", 0.00019, "aircraft"},
{"Fluxus Class Maritime Patrol Aircraft", "Somniant Stock Fund", 0.00063, "aircraft"},
{"Hostica Class Maritime Patrol Aircraft", "Somniant Stock Fund", 0.00071, "aircraft"},
{"Chrysos Class Sea Bomber", "Somniant Stock Fund", 0.00166, "aircraft"},
{"Misttalon Class Heavy Bomber", "Somniant Stock Fund", 0.00025, "aircraft"},
{"Symphonara Class Compound Intercept", "Somniant Stock Fund", 0.00066, "aircraft"},
{"Nefelian Transport Plane", "Somniant Stock Fund", 0.00083, "aircraft"},
{"Noctiluna Class Medium Transport Helicopter", "Somniant Stock Fund", 0.0010, "aircraft"},
{"Umbraclaw Class Heavy Transport Helicopter", "Somniant Stock Fund", 0.00089, "aircraft"},
{"Thalassa Class Attack Helicopter", "Somniant Stock Fund", 0.00130, "aircraft"},
{"Catonis Class Unmanned Aircraft", "Somniant Stock Fund", 0.00083, "aircraft"},
{"Lotos Class Tactical UAV", "Somniant Stock Fund", 0.00087, "aircraft"},
{"Aurantius Class Multi-Role UAV", "Somniant Stock Fund", 0.00091, "aircraft"},
{"Abeis Class Advanced Air Defense System", "Somniant Stock Fund", 0.0012, "units"},
{"Abeis Class Static Emplacement", "Somniant Stock Fund", 0.00075, "emplacements"},
{"Abeis-Empress Class Littoral Battlecruiser", "Somniant Stock Fund", 0.00022, "ships"},
{"Abeis-Taşrakah Class Littoral Orbital-Defense Ship", "Somniant Stock Fund", 0.000095, "ships"},
{"Abeis-Minerva Class Combat Littoral Strike Aircraft", "Somniant Stock Fund", 0.00051, "aircraft"},
{"Abeis-Boreas Littoral Dominance Helicopter", "Somniant Stock Fund", 0.00085, "aircraft"},
{"Abeis-Bulhanu Class High-Speed Skirmisher", "Somniant Stock Fund", 0.0068, "units"},
{"Abeis-Bulhanu Khamsin-Class Desert Skirmisher", "Somniant Stock Fund", 0.0059, "units"},
{"Abeis-Bulhanu Virelia-Class Urban Pacifier", "Somniant Stock Fund", 0.0042, "units"},
{"Abeis-Hrimthurs Class Arctic Hoverbike", "Somniant Stock Fund", 0.0051, "units"},
{"Abeis-Ismael Class “Cathartes” Littoral Hoverbike", "Somniant Stock Fund", 0.0057, "units"},
{"Abeis-Empress Class “Strix-E” Swarm-Interdictor Hoverbike", "Somniant Stock Fund", 0.0048, "units"},
{"Anguilla Class Coastal Missile Battery", "Somniant Stock Fund", 0.0022, "batteries"}
}
---------------------------------------------------------
-- 3. Special Date Events
---------------------------------------------------------
local events = {
["1,6"] = "Bayram al-Nur (Festival of Light) [Vaeringheim]",
["1,18"] = "Chag Or Hadash (Festival of New Light) [Luminaria]",
["1,30"] = "Symposion Eirinis (Symposium of Harmony) [Serena]",
["1,43"] = "Alev Günü (Day of Flame) [Pyralis]",
["1,48"] = "Day of Abandonment [Vaeringheim]",
["1,55"] = "Tikkun Tzel (Repair of Shadows) [Symphonara]",
["2,6"] = "Panegyris Chrysou (Golden Gathering) [Aurelia]",
["2,17"] = "Constitution Day [Luminaria]",
["2,19"] = "Mehtap Dalgası (Moonlit Tide) [Vaeringheim]",
["2,31"] = "Oneiro Foteino (Dream of Illumination) [Somniumpolis]",
["2,39"] = "Anniversary of victory in the New South Jangsong Campaign [Nexa]",
["2,44"] = "Erev Galgal (Eve of Cycles) [Nexa]",
["2,45"] = "Bassaridia Festival [Somniumpolis]",
["2,48"] = "Anniversary of victory in the Southern Lake Morovia Campaign [Somniumpolis]",
["2,54"] = "Leilat al-Kamar (Night of the Moon) [Lunalis Sancta]",
["2,61"] = "Taşrakah (Reverence of the Stone) [Luminaria]",
["3,6"] = "Chag Tvuah (Festival of Harvest) [Sylvapolis]",
["3,18"] = "Anagenesis Eirmos (Procession of Rebirth) [Acheron]",
["3,28"] = "Panagia Therizis (Holy Day of the Reaper) [Sylvapolis]",
["3,37"] = "Anniversary of victory in the Morovian Frontier Campaign [Acheron]",
["3,43"] = "Karnavali Thysias (Carnival of Celebration) [Erythros]",
["3,53"] = "Sefar Yashar (Straight Path Celebration) [Catonis Atrium]",
}
---------------------------------------------------------
-- 4. simulatePriceChange
-- Applies daily random factor to basePrice. If today's
-- date matches a known event, add a small positive boost.
---------------------------------------------------------
local function simulatePriceChange(basePrice, dayOfMonth, month)
local dateKey = string.format("%d,%d", month, dayOfMonth)
local changeFactor = math.random(-20, 20) / 100
local explanation
if events[dateKey] then
explanation = events[dateKey] .. ": Prices influenced by event dynamics."
changeFactor = changeFactor + 0.05 -- slight boost for event days
else
explanation = "General market fluctuations."
end
local newPrice = math.floor((basePrice * (1 + changeFactor)) * 10000) / 10000
return newPrice, changeFactor, explanation
end
---------------------------------------------------------
-- 5. determinePriceLevel
-- Swapped so that:
-- adjustedPrice > basePrice ⇒ "Low"
-- adjustedPrice < basePrice ⇒ "High"
-- otherwise ⇒ "Standard"
---------------------------------------------------------
local function determinePriceLevel(basePrice, adjustedPrice)
if adjustedPrice > basePrice then
return "Low"
elseif adjustedPrice < basePrice then
return "High"
else
return "Standard"
end
end
---------------------------------------------------------
-- 6. Main Function: generateTable
-- Builds the daily wiki-table with updated prices.
---------------------------------------------------------
function p.generateTable()
-- Seed randomness
local localTime = os.date("*t")
math.randomseed(localTime.year * 1000 + localTime.yday)
-- Get date info
local dateString, dayOfMonth, month = getCurrentDate()
-- Table header
local wikitable =
"{| class=\"wikitable\"\n" ..
"! Date !! Product !! Company !! Base Price !! Level !! Tier III !! Tier II !! Tier I !! Units !! Explanation\n"
local totalBase, totalNew, count = 0, 0, 0
-- Populate rows
for _, product in ipairs(products) do
local name, company, basePrice, units = unpack(product)
local newPrice, _, explanation = simulatePriceChange(basePrice, dayOfMonth, month)
local priceLevel = determinePriceLevel(basePrice, newPrice)
-- Row coloring
local rowStyle
if priceLevel == "Low" then
rowStyle = ' style="background-color:lightblue;"'
elseif priceLevel == "Standard" then
rowStyle = ' style="background-color:lightgreen;"'
else
rowStyle = ' style="background-color:#ffcccb;"'
end
local tierIII = math.floor((newPrice / 3) * 10000) / 10000
local tierII = math.floor((newPrice * 2/3) * 10000) / 10000
local tierI = newPrice
totalBase = totalBase + basePrice
totalNew = totalNew + newPrice
count = count + 1
wikitable = wikitable .. string.format(
"|-%s\n| %s || %s || %s || %.4f || %s || %.4f || %.4f || %.4f || %s || %s\n",
rowStyle, dateString, name, company, basePrice,
priceLevel, tierIII, tierII, tierI, units, explanation
)
end
-- Averages
local avgBase = totalBase / count
local avgNew = totalNew / count
local avgLevel
if avgNew > avgBase then
avgLevel = "Low"
elseif avgNew < avgBase then
avgLevel = "High"
else
avgLevel = "Standard"
end
-- Footer
wikitable = wikitable .. string.format(
"|-\n! colspan=\"10\" | Average adjusted price (%.4f) vs base (%.4f) ⇒ %s\n",
avgNew, avgBase, avgLevel
)
wikitable = wikitable .. "|}"
return wikitable
end
---------------------------------------------------------
-- 7. Optional: Single-Day Line Graph
---------------------------------------------------------
function p.generateSingleDayLineGraph()
local localTime = os.date("*t")
math.randomseed(localTime.year * 1000 + localTime.yday)
local dateString, dayOfMonth, month = getCurrentDate()
local data = {}
for _, product in ipairs(products) do
local name, _, basePrice = unpack(product)
local newPrice = simulatePriceChange(basePrice, dayOfMonth, month)
table.insert(data, { product = name, difference = newPrice - basePrice })
end
local spec = {
["$schema"] = "https://vega.github.io/schema/vega-lite/v5.json",
description = "Single-day price difference chart",
width = 700, height = 400,
data = { values = data },
mark = "line",
encoding = {
x = { field = "product", type = "ordinal", title = "Product" },
y = { field = "difference", type = "quantitative", title = "Difference" },
tooltip = { field = "difference", type = "quantitative" }
},
title = "Price Differences for " .. dateString
}
return string.format("<graph>%s</graph>", mw.text.jsonEncode(spec))
end
return p