Branch 3: charge-slot-budget v R__063 + odstranit v58 pro BA81/KV1 + fixed evening push
Some checks failed
CI and deploy / migration-check (push) Failing after 25s
CI and deploy / deploy (push) Has been skipped

This commit is contained in:
Dusan Vojacek
2026-06-06 22:32:48 +02:00
parent 09bca0a903
commit a7879f1141
7 changed files with 252 additions and 162 deletions

View File

@@ -337,22 +337,32 @@ def _select_charge_slots(
elif purchase_pricing_mode == "fixed" and any(
float(s.sell_price) > float(s.buy_price) + degrad for s in slots
):
min_sell_pos = min(
float(s.sell_price) for s in slots if float(s.sell_price) >= 0.0
)
am_candidates = [
(t, getattr(slots[t], "is_predicted_price", False))
(
t,
getattr(slots[t], "is_predicted_price", False),
float(slots[t].sell_price),
)
for t in range(len(slots))
if _prague_hour(slots[t]) < 12
and float(slots[t].sell_price) >= 0.0
and float(slots[t].sell_price) <= min_sell_pos + degrad + 0.05
]
am_candidates.sort(
key=lambda x: (
_grid_sort_key(x[0], x[1], 0.0)[0],
_grid_sort_key(x[0], x[1], 0.0)[1],
_grid_sort_key(x[0], x[1], 0.0)[2],
_grid_sort_key(x[0], x[1], x[2])[0],
_grid_sort_key(x[0], x[1], x[2])[1],
_grid_sort_key(x[0], x[1], x[2])[2],
x[2],
x[0],
)
)
cum = 0.0
grid_am = 0
for t, _pred in am_candidates:
for t, _pred, _sell in am_candidates:
if cum >= chg_am or per_slot_full_wh <= 0 or grid_am >= cap_am:
break
selected.add(t)
@@ -369,21 +379,28 @@ def _select_charge_slots(
),
)
pm_candidates = [
(t, getattr(slots[t], "is_predicted_price", False))
(
t,
getattr(slots[t], "is_predicted_price", False),
float(slots[t].sell_price),
)
for t in range(len(slots))
if _prague_hour(slots[t]) >= 12
and float(slots[t].sell_price) >= 0.0
and float(slots[t].sell_price) <= min_sell_pos + degrad + 0.05
]
pm_candidates.sort(
key=lambda x: (
_grid_sort_key(x[0], x[1], 0.0)[0],
_grid_sort_key(x[0], x[1], 0.0)[1],
_grid_sort_key(x[0], x[1], 0.0)[2],
_grid_sort_key(x[0], x[1], x[2])[0],
_grid_sort_key(x[0], x[1], x[2])[1],
_grid_sort_key(x[0], x[1], x[2])[2],
x[2],
x[0],
)
)
cum = 0.0
grid_pm = 0
for t, _pred in pm_candidates:
for t, _pred, _sell in pm_candidates:
if cum >= chg_pm or per_slot_full_wh <= 0 or grid_pm >= cap_pm:
break
selected.add(t)
@@ -398,15 +415,22 @@ def _select_charge_slots(
fso = _future_sell(slots, t)
if (
pv_surplus_w > 0
and float(s.sell_price) >= float(s.buy_price) - degrad
and (
float(s.sell_price) < 0
purchase_pricing_mode == "fixed"
or float(s.sell_price) >= float(s.buy_price) - degrad
)
and (
purchase_pricing_mode == "fixed"
or float(s.sell_price) < 0
or float(s.sell_price) >= fso - degrad
)
):
pv_candidates.append((t, _store_score(slots, t), float(pv_surplus_w)))
pv_candidates.sort(key=lambda x: (-x[1], x[0]))
if purchase_pricing_mode == "fixed":
pv_candidates.sort(key=lambda x: (float(slots[x[0]].sell_price), x[0]))
else:
pv_candidates.sort(key=lambda x: (-x[1], x[0]))
cum = 0.0
for t, _score, pv_surplus_w in pv_candidates:
if cum >= pv_layer_cap:

View File

@@ -1675,7 +1675,9 @@ class NegativeSellPvChargeTests(unittest.TestCase):
)
def test_fixed_high_sell_no_pv_charge_near_min_sell(self) -> None:
"""v58: ráno sell~3 Kč → export FVE; poledne sell~1,45 Kč → nabíjení z PV."""
"""Charge-slot budget: levnější sell (poledne) dostane allow_charge dřív než drahší ráno."""
from test_planning_charge_slot_selection import _select_charge_slots
prague = ZoneInfo("Europe/Prague")
base = datetime(2026, 6, 2, 6, 0, tzinfo=prague)
slots: list[PlanningSlot] = []
@@ -1693,73 +1695,29 @@ class NegativeSellPvChargeTests(unittest.TestCase):
load_baseline_w=400,
ev1_connected=False,
ev2_connected=False,
allow_charge=True,
allow_discharge_export=False,
charge_acquisition_buy_czk_kwh=3.088,
future_sell_opportunity_czk_kwh=3.2,
)
)
battery = _battery(uc_wh=12_500.0, min_pct=10.0, arb_pct=30.0)
battery.max_charge_power_w = 6250
hp = SimpleNamespace(
rated_heating_power_w=0,
tuv_min_temp_c=45.0,
tuv_target_temp_c=55.0,
)
grid = SimpleNamespace(
max_import_power_w=17_000,
max_export_power_w=8000,
block_export_on_negative_sell=False,
purchase_pricing_mode="fixed",
)
vehicles = [
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,
),
]
battery.charge_slot_buffer = 1.3
soc0 = 0.35 * battery.usable_capacity_wh
results, _, snap = solve_dispatch(
charge = _select_charge_slots(
slots,
battery,
hp,
grid,
[None, None],
vehicles,
soc0,
50.0,
operating_mode="AUTO",
purchase_pricing_mode="fixed",
apply_dynamic_grid_filter=False,
)
self.assertEqual(
snap["inputs"].get("fixed_horizon_min_sell_czk_kwh"),
1.45,
)
r_morning = results[0]
r_noon = results[5]
self.assertLess(
r_morning.grid_setpoint_w,
-2000,
"vysoký sell: přebytek FVE do sítě",
)
self.assertLessEqual(
r_morning.battery_setpoint_w,
200,
"vysoký sell: ne nabíjet z PV",
)
self.assertGreater(
r_noon.battery_setpoint_w,
800,
"min sell: nabíjení z PV",
noon_idx = 4
cheap_slots = {4, 5, 6, 7}
self.assertIn(noon_idx, charge, "min sell slot má allow_charge z PV vrstvy")
self.assertTrue(
cheap_slots.issubset(charge),
"všechny sloty u min sell musí mít allow_charge dřív než dražší ranní",
)
def test_fixed_no_grid_charge_when_sell_above_horizon_min(self) -> None:
"""v59: KV1 — grid→bat jen u min sell, ne v noci za 6 Kč při sell 3,5."""
"""v59 SQL maska: grid→bat jen u min sell; LP nerespektuje allow_charge bez allow_grid."""
prague = ZoneInfo("Europe/Prague")
cheap = PlanningSlot(
interval_start=datetime(2026, 6, 2, 10, 15, tzinfo=prague).astimezone(
@@ -1787,7 +1745,7 @@ class NegativeSellPvChargeTests(unittest.TestCase):
load_baseline_w=400,
ev1_connected=False,
ev2_connected=False,
allow_charge=True,
allow_charge=False,
allow_discharge_export=False,
charge_acquisition_buy_czk_kwh=6.353,
)