uz me to nebavi
Some checks failed
CI and deploy / migration-check (push) Failing after 22s
CI and deploy / deploy (push) Has been skipped

This commit is contained in:
Dusan Vojacek
2026-05-21 15:17:09 +02:00
parent fc0761fb2a
commit 649c9e9510
4 changed files with 56 additions and 38 deletions

View File

@@ -1420,39 +1420,41 @@ class ChargeAcquisitionArbitrageTests(unittest.TestCase):
)
self.assertLess(evening.battery_setpoint_w, -500)
def test_morning_pv_export_when_sell_above_acquisition_and_later_grid_charge(self) -> None:
"""Ráno sell>acquisition a sell<buy, později levné grid CHARGE — FVE→síť, ne do bat."""
base = datetime(2026, 5, 22, 3, 0, tzinfo=timezone.utc)
morning = PlanningSlot(
def test_no_pv_export_at_low_sell_when_evening_peak_much_higher(self) -> None:
"""Odpolední sell ~1,4 a večer ~5,5 — PV do baterie, ne FVE→síť za haléř."""
base = datetime(2026, 5, 21, 12, 0, tzinfo=timezone.utc)
afternoon = PlanningSlot(
interval_start=base,
buy_price=5.2,
sell_price=3.4,
pv_a_forecast_w=2000,
buy_price=4.5,
sell_price=1.4,
pv_a_forecast_w=8000,
pv_b_forecast_w=0,
load_baseline_w=600,
load_baseline_w=2500,
ev1_connected=False,
ev2_connected=False,
allow_charge=False,
allow_discharge_export=False,
charge_acquisition_buy_czk_kwh=0.55,
charge_acquisition_buy_czk_kwh=0.82,
future_sell_opportunity_czk_kwh=5.5,
)
cheap = PlanningSlot(
interval_start=base + timedelta(minutes=15),
buy_price=0.55,
interval_start=base + timedelta(hours=20),
buy_price=0.5,
sell_price=-0.2,
pv_a_forecast_w=5000,
pv_a_forecast_w=0,
pv_b_forecast_w=0,
load_baseline_w=1800,
load_baseline_w=2000,
ev1_connected=False,
ev2_connected=False,
allow_charge=True,
allow_discharge_export=False,
charge_acquisition_buy_czk_kwh=0.55,
charge_acquisition_buy_czk_kwh=0.82,
future_sell_opportunity_czk_kwh=5.5,
)
evening = PlanningSlot(
interval_start=base + timedelta(minutes=30),
peak = PlanningSlot(
interval_start=base + timedelta(hours=7),
buy_price=7.0,
sell_price=5.0,
sell_price=5.5,
pv_a_forecast_w=0,
pv_b_forecast_w=0,
load_baseline_w=2500,
@@ -1460,9 +1462,10 @@ class ChargeAcquisitionArbitrageTests(unittest.TestCase):
ev2_connected=False,
allow_charge=False,
allow_discharge_export=True,
charge_acquisition_buy_czk_kwh=0.55,
charge_acquisition_buy_czk_kwh=0.82,
future_sell_opportunity_czk_kwh=5.5,
)
slots = [morning, cheap, evening]
slots = [afternoon, peak, cheap]
battery = _battery(uc_wh=64_000.0, min_pct=12.0, arb_pct=20.0)
battery.max_charge_power_w = 18_000
battery.max_discharge_power_w = 18_000
@@ -1472,7 +1475,7 @@ class ChargeAcquisitionArbitrageTests(unittest.TestCase):
SimpleNamespace(max_charge_power_w=0, battery_capacity_kwh=1.0, default_target_soc_pct=80.0),
SimpleNamespace(max_charge_power_w=0, battery_capacity_kwh=1.0, default_target_soc_pct=80.0),
]
soc0 = 0.25 * battery.usable_capacity_wh
soc0 = 0.5 * battery.usable_capacity_wh
results, _ms, _ = solve_dispatch(
slots,
battery,
@@ -1484,14 +1487,17 @@ class ChargeAcquisitionArbitrageTests(unittest.TestCase):
50.0,
operating_mode="AUTO",
)
am = results[0]
self.assertLess(
am.grid_setpoint_w,
-100,
"morning PV surplus should export when later cheap grid charge exists",
pm = results[0]
self.assertGreaterEqual(
pm.grid_setpoint_w,
-50,
"low sell with high evening peak: keep PV for battery, not grid dump",
)
self.assertGreater(
pm.battery_setpoint_w,
500,
"PV surplus should charge battery ahead of evening export",
)
self.assertIn(am.export_mode, ("PV_SURPLUS", "BATTERY_SELL"))
self.assertLessEqual(am.battery_setpoint_w, 100)
if __name__ == "__main__":