Fix fixu gri charge
All checks were successful
CI and deploy / migration-check (push) Successful in 3s
CI and deploy / deploy (push) Successful in 26s

This commit is contained in:
Dusan Vojacek
2026-04-19 14:30:31 +02:00
parent 0814b1d8e8
commit dc0e37e580
2 changed files with 39 additions and 15 deletions

View File

@@ -99,6 +99,32 @@ class SelectChargeSlotsTests(unittest.TestCase):
),
)
def test_long_horizon_pv_surplus_does_not_exhaust_grid_budget(self) -> None:
"""Regrese: v 96h horizontu nesmí PV-surplus sloty „vyžrat“ grid rozpočet.
V dřívější verzi se kumulativní PV budget odečítal od `charge_buf × headroom`,
takže v dlouhém horizontu s mnoha PV sloty zbylo 0 na grid filler a levné
grid sloty se nepovolily. Tento test simuluje realistický 96h profil.
"""
# 40 levných grid-only slotů (simulace noční / „inter-peak“ hodiny).
cheap_grid = [_slot(buy=0.4 + 0.01 * i, pv=0, load=2_000) for i in range(40)]
# 100 PV-surplus slotů s velkou výrobou (přes den, přes víc dní).
pv_days = [_slot(buy=1.5, pv=10_000, load=2_000) for _ in range(100)]
slots = cheap_grid + pv_days
battery = _battery(
charge_buf=1.3, uc_wh=64_000.0, soc_max_pct=95.0, max_charge_w=18_000.0
)
out = _select_charge_slots(slots, battery, current_soc_wh=0.2 * battery.usable_capacity_wh)
grid_selected = sum(1 for i in range(len(cheap_grid)) if i in out)
self.assertGreaterEqual(
grid_selected,
5,
msg=(
"V dlouhém horizontu s mnoha PV-surplus sloty musí zůstat dostatek "
"grid slotů povolených pro nabíjení z levného importu."
),
)
def test_energy_budget_is_charge_buf_times_headroom(self) -> None:
"""Součet uvolněné energie se pohybuje okolo charge_buf × (soc_max current_soc)."""
slots = [_slot(buy=float(i + 1), pv=0, load=2_000) for i in range(40)]