zase upravujeme planovani hlavne pro home-01
This commit is contained in:
@@ -77,6 +77,9 @@ declare
|
||||
v_grid_slots_am int := 0;
|
||||
v_grid_slots_pm int := 0;
|
||||
v_acquisition_cutoff timestamptz;
|
||||
v_first_neg_sell_ord int;
|
||||
v_pre_neg_peak_sell_ord int;
|
||||
v_max_sell_czk_kwh numeric;
|
||||
v_charge_acquisition numeric;
|
||||
v_est_grid_wh numeric;
|
||||
v_est_pv_wh numeric;
|
||||
@@ -490,6 +493,11 @@ begin
|
||||
v_grid_slots_pm := v_grid_slots_pm + 1;
|
||||
end loop;
|
||||
v_grid_filled_wh := v_grid_filled_wh + v_cum;
|
||||
|
||||
-- Spot: záporný buy → grid nabíjení ve všech slotech (maximální arbitráž), mimo AM/PM rozpočet.
|
||||
update _ems_plan_slot_wk wk
|
||||
set allow_charge = true, allow_grid_charge = true
|
||||
where wk.buy_price < 0;
|
||||
end if;
|
||||
|
||||
-- A) PV-surplus: jen zbytek kapacity po grid vrstvě B
|
||||
@@ -538,6 +546,47 @@ begin
|
||||
end loop;
|
||||
end if;
|
||||
|
||||
-- Globální sell špičky (≈ max sell v horizontu): vždy export baterie, i po vyčerpání Wh rozpočtu.
|
||||
select coalesce(max(wk.sell_price), 0)
|
||||
into v_max_sell_czk_kwh
|
||||
from _ems_plan_slot_wk wk;
|
||||
|
||||
if v_max_sell_czk_kwh > 0 then
|
||||
update _ems_plan_slot_wk wk
|
||||
set allow_discharge_export = true
|
||||
where wk.sell_price >= v_max_sell_czk_kwh - v_degrad_czk_kwh
|
||||
and (
|
||||
case
|
||||
when v_purchase_pricing_mode = 'fixed' then
|
||||
wk.sell_price > v_degrad_czk_kwh
|
||||
else
|
||||
wk.sell_price > v_ref_buy_czk_kwh + v_degrad_czk_kwh
|
||||
end
|
||||
);
|
||||
end if;
|
||||
|
||||
-- Před prvním sell<0: export baterie v lokálním maximu kladného sell (ne jen v posledních slotech).
|
||||
select min(wk.slot_ord)
|
||||
into v_first_neg_sell_ord
|
||||
from _ems_plan_slot_wk wk
|
||||
where wk.sell_price < 0;
|
||||
|
||||
if v_first_neg_sell_ord is not null then
|
||||
select wk.slot_ord
|
||||
into v_pre_neg_peak_sell_ord
|
||||
from _ems_plan_slot_wk wk
|
||||
where wk.slot_ord < v_first_neg_sell_ord
|
||||
and wk.sell_price >= 0
|
||||
order by wk.sell_price desc, wk.slot_ord
|
||||
limit 1;
|
||||
|
||||
if v_pre_neg_peak_sell_ord is not null then
|
||||
update _ems_plan_slot_wk wk
|
||||
set allow_discharge_export = true
|
||||
where wk.slot_ord = v_pre_neg_peak_sell_ord;
|
||||
end if;
|
||||
end if;
|
||||
|
||||
-- Vážená acquisition cena zásoby (grid + FVE opportunity) jen pro sloty PŘED prvním
|
||||
-- plánovaným exportem z baterie — nepočítá nákup po večerním/nočním vybití do sítě.
|
||||
select min(wk.interval_start)
|
||||
|
||||
Reference in New Issue
Block a user