zas oprava KV1 a BA81
Some checks failed
CI and deploy / migration-check (push) Failing after 41s
CI and deploy / deploy (push) Has been skipped

This commit is contained in:
Dusan Vojacek
2026-06-01 19:04:11 +02:00
parent 0dcf11d471
commit 63eff96c5f
5 changed files with 189 additions and 7 deletions

View File

@@ -71,7 +71,7 @@ NEG_BUY_CHARGE_SHORTFALL_PENALTY_CZK_KWH = 100.0
PRE_NEG_CHARGE_PENALTY_CZK_KWH = 400.0
PRE_NEG_BATT_EXPORT_SHORTFALL_PENALTY_CZK_KWH = 80.0
PRE_NEG_BATT_EXPORT_MIN_SELL_CZK_KWH = 1.0
PLANNER_BUILD_TAG = "2026-06-01-fixed-pv-export-min-sell-charge-v58"
PLANNER_BUILD_TAG = "2026-06-01-fixed-grid-charge-min-sell-v59"
# Ranní slabá FVE: neaplikovat pv_store ge_pv=0 (jinak curtail při sell < večerní peak).
DAWN_LOW_PV_NO_CURTAIL_W = 1500
# BA81/KV1: PV→bat jen v těsné blízkosti nejnižšího sell v horizontu (≈ poledne), ne při ~3 Kč ráno.
@@ -4039,14 +4039,25 @@ def solve_dispatch(
+ FIXED_PV_CHARGE_ONLY_NEAR_MIN_SELL_CZK_KWH
)
)
fixed_high_sell_no_pv_charge = (
fixed_sell_above_horizon_min = (
purchase_fixed_pre
and fixed_horizon_min_sell_pre is not None
and sell_t >= 0.0
and pv_surplus_w > NIGHT_EXPORT_PV_SUNRISE_SURPLUS_W
and sell_t
> fixed_horizon_min_sell_pre + FIXED_PV_CHARGE_ONLY_NEAR_MIN_SELL_CZK_KWH
)
fixed_high_sell_no_pv_charge = (
fixed_sell_above_horizon_min
and pv_surplus_w > NIGHT_EXPORT_PV_SUNRISE_SURPLUS_W
)
fixed_grid_charge_unprofitable = (
purchase_fixed_pre
and buy_t >= 0.0
and (
sell_t < buy_t + min_spread
or fixed_sell_above_horizon_min
)
)
fixed_pv_b_export_cap = (
purchase_fixed_pre
and float(s.pv_b_forecast_w) > 0
@@ -4055,8 +4066,16 @@ def solve_dispatch(
and not fixed_pre_neg_pv_export
and int(s.pv_a_forecast_w) >= DAWN_LOW_PV_NO_CURTAIL_W
)
if fixed_grid_charge_unprofitable:
prob += bc_gi[t] == 0
if fixed_high_sell_no_pv_charge:
prob += bc_pv[t] == 0
if (
purchase_fixed_pre
and t in evening_push_ts
and sell_t > buy_t + min_spread
):
prob += bc_pv[t] == 0
prob += bc_gi[t] == 0
if fixed_pre_neg_pv_export:
prob += ge_pv[t] <= max(0.0, pv_surplus_w)

View File

@@ -1757,6 +1757,136 @@ class NegativeSellPvChargeTests(unittest.TestCase):
"min sell: nabíjení z PV",
)
def test_fixed_no_grid_charge_when_sell_below_buy(self) -> None:
"""v59: KV1 — sell < buy nesmí grid→bat (22h za 6 Kč)."""
prague = ZoneInfo("Europe/Prague")
slot = PlanningSlot(
interval_start=datetime(2026, 6, 1, 22, 0, tzinfo=prague).astimezone(
timezone.utc
),
buy_price=6.353,
sell_price=3.5,
pv_a_forecast_w=0,
pv_b_forecast_w=0,
load_baseline_w=400,
ev1_connected=False,
ev2_connected=False,
allow_charge=True,
allow_discharge_export=False,
charge_acquisition_buy_czk_kwh=6.353,
)
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,
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,
),
]
soc0 = 0.25 * battery.usable_capacity_wh
results, _, _ = solve_dispatch(
[slot],
battery,
hp,
grid,
[None, None],
vehicles,
soc0,
50.0,
operating_mode="AUTO",
)
self.assertLessEqual(
results[0].battery_setpoint_w,
200,
"sell < buy: žádné grid nabíjení",
)
def test_fixed_evening_push_no_charge_at_peak_sell(self) -> None:
"""v59: večerní push — při sell>buy ne nabíjet, jen vybíjet."""
prague = ZoneInfo("Europe/Prague")
slot = PlanningSlot(
interval_start=datetime(2026, 6, 1, 20, 45, tzinfo=prague).astimezone(
timezone.utc
),
buy_price=3.088,
sell_price=9.61,
pv_a_forecast_w=2000,
pv_b_forecast_w=200,
load_baseline_w=400,
ev1_connected=False,
ev2_connected=False,
allow_charge=True,
allow_discharge_export=True,
charge_acquisition_buy_czk_kwh=3.088,
future_sell_opportunity_czk_kwh=9.0,
)
battery = _battery(uc_wh=12_500.0, min_pct=10.0, arb_pct=30.0)
battery.max_charge_power_w = 6250
battery.max_discharge_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,
),
]
soc0 = 0.85 * battery.usable_capacity_wh
results, _, _ = solve_dispatch(
[slot],
battery,
hp,
grid,
[None, None],
vehicles,
soc0,
50.0,
operating_mode="AUTO",
)
r0 = results[0]
self.assertLessEqual(
r0.battery_setpoint_w,
200,
"večerní peak: ne nabíjet baterii",
)
self.assertLess(
r0.battery_setpoint_w,
-500,
"večerní peak: vývoz z baterie",
)
def test_fixed_night_profitable_export_not_evening_early_banned(self) -> None:
"""v58: v noci sell>buy nesmí evening_early držet ge_bat=0."""
prague = ZoneInfo("Europe/Prague")