fix BA cutoff
This commit is contained in:
@@ -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-neg-sell-no-export-fixed-v8"
|
||||
PLANNER_BUILD_TAG = "2026-05-25-purchase-fixed-neg-sell-v9"
|
||||
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
|
||||
@@ -665,11 +665,20 @@ def _slot_profitable_battery_export(
|
||||
return sell_t > acq + min_spread
|
||||
|
||||
|
||||
def _purchase_pricing_fixed(grid: Any) -> bool:
|
||||
"""Režim nákupu z DB (`site_market_config.purchase_pricing_mode`), ne odhad z rozptylu buy."""
|
||||
return (
|
||||
str(getattr(grid, "purchase_pricing_mode", "spot") or "spot").strip().lower()
|
||||
== "fixed"
|
||||
)
|
||||
|
||||
|
||||
def _horizon_fixed_tariff_like(slots: list[PlanningSlot]) -> bool:
|
||||
"""
|
||||
Fixní nákup (KV1): buy v horizontu je prakticky konstantní.
|
||||
Heuristika pro drahý import / charge_acquisition: buy v horizontu je prakticky konstantní.
|
||||
U spotu (home-01) nesmí expensive_import používat charge_acquisition — jinak
|
||||
buy > ~1 Kč označí téměř všechny sloty jako drahé (gi=0 pro dům) → Infeasible.
|
||||
BA81 má fixní nákup v DB, ale NT/VT → buy skáče; proto neg-sell export řídí _purchase_pricing_fixed.
|
||||
"""
|
||||
buys = [float(s.buy_price) for s in slots if float(s.buy_price) >= 0.0]
|
||||
if not buys:
|
||||
@@ -1184,7 +1193,8 @@ def solve_dispatch(
|
||||
else min(float(s.buy_price) for s in slots)
|
||||
)
|
||||
min_spread_pre = float(degradation_cost_effective)
|
||||
fixed_tariff_like_pre = _horizon_fixed_tariff_like(slots)
|
||||
purchase_fixed_pre = _purchase_pricing_fixed(grid)
|
||||
fixed_tariff_like_pre = purchase_fixed_pre or _horizon_fixed_tariff_like(slots)
|
||||
profitable_export_ts_pre: set[int] = set()
|
||||
if om == "AUTO":
|
||||
for _t in range(T):
|
||||
@@ -1641,8 +1651,9 @@ def solve_dispatch(
|
||||
prob += ge[t] == 0
|
||||
prob += ge_pv[t] == 0
|
||||
prob += ge_bat[t] == 0
|
||||
elif fixed_tariff_like_pre:
|
||||
# BA81: při sell<0 neexportovat (záporná cena výkupu = platíš za export).
|
||||
elif purchase_fixed_pre:
|
||||
# Fixní nákup + spot výkup (BA81, KV1 bez block_export): sell<0 = platíš za vývoz.
|
||||
# Nesouvisí s NT/VT skokem buy — řídí se výkupní cenou, ne rozptylem buy v horizontu.
|
||||
# Přebytek FVE → baterie / curtail A; B přes z_gen_cutoff nebo bc_pv.
|
||||
prob += ge[t] == 0
|
||||
prob += ge_pv[t] == 0
|
||||
@@ -1833,7 +1844,7 @@ 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
|
||||
and not purchase_fixed_pre
|
||||
) or (
|
||||
# KV1: plná baterie + kladný sell — neblokovat ge_pv==0 (jinak masivní curtail).
|
||||
getattr(grid, "block_export_on_negative_sell", False)
|
||||
@@ -1842,7 +1853,7 @@ def solve_dispatch(
|
||||
)
|
||||
# BA81: export pole B jen při kladném sell (po sell<0 jinak ge==0 výše).
|
||||
fixed_pv_b_export_cap = (
|
||||
fixed_tariff_like_pre
|
||||
purchase_fixed_pre
|
||||
and float(s.pv_b_forecast_w) > 0
|
||||
and not getattr(grid, "block_export_on_negative_sell", False)
|
||||
and sell_t >= 0
|
||||
@@ -1870,7 +1881,7 @@ def solve_dispatch(
|
||||
# Spot (home-01): buy > min ne-záporného buy v horizontu.
|
||||
# Fixní tarif (KV1): navíc buy > charge_acquisition (konstantní buy ≈ ref).
|
||||
expensive_import_slot = buy_t > ref_buy_horizon + min_spread
|
||||
if _horizon_fixed_tariff_like(slots):
|
||||
if fixed_tariff_like_pre:
|
||||
expensive_import_slot = expensive_import_slot or (
|
||||
buy_t > charge_acquisition_czk_kwh + min_spread
|
||||
)
|
||||
@@ -2600,11 +2611,14 @@ async def _load_site_context(site_id: int, db):
|
||||
)
|
||||
|
||||
g = ctx["grid"]
|
||||
m = ctx.get("market") or {}
|
||||
grid = SimpleNamespace(
|
||||
max_import_power_w=int(g["max_import_power_w"]),
|
||||
max_export_power_w=int(g["max_export_power_w"]),
|
||||
block_export_on_negative_sell=bool(g.get("block_export_on_negative_sell") or False),
|
||||
deye_gen_microinverter_cutoff_enabled=bool(g.get("deye_gen_microinverter_cutoff_enabled") or False),
|
||||
purchase_pricing_mode=str(m.get("purchase_pricing_mode") or "spot").strip().lower(),
|
||||
sale_pricing_mode=str(m.get("sale_pricing_mode") or "spot").strip().lower(),
|
||||
)
|
||||
|
||||
vehicles: list[SimpleNamespace] = []
|
||||
|
||||
Reference in New Issue
Block a user