dalsi pokusy
Some checks failed
CI and deploy / migration-check (push) Failing after 11s
CI and deploy / deploy (push) Has been skipped

This commit is contained in:
Dusan Vojacek
2026-05-23 00:06:30 +02:00
parent 8845350c0b
commit a52be1b792
5 changed files with 119 additions and 12 deletions

View File

@@ -78,7 +78,9 @@ declare
v_grid_slots_pm int := 0;
v_acquisition_cutoff timestamptz;
v_first_neg_sell_ord int;
v_first_neg_prague_date date;
v_pre_neg_peak_sell_ord int;
v_preneg_export_min_soc_wh numeric;
v_max_sell_czk_kwh numeric;
v_charge_acquisition numeric;
v_est_grid_wh numeric;
@@ -518,6 +520,23 @@ begin
end loop;
end if;
-- První záporný výkup v horizontu (od p_from = „budoucí“ sloty od replanu).
-- Peak před ním a acquisition cutoff se vážou na STEJNÝ kalendářní den (Prague),
-- ne na včerejší večer v tomže horizontu.
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.interval_start at time zone 'Europe/Prague')::date
into v_first_neg_prague_date
from _ems_plan_slot_wk wk
where wk.slot_ord = v_first_neg_sell_ord;
end if;
v_preneg_export_min_soc_wh := v_min_soc_wh + greatest(v_per_slot_discharge_wh, 1000::numeric);
-- discharge-export mask
if v_discharge_buf <= 0 then
update _ems_plan_slot_wk wk set allow_discharge_export = true;
@@ -565,18 +584,17 @@ begin
);
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
-- Před prvním sell<0 téhož dne: export v lokálním max kladného sell (např. 07:00, ne včerejší 20:45).
if v_first_neg_sell_ord is not null
and v_first_neg_prague_date is not null
and p_current_soc_wh >= v_preneg_export_min_soc_wh
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
and (wk.interval_start at time zone 'Europe/Prague')::date = v_first_neg_prague_date
order by wk.sell_price desc, wk.slot_ord
limit 1;
@@ -587,12 +605,23 @@ begin
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ě.
-- Acquisition: grid nabíjení před prvním exportem ve STEJNÝ den jako záporné výkupní okno
-- (ne dřívější večerní export v horizontu rolling replanu).
select min(wk.interval_start)
into v_acquisition_cutoff
from _ems_plan_slot_wk wk
where wk.allow_discharge_export;
where wk.allow_discharge_export
and (
v_first_neg_prague_date is null
or (wk.interval_start at time zone 'Europe/Prague')::date = v_first_neg_prague_date
);
if v_acquisition_cutoff is null then
select min(wk.interval_start)
into v_acquisition_cutoff
from _ems_plan_slot_wk wk
where wk.allow_discharge_export;
end if;
-- Acquisition: jen grid vrstva B (ne odpolední FVE z vrstvy A) před 1. exportem.
select