dalsi rozvolneni at vic jedeme arbitraz
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-21 14:54:46 +02:00
parent 3b4d54dcc7
commit 66834ddfa6
3 changed files with 51 additions and 17 deletions

View File

@@ -83,7 +83,9 @@ declare
v_est_grid_cost numeric;
v_est_pv_cost numeric;
v_export_window_start timestamptz;
v_plan_day_prague date;
begin
v_plan_day_prague := (p_from at time zone 'Europe/Prague')::date;
drop table if exists _ems_plan_slot_wk;
create temp table _ems_plan_slot_wk on commit drop as
with
@@ -289,12 +291,17 @@ begin
from _ems_plan_slot_wk wk
where extract(hour from wk.interval_start at time zone 'Europe/Prague') >= 12;
-- První výkupní okno v horizontu (stejná logika jako discharge maska) — grid nabíje
-- před tím má prioritu (dnes PM levně → dnes večer prodáš), ne nejlevnější slot zítra.
-- První výkupní okno: sell nad min(buy) **téhož kalendářního dne** (Prague), ne globál
-- min(buy) zítra (NT) — jinak okno začne už ~15:30 a dnešní PM grid dostane 1 slot.
select min(wk.interval_start)
into v_export_window_start
from _ems_plan_slot_wk wk
where wk.sell_price > v_ref_buy_czk_kwh + v_degrad_czk_kwh;
where wk.sell_price > (
select coalesce(min(w2.buy_price), wk.buy_price) + v_degrad_czk_kwh
from _ems_plan_slot_wk w2
where (w2.interval_start at time zone 'Europe/Prague')::date
= (wk.interval_start at time zone 'Europe/Prague')::date
);
-- Lookahead min buy (VT→NT) a store_score pro vrstvu A.
alter table _ems_plan_slot_wk
@@ -399,6 +406,11 @@ begin
or wk.buy_price <= wk.buy_min_next_n + v_buy_lookahead_eps
)
order by
case
when (wk.interval_start at time zone 'Europe/Prague')::date = v_plan_day_prague
then 0
else 1
end,
case
when v_export_window_start is not null
and wk.interval_start < v_export_window_start
@@ -433,6 +445,11 @@ begin
or wk.buy_price <= wk.buy_min_next_n + v_buy_lookahead_eps
)
order by
case
when (wk.interval_start at time zone 'Europe/Prague')::date = v_plan_day_prague
then 0
else 1
end,
case
when v_export_window_start is not null
and wk.interval_start < v_export_window_start