oprava KV1 nabijeni rano misto prodeje
Some checks failed
CI and deploy / migration-check (push) Failing after 14s
CI and deploy / deploy (push) Has been skipped

This commit is contained in:
Dusan Vojacek
2026-05-22 15:36:56 +02:00
parent f960e08307
commit c5525c729f
3 changed files with 97 additions and 19 deletions

View File

@@ -619,21 +619,31 @@ def _slots_with_charge_acquisition(
]
def _pv_store_value_czk_kwh(
slot: PlanningSlot,
charge_acquisition_czk_kwh: float,
min_spread: float,
) -> float:
def _pv_store_value_czk_kwh(slot: PlanningSlot, min_spread: float) -> float:
"""
Minimální efektivní sell [Kč/kWh], pod kterým je FVE→síť horší než uložení
(večerní peak / náklad zásoby z levného nákupu).
Minimální sell [Kč/kWh], pod kterým je FVE→síť horší než uložení na večerní peak.
Používá jen future_sell_opportunity (ne charge_acquisition — u fixního tarifu KV1
by jinak blokoval export i při kladném sell 2 Kč).
"""
future = float(
slot.future_sell_opportunity_czk_kwh
if slot.future_sell_opportunity_czk_kwh is not None
else slot.sell_price
)
return max(future, float(charge_acquisition_czk_kwh)) - min_spread
return future - min_spread
def _pre_negative_sell_export_window(
slots: list[PlanningSlot],
) -> tuple[int | None, int | None]:
"""Index prvního sell<0 a posledního slotu před ním (pro strategii „vyvézt dřív“)."""
first_neg = next(
(i for i, s in enumerate(slots) if float(s.sell_price) < 0),
None,
)
if first_neg is None or first_neg <= 0:
return first_neg, None
return first_neg, first_neg - 1
def _pv_forced_vent_export_allowed(
@@ -917,7 +927,7 @@ def solve_dispatch(
# Kotva: poslední slot před prvním sell<0 by měl končit u planner floor (pokud relaxace existuje).
# Slack penalizujeme v objective; samotné omezení přidáme až po definici soc.
first_neg_sell_idx = next((i for i, s in enumerate(slots) if float(s.sell_price) < 0), None)
first_neg_sell_idx, pre_neg_export_last_t = _pre_negative_sell_export_window(slots)
if first_neg_sell_idx is not None and first_neg_sell_idx > 0 and floor_pct is not None:
t_anchor = first_neg_sell_idx - 1
soc_anchor_slack = pulp.LpVariable("soc_anchor_slack_wh", 0, float(battery.usable_capacity_wh))
@@ -1311,16 +1321,25 @@ def solve_dispatch(
0.0,
float(s.pv_a_forecast_w) + float(s.pv_b_forecast_w) - load_t,
)
# FVE export jen pokud sell ≥ hodnota uložení (večerní peak / acquisition degradace).
pv_store_val = _pv_store_value_czk_kwh(
s, charge_acquisition_czk_kwh, min_spread
# FVE export: před prvním sell<0 smí jít přebytek do sítě (kladný sell), pak nabít
# v záporném okně z PV. Jinak držet energii na future_sell peak.
allow_pre_neg_pv_export = (
first_neg_sell_idx is not None
and pre_neg_export_last_t is not None
and t <= pre_neg_export_last_t
and sell_t >= 0
)
if sell_t < pv_store_val and not _pv_forced_vent_export_allowed(
t,
current_soc_wh=current_soc_wh,
battery=battery,
soc_headroom_wh=soc_headroom_wh,
pv_surplus_w=pv_surplus_w,
pv_store_val = _pv_store_value_czk_kwh(s, min_spread)
if (
not allow_pre_neg_pv_export
and sell_t < pv_store_val
and not _pv_forced_vent_export_allowed(
t,
current_soc_wh=current_soc_wh,
battery=battery,
soc_headroom_wh=soc_headroom_wh,
pv_surplus_w=pv_surplus_w,
)
):
prob += ge_pv[t] == 0
# Drahý nákup: dům + TČ z baterie (ne import ze sítě); síť jen EV (+ případně TČ).

View File

@@ -1818,6 +1818,65 @@ class LoadFirstDispatchTests(unittest.TestCase):
self.assertEqual(r.export_mode, "PV_SURPLUS")
class PreNegativeSellExportTests(unittest.TestCase):
"""Před prvním sell<0: export přebytku (BA81/KV1 strategie), ne nabíjení + pozdní vývoz."""
def test_kv1_like_morning_exports_before_negative_sell_window(self) -> None:
base = datetime(2026, 5, 22, 6, 45, tzinfo=timezone.utc)
slots = [
PlanningSlot(
interval_start=base + timedelta(minutes=15 * i),
buy_price=6.35,
sell_price=2.2,
pv_a_forecast_w=5000,
pv_b_forecast_w=0,
load_baseline_w=400,
ev1_connected=False,
ev2_connected=False,
allow_charge=False,
allow_discharge_export=False,
charge_acquisition_buy_czk_kwh=6.35,
future_sell_opportunity_czk_kwh=5.5,
)
for i in range(8)
] + [
PlanningSlot(
interval_start=base + timedelta(hours=2),
buy_price=6.35,
sell_price=-0.3,
pv_a_forecast_w=6000,
pv_b_forecast_w=0,
load_baseline_w=400,
ev1_connected=False,
ev2_connected=False,
allow_charge=False,
allow_discharge_export=False,
charge_acquisition_buy_czk_kwh=6.35,
future_sell_opportunity_czk_kwh=-0.3,
),
]
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=True,
)
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),
]
soc0 = 0.85 * battery.soc_max_wh
results, _, _ = solve_dispatch(
slots, battery, hp, grid, [None, None], vehicles, soc0, 50.0, operating_mode="AUTO"
)
self.assertLess(results[0].grid_setpoint_w, -500, "ráno: přebytek FVE do sítě před sell<0")
neg = results[8]
self.assertGreater(neg.battery_setpoint_w, 500, "záporný sell: PV do baterie")
self.assertEqual(neg.export_mode, "NONE")
class Home01PvStoreValueTests(unittest.TestCase):
"""FVE (zejména pole B) nesmí jít do sítě pod hodnotou uložení / večerní peak."""