feat(lagre): vælg bygning -> statistik pr. vare: værdi nu/ved toppris, gårdens beholdning i døgn, forbrug og produktion pr. døgn (v1.15.0.0)

This commit is contained in:
2026-09-24 01:54:47 +02:00
parent eb053083c2
commit a6547462fc
10 changed files with 356 additions and 3 deletions
+22
View File
@@ -20,6 +20,7 @@ SellingStation = {}
dofile("FS25_ADSmartPickup/adSupplyPlanner.lua")
dofile("FS25_ADSmartPickup/adPrices.lua")
dofile("FS25_ADSmartPickup/adStorageStats.lua")
dofile("FS25_ADSmartPickup/adSources.lua")
local failures = 0
@@ -383,5 +384,26 @@ check("S17 gylle-enden: gylle", slurryEnd[1].fillType, SLURRY)
twoEndStation.loadTriggers[1].fillTypes = nil
check("S17 uden punkt-varer: stationens varer", #ADSources.getProducts(adEnv, ADSources.identify(adEnv, 40, 1), 1), 2)
-- S18: gårdens forbrug og produktion pr. døgn (fabrikker + stalde) og bedste markedspris
tmrFactory.spec_productionPoint.productionPoint.getIsProductionEnabled = function(self, id) return id == "tmr3" end
tmrFactory.spec_productionPoint.productionPoint.productions[1].outputs = {{type = FORAGE, amount = 240}}
cowBarn.spec_husbandryWater.automaticWaterSupply = false
local rates = ADSources.getFarmRates(adEnv, 1)
-- TMR-fabrik: 45 l roer × 200/60 cyklus/min × 1440 = 216.000 l/døgn; TMR ud 240 × 200/60 × 1440 = 1.152.000
check("S18 roer forbrug", math.floor(rates[BEET].consumption + 0.5), 216000)
check("S18 TMR produktion", math.floor(rates[FORAGE].production + 0.5), 1152000)
check("S18 halm i stald 500 l/t", rates[STRAW].consumption, 12000)
check("S18 vand 100 l/t", rates[WATER].consumption, 2400)
check("S18 anden farm tæller ikke", rates[STRAW].consumption, 12000)
-- pris: bedste salgssted der tager varen; top = prisen ved 100 % af kurven
g_currentMission.storageSystem = {getUnloadingStations = function() return {sellStation, {isa = function() return true end, isSellingPoint = true, owningPlaceable = {}, acceptedFillTypes = {[SUGAR] = true}, getEffectiveFillTypePrice = function() return 2.0 end}} end}
sellStation.getEffectiveFillTypePrice = function() return 1.5 end
g_currentMission.environment = {currentPeriod = 1}
DESC[SUGAR].economy = {factors = {0.8, 1.0}}
local quote = ADSources.getMarketQuote(SUGAR)
check("S18 bedste pris", quote.price, 2.0)
check("S18 top ved 80 % af kurven", quote.top, 2.5)
check("S18 intet salgssted -> nil", ADSources.getMarketQuote(FORAGE), nil)
print(failures == 0 and "\nALLE TESTS OK" or ("\n" .. failures .. " FEJL"))
os.exit(failures == 0 and 0 or 1)
+46
View File
@@ -0,0 +1,46 @@
-- Kør: luajit tests/test_adStorageStats.lua (fra repo-roden)
-- Lagerstatistik pr. vare: fyldning, værdi nu / ved toppris, gårdens samlede beholdning, dage tilbage.
dofile("FS25_ADSmartPickup/adStorageStats.lua")
local S = ADStorageStats
local failures = 0
local function check(name, actual, expected)
if actual == expected then print("OK " .. name) else failures = failures + 1; print(string.format("FAIL %s: forventede %s, fik %s", name, tostring(expected), tostring(actual))) end
end
-- ST1: fuld beregning
local st = S.itemStats({fillType = 5, level = 150000, capacity = 180000}, 412000, {consumption = 130000, production = 48000}, {price = 1.6, top = 2.0})
check("ST1 procent", st.percent, 83)
check("ST1 værdi nu", st.valueNow, 240000)
check("ST1 værdi top", st.valueTop, 300000)
check("ST1 gårdens beholdning", st.farmTotal, 412000)
check("ST1 dage", math.floor(st.days * 10 + 0.5) / 10, 3.2)
check("ST1 netto pr. døgn", st.net, -82000)
-- ST2: ingen salgssted, intet forbrug, ingen kapacitet
local st2 = S.itemStats({fillType = 6, level = 5000, capacity = 0}, 5000, nil, nil)
check("ST2 ingen pris -> nil", st2.valueNow, nil)
check("ST2 intet forbrug -> dage nil", st2.days, nil)
check("ST2 kapacitet 0 -> procent nil", st2.percent, nil)
-- ST3: bygningens samlede værdi (kun varer med pris)
local total = S.buildingTotals({st, st2, S.itemStats({fillType = 7, level = 1000, capacity = 2000}, 1000, nil, {price = 2, top = 3})})
check("ST3 samlet nu", total.valueNow, 242000)
check("ST3 samlet top", total.valueTop, 303000)
-- ST4: gårdens totaler fra inventar
local totals = S.farmTotals({{entries = {{fillType = 5, level = 100}, {fillType = 6, level = 5}}}, {entries = {{fillType = 5, level = 50}}}})
check("ST4 sum pr. vare", totals[5], 150)
check("ST4 anden vare", totals[6], 5)
-- ST5: foder-forbrug i et fælles trug fordeles efter truget indhold; tomt trug -> bedste foder
local split = S.splitTroughConsumption(2400, {[116] = 3000, [7] = 1000}, {[116] = 1.0, [7] = 0.8})
check("ST5 TMR 75 %", split[116], 1800)
check("ST5 ensilage 25 %", split[7], 600)
local empty = S.splitTroughConsumption(2400, {}, {[116] = 1.0, [7] = 0.8})
check("ST5 tomt trug -> bedste foder", empty[116], 2400)
check("ST5 tomt trug -> intet på ensilage", empty[7], nil)
print(failures == 0 and "\nALLE TESTS OK" or ("\n" .. failures .. " FEJL"))
os.exit(failures == 0 and 0 or 1)