chjo2
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-23 23:28:50 +02:00
parent 61a58a62b1
commit 7ff2abc7e0
4 changed files with 155 additions and 15 deletions

View File

@@ -55,6 +55,11 @@ PEAK_EXPORT_SHORTFALL_PENALTY_CZK_KWH = 40.0
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).
NEG_SELL_CURTAIL_PENALTY_CZK_KWH = 1.0
# Odměna v objective za FVE→baterie při sell<0 (doplňuje shortfall; BA81 fixed tarif).
NEG_SELL_PV_CHARGE_REWARD_CZK_KWH = 0.8
# Cíl SoC v okně záporného výkupu (podíl soc_max) — safety_soc_target z SQL jde jen k ~50 %.
NEG_SELL_CHARGE_SOC_FRAC_OF_MAX = 0.92
PLANNER_BUILD_TAG = "2026-05-24-neg-sell-v2"
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
@@ -1021,19 +1026,19 @@ def solve_dispatch(
charge_slots |= {
t for t, s in enumerate(slots) if float(s.buy_price) < 0.0
}
if bool(getattr(grid, "block_export_on_negative_sell", False)):
charge_slots |= {
t
for t, s in enumerate(slots)
if float(s.sell_price) < 0.0
and max(
0,
int(s.pv_a_forecast_w)
+ int(s.pv_b_forecast_w)
- int(s.load_baseline_w),
)
> 0
}
# Stejně jako R__063 (sell<0 + PV přebytek): shortfall/curtail penalizace i bez block_export.
charge_slots |= {
t
for t, s in enumerate(slots)
if float(s.sell_price) < 0.0
and max(
0,
int(s.pv_a_forecast_w)
+ int(s.pv_b_forecast_w)
- int(s.load_baseline_w),
)
> 500
}
discharge_export_slots = {
t for t, s in enumerate(slots) if s.allow_discharge_export
}
@@ -1248,6 +1253,18 @@ def solve_dispatch(
if om == "AUTO" and t in discharge_export_slots
else 0
)
- (
bc_pv[t]
* NEG_SELL_PV_CHARGE_REWARD_CZK_KWH
* INTERVAL_H
/ 1000
if (
om == "AUTO"
and float(slots[t].sell_price) < 0.0
and t in charge_slots
)
else 0
)
+ pulp.lpSum(
ev_direct[e][t] * slots[t].buy_price * INTERVAL_H / 1000
+ ev_via_bat[e][t] * slots[t].buy_price * EV_ROUNDTRIP_FACTOR * INTERVAL_H / 1000
@@ -1399,7 +1416,17 @@ def solve_dispatch(
sv = safety_vars[t]
tgt_s = slots[t].safety_soc_target_wh if daytime_en else None
if sv is not None and tgt_s is not None:
prob += sv >= float(tgt_s) - soc[t]
eff_tgt_s = float(tgt_s)
if (
om == "AUTO"
and float(s.sell_price) < 0.0
and t in charge_slots
):
eff_tgt_s = max(
eff_tgt_s,
float(battery.soc_max_wh) * NEG_SELL_CHARGE_SOC_FRAC_OF_MAX,
)
prob += sv >= eff_tgt_s - soc[t]
# ev_via_bat kryto z discharge
prob += pulp.lpSum(ev_via_bat[e][t] for e in range(EV)) <= bd[t]
@@ -1646,7 +1673,14 @@ def solve_dispatch(
float(s.pv_b_forecast_w) > 0
and not getattr(grid, "block_export_on_negative_sell", False)
and sell_t < 0
and not fixed_tariff_like_pre
)
if (
fixed_tariff_like_pre
and sell_t < 0
and t in charge_slots
):
prob += ge_pv[t] <= max(0.0, float(s.pv_b_forecast_w))
if (
not allow_pre_neg_pv_export
and not skip_pv_store_block
@@ -1904,6 +1938,7 @@ def solve_dispatch(
night0 = slots[0]
solver_snapshot: dict[str, Any] = {
"version": 1,
"planner_build_tag": PLANNER_BUILD_TAG,
"inputs": {
"current_soc_wh": float(current_soc_wh),
"operating_mode": operating_mode,