dalsi fix - chtel drzet baterii prakticky porad a neprodat ani nejeet passive mode
Some checks failed
CI and deploy / migration-check (push) Failing after 12s
CI and deploy / deploy (push) Has been skipped

This commit is contained in:
Dusan Vojacek
2026-05-16 15:52:14 +02:00
parent 1426c0e153
commit a17c22d475
3 changed files with 115 additions and 14 deletions

View File

@@ -61,6 +61,7 @@ declare
v_daytime_en boolean;
v_night_buf_pct numeric;
v_degrad_czk_kwh numeric;
v_ref_buy_czk_kwh numeric;
begin
drop table if exists _ems_plan_slot_wk;
create temp table _ems_plan_slot_wk on commit drop as
@@ -323,6 +324,17 @@ begin
end loop;
end if;
-- Referenční nákup pro arbitráž exportu: nejlevnější buy mezi sloty, kde lze nabíjet
-- (ne buy ve stejném slotu — střídač nekupuje a neprodává současně).
select coalesce(
min(wk.buy_price) filter (where wk.allow_charge),
min(wk.buy_price)
)
into v_ref_buy_czk_kwh
from _ems_plan_slot_wk wk;
v_ref_buy_czk_kwh := coalesce(v_ref_buy_czk_kwh, 0);
-- discharge-export mask
if v_discharge_buf <= 0 then
update _ems_plan_slot_wk wk set allow_discharge_export = true;
@@ -334,7 +346,7 @@ begin
for r_slot in
select wk.slot_ord
from _ems_plan_slot_wk wk
where wk.sell_price > wk.buy_price + v_degrad_czk_kwh
where wk.sell_price > v_ref_buy_czk_kwh + v_degrad_czk_kwh
order by wk.sell_price desc, wk.slot_ord desc
loop
exit when v_cum >= v_discharge_target_wh;