dalsi a dalsi oprava
This commit is contained in:
@@ -304,24 +304,33 @@ begin
|
||||
from _ems_plan_slot_wk wk
|
||||
where extract(hour from wk.interval_start at time zone 'Europe/Prague') >= 12;
|
||||
|
||||
-- První výkupní okno: sell nad min(buy) **téhož kalendářního dne** (Prague), ne globální
|
||||
-- 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 > (
|
||||
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
|
||||
add column if not exists future_sell_lookahead numeric,
|
||||
add column if not exists buy_min_next_n numeric,
|
||||
add column if not exists store_score numeric,
|
||||
add column if not exists allow_grid_charge boolean default false;
|
||||
add column if not exists allow_grid_charge boolean default false,
|
||||
add column if not exists export_window_start_at timestamptz;
|
||||
|
||||
-- První výkupní okno **per kalendářní den** (Prague). Globální min přes dny by
|
||||
-- zablokoval NT grid nabíjení (včerejší večerní peak → dnešní 00–06 už „po okně“).
|
||||
update _ems_plan_slot_wk wk
|
||||
set export_window_start_at = (
|
||||
select min(wx.interval_start)
|
||||
from _ems_plan_slot_wk wx
|
||||
where (wx.interval_start at time zone 'Europe/Prague')::date
|
||||
= (wk.interval_start at time zone 'Europe/Prague')::date
|
||||
and wx.sell_price > (
|
||||
select coalesce(min(w2.buy_price), wx.buy_price) + v_degrad_czk_kwh
|
||||
from _ems_plan_slot_wk w2
|
||||
where (w2.interval_start at time zone 'Europe/Prague')::date
|
||||
= (wx.interval_start at time zone 'Europe/Prague')::date
|
||||
)
|
||||
);
|
||||
|
||||
select min(wk.export_window_start_at)
|
||||
into v_export_window_start
|
||||
from _ems_plan_slot_wk wk;
|
||||
|
||||
update _ems_plan_slot_wk wk
|
||||
set
|
||||
@@ -339,8 +348,8 @@ begin
|
||||
where w2.slot_ord > wk.slot_ord
|
||||
and w2.slot_ord <= wk.slot_ord + v_lookahead_slots
|
||||
and (
|
||||
v_export_window_start is null
|
||||
or w2.interval_start < v_export_window_start
|
||||
wk.export_window_start_at is null
|
||||
or w2.interval_start < wk.export_window_start_at
|
||||
)
|
||||
),
|
||||
store_score =
|
||||
@@ -431,8 +440,8 @@ begin
|
||||
else 1
|
||||
end,
|
||||
case
|
||||
when v_export_window_start is not null
|
||||
and wk.interval_start < v_export_window_start
|
||||
when wk.export_window_start_at is not null
|
||||
and wk.interval_start < wk.export_window_start_at
|
||||
then 0
|
||||
else 1
|
||||
end,
|
||||
@@ -479,8 +488,8 @@ begin
|
||||
else 1
|
||||
end,
|
||||
case
|
||||
when v_export_window_start is not null
|
||||
and wk.interval_start < v_export_window_start
|
||||
when wk.export_window_start_at is not null
|
||||
and wk.interval_start < wk.export_window_start_at
|
||||
then 0
|
||||
else 1
|
||||
end,
|
||||
@@ -522,8 +531,8 @@ begin
|
||||
else 1
|
||||
end,
|
||||
case
|
||||
when v_export_window_start is not null
|
||||
and wk.interval_start < v_export_window_start
|
||||
when wk.export_window_start_at is not null
|
||||
and wk.interval_start < wk.export_window_start_at
|
||||
then 0
|
||||
else 1
|
||||
end,
|
||||
@@ -567,8 +576,8 @@ begin
|
||||
else 1
|
||||
end,
|
||||
case
|
||||
when v_export_window_start is not null
|
||||
and wk.interval_start < v_export_window_start
|
||||
when wk.export_window_start_at is not null
|
||||
and wk.interval_start < wk.export_window_start_at
|
||||
then 0
|
||||
else 1
|
||||
end,
|
||||
|
||||
Reference in New Issue
Block a user