@@ -44,36 +44,40 @@ func TestMPCPersistence_SaveAndLoad(t *testing.T) {
4444 now := time .Now ().Unix ()
4545 decisions := []mpc.ControlDecision {
4646 {
47- Hour : 0 ,
48- Timestamp : now + 3600 ,
49- BatteryCharge : 10.5 ,
50- BatteryDischarge : 0 ,
51- GridImport : 5.0 ,
52- GridExport : 0 ,
53- BatterySOC : 0.6 ,
54- Profit : 2.5 ,
55- ImportPrice : 0.1 ,
56- ExportPrice : 0.05 ,
57- SolarForecast : 15.0 ,
58- LoadForecast : 10.0 ,
59- CloudCoverage : 30.0 ,
60- WeatherSymbol : "clearsky_day" ,
47+ Hour : 0 ,
48+ Timestamp : now + 3600 ,
49+ BatteryCharge : 10.5 ,
50+ BatteryChargeFromPV : 10.5 ,
51+ BatteryChargeFromGrid : 5.0 ,
52+ BatteryDischarge : 0 ,
53+ GridImport : 5.0 ,
54+ GridExport : 0 ,
55+ BatterySOC : 0.6 ,
56+ Profit : 2.5 ,
57+ ImportPrice : 0.1 ,
58+ ExportPrice : 0.05 ,
59+ SolarForecast : 15.0 ,
60+ LoadForecast : 10.0 ,
61+ CloudCoverage : 30.0 ,
62+ WeatherSymbol : "clearsky_day" ,
6163 },
6264 {
63- Hour : 1 ,
64- Timestamp : now + 7200 ,
65- BatteryCharge : 0 ,
66- BatteryDischarge : 8.0 ,
67- GridImport : 0 ,
68- GridExport : 3.0 ,
69- BatterySOC : 0.5 ,
70- Profit : 3.2 ,
71- ImportPrice : 0.12 ,
72- ExportPrice : 0.06 ,
73- SolarForecast : 20.0 ,
74- LoadForecast : 12.0 ,
75- CloudCoverage : 10.0 ,
76- WeatherSymbol : "fair_day" ,
65+ Hour : 1 ,
66+ Timestamp : now + 7200 ,
67+ BatteryCharge : 0 ,
68+ BatteryChargeFromPV : 0 ,
69+ BatteryChargeFromGrid : 0 ,
70+ BatteryDischarge : 8.0 ,
71+ GridImport : 0 ,
72+ GridExport : 3.0 ,
73+ BatterySOC : 0.5 ,
74+ Profit : 3.2 ,
75+ ImportPrice : 0.12 ,
76+ ExportPrice : 0.06 ,
77+ SolarForecast : 20.0 ,
78+ LoadForecast : 12.0 ,
79+ CloudCoverage : 10.0 ,
80+ WeatherSymbol : "fair_day" ,
7781 },
7882 }
7983
@@ -103,6 +107,12 @@ func TestMPCPersistence_SaveAndLoad(t *testing.T) {
103107 if decision .BatteryCharge != decisions [i ].BatteryCharge {
104108 t .Errorf ("Decision %d: expected battery_charge %.2f, got %.2f" , i , decisions [i ].BatteryCharge , decision .BatteryCharge )
105109 }
110+ if decision .BatteryChargeFromPV != decisions [i ].BatteryChargeFromPV {
111+ t .Errorf ("Decision %d: expected battery_charge_from_pv %.2f, got %.2f" , i , decisions [i ].BatteryChargeFromPV , decision .BatteryChargeFromPV )
112+ }
113+ if decision .BatteryChargeFromGrid != decisions [i ].BatteryChargeFromGrid {
114+ t .Errorf ("Decision %d: expected battery_charge_from_grid %.2f, got %.2f" , i , decisions [i ].BatteryChargeFromGrid , decision .BatteryChargeFromGrid )
115+ }
106116 if decision .Profit != decisions [i ].Profit {
107117 t .Errorf ("Decision %d: expected profit %.2f, got %.2f" , i , decisions [i ].Profit , decision .Profit )
108118 }
@@ -238,10 +248,10 @@ func TestMPCPersistence_LoadOnlyFutureDecisions(t *testing.T) {
238248 // Insert directly to test load filtering
239249 for _ , d := range decisions {
240250 _ , err := db .Exec (`
241- INSERT INTO mpc_decisions (timestamp, hour, battery_charge, battery_discharge ,
242- grid_import, grid_export, battery_soc, profit, import_price, export_price ,
243- solar_forecast, load_forecast)
244- VALUES ($1, $2, 0, 0, 0, 0, 0.5, $3, 0.1, 0.05, 10, 5)
251+ INSERT INTO mpc_decisions (timestamp, hour, battery_charge, battery_charge_from_pv ,
252+ battery_charge_from_grid, battery_discharge, grid_import, grid_export, battery_soc ,
253+ profit, import_price, export_price, solar_forecast, load_forecast)
254+ VALUES ($1, $2, 0, 0, 0, 0, 0, 0, 0 .5, $3, 0.1, 0.05, 10, 5)
245255 ` , d .Timestamp , d .Hour , d .Profit )
246256 if err != nil {
247257 t .Fatalf ("Failed to insert decision: %v" , err )
@@ -299,21 +309,21 @@ func TestMPCPersistence_UniqueTimestamp(t *testing.T) {
299309
300310 // Insert first decision
301311 _ , err = db .Exec (`
302- INSERT INTO mpc_decisions (timestamp, hour, battery_charge, battery_discharge ,
303- grid_import, grid_export, battery_soc, profit, import_price, export_price ,
304- solar_forecast, load_forecast)
305- VALUES ($1, 0, 10, 0, 5, 0, 0.6, 2.5, 0.1, 0.05, 15, 10)
312+ INSERT INTO mpc_decisions (timestamp, hour, battery_charge, battery_charge_from_pv ,
313+ battery_charge_from_grid, battery_discharge, grid_import, grid_export, battery_soc ,
314+ profit, import_price, export_price, solar_forecast, load_forecast)
315+ VALUES ($1, 0, 10, 10, 0, 0, 5, 0, 0.6, 2.5, 0.1, 0.05, 15, 10)
306316 ` , timestamp )
307317 if err != nil {
308318 t .Fatalf ("Failed to insert first decision: %v" , err )
309319 }
310320
311321 // Try to insert duplicate timestamp (should be handled by UPSERT in saveMPCDecisions)
312322 _ , err = db .Exec (`
313- INSERT INTO mpc_decisions (timestamp, hour, battery_charge, battery_discharge ,
314- grid_import, grid_export, battery_soc, profit, import_price, export_price ,
315- solar_forecast, load_forecast)
316- VALUES ($1, 1, 20, 0, 10, 0, 0.7, 5.0, 0.12, 0.06, 20, 12)
323+ INSERT INTO mpc_decisions (timestamp, hour, battery_charge, battery_charge_from_pv ,
324+ battery_charge_from_grid, battery_discharge, grid_import, grid_export, battery_soc ,
325+ profit, import_price, export_price, solar_forecast, load_forecast)
326+ VALUES ($1, 1, 20, 20, 0, 0, 10, 0, 0.7, 5.0, 0.12, 0.06, 20, 12)
317327 ON CONFLICT (timestamp) DO UPDATE SET
318328 hour = EXCLUDED.hour,
319329 profit = EXCLUDED.profit
0 commit comments