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

This commit is contained in:
Dusan Vojacek
2026-05-29 23:24:03 +02:00
parent b73c3323e1
commit 308c24f029
5 changed files with 288 additions and 30 deletions

View File

@@ -874,6 +874,37 @@ begin
end if;
end loop;
-- v43: levný grid před prvním sell<0, když tentýž den večer (≥17h) dává arbitráž buy→sell.
update _ems_plan_slot_wk wk
set allow_charge = true,
allow_grid_charge = true,
grid_charge_suppressed_reason = coalesce(
wk.grid_charge_suppressed_reason,
'evening_arbitrage_unlock'
)
from (
select
(wk2.interval_start at time zone 'Europe/Prague')::date as plan_date,
max(wk2.sell_price) filter (
where extract(hour from wk2.interval_start at time zone 'Europe/Prague')
>= v_evening_peak_start_hour
and wk2.sell_price > 0
) as evening_peak_sell
from _ems_plan_slot_wk wk2
group by 1
) ep
where (wk.interval_start at time zone 'Europe/Prague')::date = ep.plan_date
and ep.evening_peak_sell is not null
and ep.evening_peak_sell > v_degrad_czk_kwh + 0.05
and wk.buy_price >= 0
and wk.buy_price + v_degrad_czk_kwh < ep.evening_peak_sell
and extract(hour from wk.interval_start at time zone 'Europe/Prague')
< v_evening_peak_start_hour
and (
v_first_neg_sell_ord is null
or wk.slot_ord < v_first_neg_sell_ord
);
-- Ranní pásmo před prvním sell<0 (511 Prague): lokální peak, ne půlnoc celého dne.
if v_first_neg_sell_ord is not null
and v_first_neg_prague_date is not null