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

This commit is contained in:
Dusan Vojacek
2026-05-25 00:10:58 +02:00
parent b844a9182f
commit 9ba65ea6bb
5 changed files with 170 additions and 8 deletions

View File

@@ -737,6 +737,26 @@ begin
-- A) PV-surplus: jen zbytek kapacity po grid vrstvě B
v_pv_layer_cap_wh := greatest(v_energy_to_fill - v_grid_filled_wh, 0);
-- Rezervace SoC pro sell<0 okno: pokud v zápor. výkup. slotech máme
-- očekávaný PV přebytek X Wh (po efektivitě), snížíme PV vrstvu A o X.
-- Důsledek: do okna nedorazíme „plní" (98 % SoC), zbude prostor přijmout PV
-- z neg-sell slotů místo exportu do mínusu / curtail pole A.
-- Sample neg-sell PV sloty (sell<0 a buy<0, kde sell<buy) jsou vyloučené
-- z hlavního A-loopu (filtr sell >= buy degrad), takže redukce je čistá.
declare
v_neg_window_pv_surplus_wh numeric := 0;
begin
select coalesce(sum(least(wk.pv_surplus_w::numeric, v_max_charge_w) * v_charge_eff * 0.25), 0)
into v_neg_window_pv_surplus_wh
from _ems_plan_slot_wk wk
where wk.sell_price < 0
and wk.pv_surplus_w > 0;
if v_neg_window_pv_surplus_wh > 0 then
v_pv_layer_cap_wh := greatest(v_pv_layer_cap_wh - v_neg_window_pv_surplus_wh, 0);
end if;
end;
v_cum := 0;
for r_slot in
select wk.slot_ord, wk.pv_surplus_w
@@ -999,11 +1019,16 @@ begin
if v_est_grid_wh > 0 then
v_charge_acquisition := v_est_grid_cost / v_est_grid_wh;
elsif v_charge_acquisition is null then
v_charge_acquisition := coalesce(
(v_ref_buy_am_czk_kwh + v_ref_buy_pm_czk_kwh) / 2.0,
v_ref_buy_czk_kwh
);
-- Fallback: nejnizsi positivni buy v horizontu (nikoli avg ref_buy_am/pm,
-- ktery muze byt < 0 kdyz PM zahrnuje zaporne OTE sloty 13-15h).
-- Cena akvizice baterie nikdy nesmi byt < 0 (jinak rozhazuje arbitraz
-- objective + two_pass divergence).
select coalesce(min(wk.buy_price), 0)
into v_charge_acquisition
from _ems_plan_slot_wk wk
where wk.buy_price >= 0;
end if;
v_charge_acquisition := greatest(v_charge_acquisition, 0);
-- v_charge_acquisition z min(grid) zůstane, pokud je jen jeden grid slot před exportem
return query