Module:AutoUpdateAgPrices: Difference between revisions

From MicrasWiki
Jump to navigationJump to search
NewZimiaGov (talk | contribs)
No edit summary
NewZimiaGov (talk | contribs)
No edit summary
Line 258: Line 258:
     {"Jied-Rarev (Unrefined Pollen)", "Port of Corumia", 5.13, "kilograms"},
     {"Jied-Rarev (Unrefined Pollen)", "Port of Corumia", 5.13, "kilograms"},
     {"Fuy-Rabrev (Raw Resin)", "Port of Corumia", 5.70, "kilograms"},
     {"Fuy-Rabrev (Raw Resin)", "Port of Corumia", 5.70, "kilograms"},
    {"Silver Ore (Kralian Sourced)", "Port of Corumia", 0.60, "bars"},
    {"Fragrance Resin Base (Asee Extract)", "Port of Corumia", 46.20, "ampoules"},
    {"Sevid-Fiota Rope Fibers", "Port of Corumia", 23.10, "bundles"},
    {"Twine Material (Unprocessed)", "Port of Corumia", 57.75, "rolls"},
    {"Raw String Material", "Port of Corumia", 69.30, "rolls"},
    {"Rope", "Port of Corumia", 23.10, "bundles"},
    {"String", "Port of Corumia", 69.30, "rolls"},
    {"Indigo Dye Cakes (Pressed)", "Port of Corumia", 12.60, "cakes"},
    {"Ceramic Amphorae (Export-Grade)", "Port of Corumia", 2.86, "units"},
    {"Pitch & Naval Tar", "Port of Corumia", 12.10, "casks"},
    {"Freight Handling (per ton)", "Port of Corumia", 1.20, "tons"},
    {"Harbor Pilotage (per transit)", "Port of Corumia", 4.80, "transits"},
    {"Drydock Berth (per day)", "Port of Corumia", 16.00, "days"},
    {"Tug Assist (harbor move)", "Port of Corumia", 2.40, "moves"},
    {"Customs Brokerage (filing)", "Port of Corumia", 1.10, "filings"},
    {"Bonded Warehousing", "Port of Corumia", 0.22, "m³·day"},
    {"Cold Storage", "Port of Corumia", 0.38, "m³·day"},
    {"Security Escort (quay-to-gate)", "Port of Corumia", 0.95, "escorts"},
    {"Quarantine Inspection (vessel)", "Port of Corumia", 2.10, "vessels"},
    {"Medical Clearance (per crew)", "Port of Corumia", 0.36, "crew"},


}
}

Revision as of 17:45, 6 September 2025

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

---------------------------------------------------------
-- Module:DailyPriceTable
-- Generates a table of daily-updated product prices,
-- with each cell changing automatically once per day.
--
-- Features:
--  • Seeds randomness each day using localTime.year + localTime.yday
--  • No manual intervention required
--  • Tier prices derived from the final adjusted price
--  • Minor event-based price boost for special days
---------------------------------------------------------

local p = {}

---------------------------------------------------------
-- 1. getCurrentDate
--    Determines today's PSSC date and returns:
--      * dateString in "day/month/year [PSSC]"
--      * dayOfMonth (1..61 or 1..61 or 1..61)
--      * month (1=Atosiel, 2=Thalassiel, 3=Opsitheiel)
---------------------------------------------------------
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

---------------------------------------------------------
-- 2. Product Data
---------------------------------------------------------
local products = {
    {"Rice", "Gladeseed Farmers' Union", 9.00, "tons"},
    {"Edible Algae", "Gladeseed Farmers' Union", 21.00, "tons"},
    {"Shrimp", "Gladeseed Farmers' Union", 15.00, "tons"},
    {"Anterran Spicy Onion", "Gladeseed Farmers' Union", 18.00, "tons"},
    {"Queen's Garlic", "Gladeseed Farmers' Union", 27.00, "tons"},
    {"Morovian Water Buffalo", "Atterian Cattle Drivers", .60, "head"},
    {"Morovian Water Buffalo Beef", "Atterian Cattle Drivers", 5, "tons"},
    {"Unprocessed Noctic-Rabrev Leaf Concentrate", "Noctic Fleet", .60, "barrels"},
    {"Processed Noctic-Rabrev Leaf Concentrate", "Noctic Fleet", .30, "barrels"},
    {"Dried Noctic-Rabrev Petals", "Noctic Fleet", 2.25, "kilograms"},
    {"Noctic-Rabrev Flower Oil Extract", "Noctic Fleet", .450, "liters"},
    {"Noctic-Rabrev Culinary Spice Blend", "Noctic Fleet", 1.75, "kilograms"},
    {"Sanctified Noctic Leaf (ritual-grade)", "Noctic Fleet", 9.00, "bundles"},
    {"Noctic Tincture (therapeutic dosage)", "Noctic Fleet", 2.50, "vials"},
    {"Noctic-Rabrev Infused Incense", "Noctic Fleet", 3.00, "packs"},
    {"Noctic Flower Lokum (sweet export)", "Noctic Fleet", 2.25, "boxes"},
    {"Temple-Pressed Noctic Resin", "Noctic Fleet", 5.00, "bricks"},
    {"Distilled Noctic Elixir (medical grade)", "Noctic Fleet", 6.75, "bottles"},
    {"Noctic-Rabrev Anointing Balm", "Noctic Fleet", 4.00, "jars"},
    {"Noctic-Rabrev Ritual Ink", "Noctic Fleet", 3.50, "bottles"},
    {"Noctic Soak Oil", "Noctic Fleet", 4.75, "flasks"},
    {"Nocticine Silk-Wrap Cigarettes (20-count)", "Noctic Fleet", 7.25, "packs"},
    {"Caravan Reserve Noctic Cigars (hand-rolled)", "Noctic Fleet", 3.40, "sticks"},
    {"Pocket-Press Noctic Chew Pouches (minted)", "Noctic Fleet", 4.80, "tins"},
    {"Chewable Night-Leaf Gum (sugar-free)", "Noctic Fleet", 3.20, "blisters"},
    {"Quick-Fuse Nocticine Buccal Film", "Noctic Fleet", 8.10, "sheets"},
    {"Hand-Cured Nefel Leaf Cigarettes (20-count)", "Nefel Village", 6.80, "packs"},
    {"Village Reserve Tobacco Cigars (oak-aged)", "Nefel Village", 4.10, "sticks"},
    {"Pressed Nefel Chew Rolls (spiced)", "Nefel Village", 4.50, "tins"},
    {"Sun-Dried Pipe Tobacco (long-cut)", "Nefel Village", 5.25, "pouches"},
    {"Tobacco Infused Oil (for incense burners)", "Nefel Village", 3.90, "flasks"},
    {"Nefel Clay-Smoked Cigarettes (10-count)", "Nefel Village", 7.45, "packs"},
    {"Herbal-Blend Hookah Tobacco", "Nefel Village", 6.20, "jars"},
    {"Tobacco Ash Charcoal Tablets (ritual use)", "Nefel Village", 2.60, "discs"},
    {"Manwine", "Jogiani Merchants of Manwine", 2.07, "barrels"},
    {"Milkwine", "Jogiani Merchants of Manwine", 6.00, "barrels"},
    {"Zoe Elm Resin (Unrefined)", "Keepers of the Grove of Zoe Elm", 0.03, "barrels"},
    {"Zoe Elm Resin (Refined)", "Keepers of the Grove of Zoe Elm", 0.04, "barrels"},
    {"Sea Elm Flavored Mead", "Sea-Elm Southern Meadery", 1.11, "barrels"},
    {"Wheat", "Plains of Jogi", 0.30, "tons"},
    {"Oats", "Plains of Jogi", 0.23, "tons"},
    {"Cereal", "Plains of Jogi", 0.52, "pallets"},
    {"Hay", "Plains of Jogi", 0.45, "bales"},
    {"Ale of the Night", "Ale of the Night Central Brewery", 2.43, "barrels"},
    {"Camels", "Camel Herders of the Jangsong Province", 1.04, "head"},
    {"Camel Meat", "Camel Herders of the Jangsong Province", 34.65, "tons"},
    {"Camel Milk", "Camel Herders of the Jangsong Province", 5.20, "barrels"},
    {"Camel Hump Water", "Camel Herders of the Jangsong Province", 3.47, "barrels"},
    {"Camel Hump Water Tea", "Camel Herders of the Jangsong Province", 0.86, "barrels"},
    {"Pearls", "Anterran Imports and Services", 0.79, "sacks"},
    {"Abalone", "Anterran Imports and Services", 2.64, "crates"},
    {"Opium", "Merchant Guild of the Poppy Goddess", 0.18, "sacks"},
    {"Hash", "Merchant Guild of the Poppy Goddess", 0.17, "sacks"},
    {"Mead", "Grand Cave Bee Meadery", 0.49, "barrels"},
    {"Cinammon", "Cinammon Plains of Roue", 0.45, "tons"},
    {"Velvet Worm Meat", "The Velvet Company", 1.04, "tons"},
    {"Velvet Worm Eggs", "The Velvet Company", 0.35, "crates"},
    {"Silk", "Seamstresses of Rouge", 5.00, "rolls"},
    {"Horehound Mead", "Salurian Temple of Sacred Horehound", 0.05, "barrels"},
    {"Horehound Beer", "Salurian Temple of Sacred Horehound", 0.07, "barrels"},
    {"Sea Cow Beef", "Bulhanu Ranchers' Association", 8.50, "tons"},
    {"Atterian Armored Pufferfish", "Suncliff Fisheries", 3.00, "tons"},
    {"Morovian Saucer Eyed Giant Eel", "Suncliff Fisheries", 7.50, "tons"},
    {"Amina Crab", "Suncliff Fisheries", 6.00, "tons"},
    {"Mugwort Oil", "Ministers of Mistress Mugwort", 0.35, "barrels"},
    {"Ground Mugwort", "Ministers of Mistress Mugwort", 0.75, "sacks"},
    {"Mugwort Tincture", "Ministers of Mistress Mugwort", 0.10, "barrels"},
    {"Blood InfusedRed Wine", "Blood Vineyards of the Far North", 0.39, "barrels"},
    {"Wisp Rice", "Norsolyrian Wisp Rice Farmers Association", 15.00, "tons"},
    {"Giid-Lisea-Eda", "Giid-Lisea Ranching Import Company", 0.41, "head"},
    {"Giid-Lisea-Eda Beef", "Giid-Lisea Ranching Import Company", 7.10, "tons"},
    {"Giid-Lisea-Eda Milk", "Giid-Lisea Ranching Import Company", 3.85, "liters"},
    {"Cream Butter", "Giid-Lisea Ranching Import Company", 2.12, "pounds"},
    {"Aged Cheese", "Giid-Lisea Ranching Import Company", 1.44, "wheels"},
    {"Giid-Lisea Hide Leather", "Giid-Lisea Ranching Import Company", 4.23, "sheets"},
    {"Tusk Ivory Carvings", "Giid-Lisea Ranching Import Company", 0.73, "pieces"},
    {"Bone-Broth Concentrate", "Giid-Lisea Ranching Import Company", 5.67, "jars"},
    {"Mammoth Fat Candles", "Giid-Lisea Ranching Import Company", 1.98, "candles"},
    {"Frozen Mammoth Steaks", "Giid-Lisea Ranching Import Company", 6.22, "pounds"},
    {"Pickled Mammoth Tongue", "Giid-Lisea Ranching Import Company", 0.89, "jars"},
    {"Giid-Lisea Jerky (salted)", "Giid-Lisea Ranching Import Company", 4.56, "slabs"},
    {"Mammoth Bone Flour (fertilizer)", "Giid-Lisea Ranching Import Company", 2.71, "sacks"},
    {"Giid-Lisea Cream Liqueur", "Giid-Lisea Ranching Import Company", 3.14, "bottles"},
    {"Highland Ale (milk-based)", "Giid-Lisea Ranching Import Company", 5.09, "tankards"},
    {"Vaeringheim Turkey Meat", "Bird Keepers of Saluria", 1.07, "tons"},
    {"Salurian Swamp Quail Eggs", "Bird Keepers of Saluria", 12.00, "crates"},
    {"Giant Fanged Penguin Blubber", "Hunters of the Giant Fanged Penguin", 25.00, "tons"},
    {"Giant Fanged Penguin Blubber Oil Extract", "Hunters of the Giant Fanged Penguin", 5.00, "barrels"},
    {"Coffee", "Aminian Coffee Company", 100, "pounds"},
    {"Reindeer Meat", "Knights Castle Reindeer Herders", 3.15, "tons"},
    {"Leather", "Knights Castle Reindeer Herders", 7.5, "pounds"},
    {"Bone Products", "Knights Castle Reindeer Herders", 1.06, "crates"},
    {"Whale Meat", "Lindley Whaling Company", 13.5, "tons"},
    {"Whale Oil", "Lindley Whaling Company", .77, "crates"},
    {"Whale Bone", "Lindley Whaling Company", 5.1, "tons"},
    {"Seal Meat", "Lindley Whaling Company", 3.1, "tons"},
    {"Seal Oil", "Lindley Whaling Company", .32, "crates"},
    {"Seal Fur", "Lindley Whaling Company", 2.23, "crates"},
    {"Sea Lion Meat", "Lindley Whaling Company", 6.45, "tons"},
    {"Sea Lion Oil", "Lindley Whaling Company", .46, "crates"},
    {"Sea Lion Fur", "Lindley Whaling Company", 4.8, "crates"},
    {"Beans", "Granadita Collective", 1.1, "tons"},
    {"Potatos", "Granadita Collective", 4.2, "tons"},
    {"Squash", "Granadita Collective", 3.7, "tons"},
    {"Wheat", "Granadita Collective", .55, "tons"},
    {"maize", "Granadita Collective", 5.5, "tons"},
    {"Vegetable Lamb of Tartary", "Herd Caton", 2.77, "head"},
    {"Lamb’s Wool (Vegetable Blend)", "Herd Caton", .18, "kg"},
    {"Lamb-Root Cheese", "Herd Caton", .42, "wheels"},
    {"Tartary Saplings", "Herd Caton", .32, "plants"},
    {"Pickled Lamb Stalks", "Herd Caton", .24, "jars"},
    {"Partially Digested Fish Pulp", "Wasp Hunters of the Austral Isles", 23.76, "pounds"},
    {"Fermented Fish Pulp Bricks", "Wasp Hunters of the Austral Isles", 4.12, "bricks"},
    {"Fish Gut Oil (cooking & lamp use)", "Wasp Hunters of the Austral Isles", 7.85, "liters"},
    {"Salted Intestinal Mash", "Wasp Hunters of the Austral Isles", 15.63, "pounds"},
    {"Brined Gill Ribbons", "Wasp Hunters of the Austral Isles", 3.21, "bundles"},
    {"Smoked Aiji-Hial-Nas Strips", "Wasp Hunters of the Austral Isles", 8.44, "pounds"},
    {"Pickled Stomach Chunks", "Wasp Hunters of the Austral Isles", 2.09, "jars"},
    {"Fish Maw Jelly", "Wasp Hunters of the Austral Isles", 6.39, "jars"},
    {"Dried Scale Powder (seasoning)", "Wasp Hunters of the Austral Isles", 2.44, "sachets"},
    {"Sea-Salt Ferment Porridge", "Wasp Hunters of the Austral Isles", 5.70, "bowls"},
    {"Wasp Hunter’s Black Rum", "Wasp Hunters of the Austral Isles", 9.80, "bottles"},
    {"Fish-Pulp Mead (sweet & briny blend)", "Wasp Hunters of the Austral Isles", 4.55, "bottles"},
    {"Spiced Intestine Ale", "Wasp Hunters of the Austral Isles", 6.13, "tankards"},
    {"Dried Roe Biscuits", "Wasp Hunters of the Austral Isles", 3.22, "cakes"},
    {"Hunter’s Brine Wine (fortified)", "Wasp Hunters of the Austral Isles", 7.90, "bottles"},
    {"Raw Cane Sugar", "Diamonia Sugar Cooperatives", 1.92, "tons"},
    {"Refined White Sugar", "Diamonia Sugar Cooperatives", 1.44, "tons"},
    {"Brown Sugar", "Diamonia Sugar Cooperatives", 0.88, "tons"},
    {"Molasses", "Diamonia Sugar Cooperatives", 0.76, "barrels"},
    {"Rock Sugar Crystals", "Diamonia Sugar Cooperatives", 0.67, "crates"},
    {"Sugar Loaves", "Diamonia Sugar Cooperatives", 1.15, "blocks"},
    {"Date Sugar Blend", "Diamonia Sugar Cooperatives", 0.38, "sacks"},
    {"Candied Citrus Peel", "Diamonia Sugar Cooperatives", 0.24, "crates"},
    {"Sugar Syrup", "Diamonia Sugar Cooperatives", 0.91, "barrels"},
    {"Sweet Tea Cakes", "Diamonia Sugar Cooperatives", 0.53, "boxes"},
     {"Cold-Steppe Barley", "Ouriana Lowlands Farmers' Association", 8.25, "tons"},
    {"Proso Millet", "Ouriana Lowlands Farmers' Association", 7.75, "tons"},
    {"Buckwheat", "Ouriana Lowlands Farmers' Association", 9.50, "tons"},
    {"Foxtail Millet", "Ouriana Lowlands Farmers' Association", 8.00, "tons"},
    {"Cold-Hardy Lentils", "Ouriana Lowlands Farmers' Association", 12.00, "tons"},
    {"Turnips (Mountain-Grown)", "Ouriana Lowlands Farmers' Association", 6.25, "tons"},
    {"Rutabagas (Highland)", "Ouriana Lowlands Farmers' Association", 6.50, "tons"},
    {"Alpine Cabbage", "Ouriana Lowlands Farmers' Association", 6.75, "tons"},
    {"Wild Rye", "Ouriana Lowlands Farmers' Association", 9.00, "tons"},
    {"Cultivated Rye", "Ouriana Lowlands Farmers' Association", 9.75, "tons"},
    {"Kohlrabi", "Ouriana Lowlands Farmers' Association", 7.25, "tons"},
    {"Steppe Rhubarb", "Ouriana Lowlands Farmers' Association", 5.75, "tons"},
    {"Mountain Sorrel", "Ouriana Lowlands Farmers' Association", 4.00, "tons"},
    {"Cold-Hardy Hops", "Ouriana Lowlands Farmers' Association", 18.00, "tons"},
    {"Highland Herbal Blend (raw)", "Ouriana Lowlands Farmers' Association", 10.50, "tons"},
    {"Fermenting Barley", "Ouriana Lowlands Farmers' Association", 12.75, "tons"},
    {"Highland Lentil and Millet Mix (packaged)", "Ouriana Lowlands Farmers' Association", 13.25, "tons"},
    {"Highland Grayling", "Ouriad River Fisheries Cooperative", 7.80, "tons"},
    {"Mountain Whitefish", "Ouriad River Fisheries Cooperative", 6.90, "tons"},
    {"Brown Trout", "Ouriad River Fisheries Cooperative", 8.25, "tons"},
    {"Lake Sturgeon Roe", "Ouriad River Fisheries Cooperative", 11.50, "kilograms"},
    {"Whitefish (Spawning-Run)", "Ouriad River Fisheries Cooperative", 6.50, "tons"},
    {"Lamprey", "Ouriad River Fisheries Cooperative", 9.75, "crates"},
    {"Salted Lamprey Filets", "Ouriad River Fisheries Cooperative", 8.10, "tons"},
    {"Smoked Burbot", "Ouriad River Fisheries Cooperative", 7.25, "tons"},
    {"Steppe Horse (Working Breed)", "Caspazani Livestock Company", 3.2, "head"},
    {"Highland Courier Mount", "Caspazani Livestock Company", 4.7, "head"},
    {"Cavalry Stock (Auxiliary-Grade)", "Caspazani Livestock Company", 5.4, "head"},
    {"Foal Training Licenses", "Caspazani Livestock Company", 0.4, "permits"},
    {"Standard Saddle Kits (Hide & Wood)", "Caspazani Livestock Company", 1.6, "sets"},
    {"Herding Bat Colony (Trained)", "Caspazani Livestock Company", 5.8, "colonies"},
    {"Bat Guidance Whistle Sets", "Caspazani Livestock Company", 0.5, "kits"},
    {"Pack Horse Leasing Contracts", "Caspazani Livestock Company", 1.9, "agreements"},
    {"Horse Milk (Fermentable)", "Caspazani Livestock Company", 1.1, "liters"},
    {"Livestock Registry Processing (Valley Standard)", "Caspazani Livestock Company", 0.3, "entries"},
    {"White Beets", "White Ruby Communes", 7.124, "crates"},
    {"Potatoes", "White Ruby Communes", 12.542, "sacks"},
    {"Onions", "White Ruby Communes", 10.304, "sacks"},
    {"Cabbage", "White Ruby Communes", 8.761, "heads"},
    {"Garlic Bulbs", "White Ruby Communes", 1.984, "bundles"},
    {"Dill", "White Ruby Communes", 0.673, "kilograms"},
    {"Parsley", "White Ruby Communes", 0.544, "kilograms"},
    {"Wild Juniper Berries", "White Ruby Communes", 0.298, "kilograms"},
    {"Thyme Bush Cuttings", "White Ruby Communes", 0.186, "kilograms"},
    {"Preserved Wild Boar (Spiced)", "White Ruby Communes", 0.462, "kilograms"},
    {"Caledonian Spiced Ham", "White Ruby Communes", 0.117, "kilograms"},
    {"Caledonian Cured Ham (Young)", "White Ruby Communes", 0.221, "kilograms"},
    {"Purple Sturgeon Caviar", "White Ruby Communes", 0.037, "kilograms"},
    {"Crab Roe Caviar", "White Ruby Communes", 0.052, "kilograms"},
    {"Dried Pel'myeny Dumplings", "White Ruby Communes", 3.210, "packs"},
    {"Borsch Base Mix (Dehydrated)", "White Ruby Communes", 2.901, "canisters"},
    {"Velvet Antler Capsules", "Fange Velvet", 0.245, "bottles"},
    {"Powdered Velvet Antler", "Fange Velvet", 1.102, "kilograms"},
    {"Velvet Antler Slices (Dried)", "Fange Velvet", 0.538, "kilograms"},
    {"Antler-Based Tonic Elixir", "Fange Velvet", 0.782, "liters"},
    {"Velvet Antler Salve", "Fange Velvet", 0.312, "jars"},
    {"Luxury Antler Infused Tea", "Fange Velvet", 0.874, "canisters"},
    {"Antler Resin Bars", "Fange Velvet", 1.090, "bricks"},
    {"Velvet Antler Wine (Fortified)", "Fange Velvet", 2.320, "bottles"},
    {"Velvet Antler Soap", "Fange Velvet", 2.50, "bars"},
    {"Antler Horn Carvings (Polished Ends)", "Fange Velvet", 0.152, "units"},
    {"Wheat (Unmilled)", "Port of Corumia", 0.30, "tons"},
    {"Oats (Unhulled)", "Port of Corumia", 0.23, "tons"},
    {"Hay (Dry Bundled)", "Port of Corumia", 0.45, "bales"},
    {"Cereal Base Grain Blend", "Port of Corumia", 0.52, "pallets"},
    {"Nou-Oname Leaves (Dried)", "Port of Corumia", 10.45, "satchels"},
    {"Adraso-Onam (Dried Herb Mix)", "Port of Corumia", 19.01, "bundles"},
    {"Eeli-Illt-Eda Meat (Fresh)", "Port of Corumia", 2.38, "tons"},
    {"Calamari (Lake Norton)", "Port of Corumia", 2.38, "tons"},
    {"Jied-Rarev (Unrefined Pollen)", "Port of Corumia", 5.13, "kilograms"},
    {"Fuy-Rabrev (Raw Resin)", "Port of Corumia", 5.70, "kilograms"},

}

---------------------------------------------------------
-- 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
--    Randomly modifies the base price daily,
--    applying a slight additional boost if
--    a special event occurs on that dateKey.
---------------------------------------------------------
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  -- small boost for special events
    else
        explanation = "General market fluctuations."
    end

    local newPrice = math.floor((basePrice * (1 + changeFactor)) * 100) / 100
    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 Table Generation
---------------------------------------------------------
function p.generateTable()
    -------------------------------------------------------
    -- Step A: create a daily seed for randomness
    -- Uses year + yday to ensure each day is unique
    -------------------------------------------------------
    local localTime = os.date("*t")
    local dailySeed = localTime.year * 1000 + localTime.yday
    math.randomseed(dailySeed)

    -- Step B: gather date info
    local dateString, dayOfMonth, month = getCurrentDate()

    -- Step C: build table header
    local wikitable =
        "{| class=\"wikitable\"\n" ..
        "! Date (Day/Month/Year [[PSSC]]) !! Product !! Producing Company !! Base Price !! Price Level !! Tier III Price !! Tier II Price !! Tier I Price !! Units !! Explanation\n"

    -- We’ll track totals so we can compare average base vs. average new.
    local totalBase, totalNew = 0, 0
    local count = 0

    -- Step D: process each product with new daily random changes
    for _, product in ipairs(products) do
        local name     = product[1]
        local company  = product[2]
        local basePrice= product[3]
        local unit     = product[4]

        -- 1) Adjust price with daily random change
        local newPrice, changeFactor, explanation = simulatePriceChange(basePrice, dayOfMonth, month)

        -- 2) Determine price level (swapped logic)
        local priceLevel = determinePriceLevel(basePrice, newPrice)

        -- choose row color
        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;"'  -- light red
        end

        -- 3) Tier prices
        local tierIIIPrice = math.floor((newPrice / 3) * 100) / 100
        local tierIIPrice  = math.floor((newPrice * 2 / 3) * 100) / 100
        local tierIPrice   = newPrice

        -- 4) Accumulate totals for later average
        totalBase = totalBase + basePrice
        totalNew  = totalNew + newPrice
        count = count + 1

        -- 5) Insert row with coloring
        wikitable = wikitable .. string.format(
            "|-%s\n| %s || %s || %s || %.2f || %s || %.2f || %.2f || %.2f || %s || %s\n",
            rowStyle,
            dateString,
            name,
            company,
            basePrice,
            priceLevel,
            tierIIIPrice,
            tierIIPrice,
            tierIPrice,
            unit,
            explanation
        )
    end

    -- Step E: compute average and determine overall level (swapped)
    local avgBase = totalBase / count
    local avgNew  = totalNew / count
    local averagePriceLevel
    if avgNew > avgBase then
        averagePriceLevel = "Low"
    elseif avgNew < avgBase then
        averagePriceLevel = "High"
    else
        averagePriceLevel = "Standard"
    end

    -- Step F: add a final row at the bottom
    wikitable = wikitable .. string.format(
        "|-\n! colspan=\"10\" | Average adjusted price (%.2f) compared to average base price (%.2f) is **%s**.\n",
        avgNew, avgBase, averagePriceLevel
    )

    -- Close table
    wikitable = wikitable .. "|}"
    return wikitable
end

return p