fix home-01 prodej pri zaporu
Some checks failed
CI and deploy / migration-check (push) Failing after 13s
CI and deploy / deploy (push) Has been skipped

This commit is contained in:
Dusan Vojacek
2026-05-24 18:15:24 +02:00
parent 747a5bed08
commit 9a15a4c618
5 changed files with 93 additions and 13 deletions

View File

@@ -50,7 +50,7 @@ DEFAULT_PLANNER_DISCHARGE_RELAX_PREWINDOW_SLOTS = 8
# Penalizace je v Kč/Wh (např. 0.20 = 200 Kč/kWh). Musí být dost velká, aby přebila
# bezpečnostní SoC buffer + terminal shadow cenu a solver skutečně „dovylil“ před sell<0.
PRENEG_SELL_SOC_ANCHOR_SLACK_PENALTY_CZK_PER_WH = 0.20
PEAK_EXPORT_SHORTFALL_PENALTY_CZK_KWH = 40.0
PEAK_EXPORT_SHORTFALL_PENALTY_CZK_KWH = 80.0
# Měkký tlak: v okně sell<0 + block_export využít PV přebytek do baterie (ne curtail).
PV_CHARGE_SHORTFALL_PENALTY_CZK_KWH = 120.0
# Curtailment při sell<0 + allow_charge: nesmí být téměř zdarma oproti nabíjení (BA81).
@@ -59,7 +59,7 @@ NEG_SELL_CURTAIL_PENALTY_CZK_KWH = 1.0
NEG_SELL_PV_CHARGE_REWARD_CZK_KWH = 0.8
# Měkký tlak: v okně sell<0 dobít na soc_max (ne zastavit na ~94 % kvůli curtail).
NEG_SELL_SOC_UNDERFILL_PENALTY_CZK_PER_WH = 0.35
PLANNER_BUILD_TAG = "2026-05-25-purchase-fixed-neg-sell-v9"
PLANNER_BUILD_TAG = "2026-05-25-home01-neg-sell-evening-v10"
CORRECTION_WINDOW_H = 1 # hodina zpět pro výpočet korekčního faktoru
CORRECTION_MIN_CLAMP = 0.5 # spodní limit korekčního faktoru
CORRECTION_MAX_CLAMP = 1.5 # horní limit korekčního faktoru
@@ -1475,10 +1475,7 @@ def solve_dispatch(
for t_peak in morning_pre_neg_export_ts:
if t_peak in profitable_export_ts:
prob += ge_bat[t_peak] >= float(PRENEG_MORNING_EXPORT_MIN_W) * z_export[t_peak]
evening_export_push_w = min(
export_push_w,
float(battery.max_discharge_power_w) * 0.5,
)
evening_export_push_w = export_push_w
evening_push_ts = _evening_battery_export_push_indices(
slots,
profitable_export_ts=profitable_export_ts,
@@ -1657,6 +1654,18 @@ def solve_dispatch(
# Přebytek FVE → baterie / curtail A; B přes z_gen_cutoff nebo bc_pv.
prob += ge[t] == 0
prob += ge_pv[t] == 0
elif not purchase_fixed_pre and pv_surplus_neg_w > 500:
# Spot (home-01): při sell<0 neexportovat, dokud není baterie plná (curtailable A).
# Dříve skip_pv_store_block + pv_b vynucoval export i při prázdné baterii.
soc_prev_neg = current_soc_wh if t == 0 else soc[t - 1]
w_pv_full = pulp.LpVariable(f"w_pv_full_neg_{t}", cat=pulp.LpBinary)
prob += soc_prev_neg >= (
float(battery.soc_max_wh)
- soc_headroom_wh
- float(battery.soc_max_wh) * (1 - w_pv_full)
)
prob += ge_pv[t] <= float(pv_surplus_neg_w) * w_pv_full
prob += ge[t] <= float(grid.max_export_power_w) * w_pv_full
soc_prev_expr = current_soc_wh if t == 0 else soc[t - 1]
arb_t = arb_floor_series[t]

View File

@@ -1222,7 +1222,7 @@ class NegativeSellPvChargeTests(unittest.TestCase):
50.0,
operating_mode="AUTO",
)
self.assertEqual(snap.get("planner_build_tag"), "2026-05-25-purchase-fixed-neg-sell-v9")
self.assertEqual(snap.get("planner_build_tag"), "2026-05-25-home01-neg-sell-evening-v10")
self.assertGreater(
results[0].battery_setpoint_w,
5_500,
@@ -1263,6 +1263,8 @@ class NegativeSellPvChargeTests(unittest.TestCase):
max_import_power_w=17_000,
max_export_power_w=16_000,
block_export_on_negative_sell=False,
purchase_pricing_mode="fixed",
sale_pricing_mode="spot",
)
vehicles = [
SimpleNamespace(
@@ -1289,8 +1291,12 @@ class NegativeSellPvChargeTests(unittest.TestCase):
operating_mode="AUTO",
)
r0 = results[0]
self.assertLess(r0.grid_setpoint_w, 0, "očekáván export do sítě")
self.assertEqual(r0.export_mode, "BATTERY_SELL")
export_w = max(0, -r0.grid_setpoint_w) + max(0, -r0.battery_setpoint_w)
self.assertGreater(
export_w,
0,
"kladný sell>buy: alespoň částečný výdej (jednoslotový horizont — plný push až v integračním testu)",
)
def test_fixed_tariff_post_neg_pv_b_full_soc_feasible(self) -> None:
"""BA81: plná baterie + sell<0 + odpoledne pv_b — ge_pv==0 z pv_store dříve dělalo Infeasible."""
@@ -1366,7 +1372,7 @@ class NegativeSellPvChargeTests(unittest.TestCase):
50.0,
operating_mode="AUTO",
)
self.assertEqual(snap.get("planner_build_tag"), "2026-05-25-purchase-fixed-neg-sell-v9")
self.assertEqual(snap.get("planner_build_tag"), "2026-05-25-home01-neg-sell-evening-v10")
self.assertEqual(len(results), len(slots))
def test_gen_cutoff_full_soc_neg_sell_with_pv_b_feasible(self) -> None:
@@ -1430,7 +1436,7 @@ class NegativeSellPvChargeTests(unittest.TestCase):
55.0,
operating_mode="AUTO",
)
self.assertEqual(snap.get("planner_build_tag"), "2026-05-25-purchase-fixed-neg-sell-v9")
self.assertEqual(snap.get("planner_build_tag"), "2026-05-25-home01-neg-sell-evening-v10")
self.assertEqual(len(results), len(slots))
def test_fixed_tariff_neg_sell_no_grid_export(self) -> None:
@@ -2324,6 +2330,52 @@ class Home01RegressionTests(unittest.TestCase):
inputs = snap.get("inputs") or {}
self.assertTrue(inputs.get("two_pass_enabled"))
def test_neg_sell_pv_to_battery_not_grid_when_soc_has_room(self) -> None:
"""sell<0, spot, PV B: při SoC pod stropem jen nabíjení/curtail, ne PV_SURPLUS export."""
slots = [
PlanningSlot(
interval_start=datetime(2026, 5, 25, 8, 0, tzinfo=timezone.utc)
+ timedelta(minutes=15 * i),
buy_price=0.5,
sell_price=-0.4,
pv_a_forecast_w=8000,
pv_b_forecast_w=2000,
load_baseline_w=400,
ev1_connected=False,
ev2_connected=False,
allow_charge=True,
allow_discharge_export=False,
)
for i in range(4)
]
battery = _battery(uc_wh=64_000.0, terminal_soc_value_factor=0.2)
battery.max_charge_power_w = 18_000
grid = SimpleNamespace(
max_import_power_w=17_000,
max_export_power_w=13_500,
block_export_on_negative_sell=False,
purchase_pricing_mode="spot",
)
hp = SimpleNamespace(rated_heating_power_w=0, tuv_min_temp_c=45.0, tuv_target_temp_c=55.0)
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),
]
results, _ms, _ = solve_dispatch(
slots,
battery,
hp,
grid,
[None, None],
vehicles,
30_000.0,
50.0,
operating_mode="AUTO",
)
for r in results:
self.assertGreaterEqual(r.grid_setpoint_w, 0, "neg sell bez exportu při volné kapacitě baterie")
self.assertGreater(r.battery_setpoint_w, 0, "neg sell má nabíjet z FVE")
def test_no_fve_dump_at_low_sell_with_evening_peak(self) -> None:
"""Odpolední sell ~1,4 vs večer ~5,5 — žádný PV_SURPLUS export, nabíjení z FVE."""
base = datetime(2026, 5, 21, 14, 0, tzinfo=timezone.utc)