dalsi oprava
This commit is contained in:
@@ -503,6 +503,88 @@ begin
|
||||
update _ems_plan_slot_wk wk
|
||||
set allow_charge = true, allow_grid_charge = true
|
||||
where wk.buy_price < 0;
|
||||
elsif exists (
|
||||
select 1
|
||||
from _ems_plan_slot_wk w2
|
||||
where w2.sell_price > w2.buy_price + v_degrad_czk_kwh
|
||||
) then
|
||||
-- Fixní nákup (BA81): buy konstantní — grid nabíjení před exportním oknem, AM/PM rozpočet.
|
||||
v_cum := 0;
|
||||
v_grid_slots_am := 0;
|
||||
for r_slot in
|
||||
select wk.slot_ord
|
||||
from _ems_plan_slot_wk wk
|
||||
where extract(hour from wk.interval_start at time zone 'Europe/Prague') < 12
|
||||
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
|
||||
then 0
|
||||
else 1
|
||||
end,
|
||||
wk.is_predicted_price::int,
|
||||
wk.slot_ord
|
||||
loop
|
||||
exit when v_cum >= v_chg_am_wh;
|
||||
exit when v_per_slot_charge_wh <= 0;
|
||||
exit when v_grid_slots_am >= v_grid_charge_cap_am;
|
||||
update _ems_plan_slot_wk wk
|
||||
set allow_charge = true, allow_grid_charge = true
|
||||
where wk.slot_ord = r_slot.slot_ord;
|
||||
v_cum := v_cum + v_per_slot_charge_wh;
|
||||
v_grid_slots_am := v_grid_slots_am + 1;
|
||||
end loop;
|
||||
v_grid_filled_wh := v_grid_filled_wh + v_cum;
|
||||
|
||||
v_chg_pm_wh := greatest(v_chg_pm_wh, v_grid_target_wh - v_grid_filled_wh);
|
||||
if v_per_slot_charge_wh > 0 and v_charge_buf > 0 then
|
||||
v_grid_charge_cap_pm := greatest(
|
||||
v_grid_charge_cap_pm,
|
||||
least(24, ceil((v_chg_pm_wh / v_per_slot_charge_wh) * v_charge_buf)::int)
|
||||
);
|
||||
elsif v_per_slot_charge_wh > 0 then
|
||||
v_grid_charge_cap_pm := greatest(
|
||||
v_grid_charge_cap_pm,
|
||||
least(24, ceil(v_chg_pm_wh / v_per_slot_charge_wh)::int)
|
||||
);
|
||||
end if;
|
||||
|
||||
v_cum := 0;
|
||||
v_grid_slots_pm := 0;
|
||||
for r_slot in
|
||||
select wk.slot_ord
|
||||
from _ems_plan_slot_wk wk
|
||||
where extract(hour from wk.interval_start at time zone 'Europe/Prague') >= 12
|
||||
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
|
||||
then 0
|
||||
else 1
|
||||
end,
|
||||
wk.is_predicted_price::int,
|
||||
wk.slot_ord
|
||||
loop
|
||||
exit when v_cum >= v_chg_pm_wh;
|
||||
exit when v_per_slot_charge_wh <= 0;
|
||||
exit when v_grid_slots_pm >= v_grid_charge_cap_pm;
|
||||
update _ems_plan_slot_wk wk
|
||||
set allow_charge = true, allow_grid_charge = true
|
||||
where wk.slot_ord = r_slot.slot_ord;
|
||||
v_cum := v_cum + v_per_slot_charge_wh;
|
||||
v_grid_slots_pm := v_grid_slots_pm + 1;
|
||||
end loop;
|
||||
v_grid_filled_wh := v_grid_filled_wh + v_cum;
|
||||
end if;
|
||||
|
||||
-- A) PV-surplus: jen zbytek kapacity po grid vrstvě B
|
||||
|
||||
Reference in New Issue
Block a user