puldenni sltovoani , zruseni omemzeni na zakaz exportu pri zapornem sellu, hlubsi vybijeni ped zaporbnym nakupem
This commit is contained in:
@@ -36,6 +36,11 @@ begin
|
||||
'arb_floor_wh', (ab.reserve_soc_percent / 100.0 * ab.usable_capacity_wh)::numeric,
|
||||
'reserve_soc_wh', (ab.reserve_soc_percent / 100.0 * ab.usable_capacity_wh)::numeric,
|
||||
'soc_max_wh', (ab.max_soc_percent / 100.0 * ab.usable_capacity_wh)::numeric,
|
||||
'planner_soc_max_wh', (
|
||||
coalesce(ab.planner_max_soc_percent, ab.max_soc_percent) / 100.0 * ab.usable_capacity_wh
|
||||
)::numeric,
|
||||
'planner_extreme_buy_threshold_czk_kwh', coalesce(ab.planner_extreme_buy_threshold_czk_kwh, -5.0),
|
||||
'planner_discharge_floor_percent', ab.planner_discharge_floor_percent,
|
||||
'charge_efficiency', ab.charge_efficiency,
|
||||
'discharge_efficiency', ab.discharge_efficiency,
|
||||
'degradation_cost_czk_kwh', ab.degradation_cost_czk_kwh,
|
||||
|
||||
@@ -41,6 +41,12 @@ declare
|
||||
v_discharge_target_wh numeric;
|
||||
v_cum numeric;
|
||||
r_slot record;
|
||||
v_n_am int;
|
||||
v_n_pm int;
|
||||
v_chg_am_wh numeric;
|
||||
v_chg_pm_wh numeric;
|
||||
v_dis_am_wh numeric;
|
||||
v_dis_pm_wh numeric;
|
||||
begin
|
||||
drop table if exists _ems_plan_slot_wk;
|
||||
create temp table _ems_plan_slot_wk on commit drop as
|
||||
@@ -252,7 +258,7 @@ begin
|
||||
coalesce(ab.discharge_slot_buffer, 0::numeric),
|
||||
ab.usable_capacity_wh::numeric,
|
||||
(ab.min_soc_percent / 100.0 * ab.usable_capacity_wh)::numeric,
|
||||
(ab.max_soc_percent / 100.0 * ab.usable_capacity_wh)::numeric,
|
||||
(coalesce(ab.planner_max_soc_percent, ab.max_soc_percent) / 100.0 * ab.usable_capacity_wh)::numeric,
|
||||
greatest(coalesce(ab.charge_efficiency, 1::numeric), 0.0001::numeric),
|
||||
least(
|
||||
coalesce(ai.max_battery_charge_w, ai.max_charge_power_w),
|
||||
@@ -302,6 +308,40 @@ begin
|
||||
v_grid_target_wh := v_energy_to_fill * v_charge_buf;
|
||||
v_discharge_target_wh := v_exportable * v_discharge_buf;
|
||||
|
||||
-- Rozpočet na půl dne (Europe/Prague): 00:00–12:00 vs 12:00–24:00; chybějící segment dostane celý budget.
|
||||
select
|
||||
coalesce(
|
||||
count(*) filter (
|
||||
where extract(hour from wk.interval_start at time zone 'Europe/Prague') < 12
|
||||
),
|
||||
0
|
||||
)::int,
|
||||
coalesce(
|
||||
count(*) filter (
|
||||
where extract(hour from wk.interval_start at time zone 'Europe/Prague') >= 12
|
||||
),
|
||||
0
|
||||
)::int
|
||||
into v_n_am, v_n_pm
|
||||
from _ems_plan_slot_wk wk;
|
||||
|
||||
if v_n_am <= 0 then
|
||||
v_chg_am_wh := 0;
|
||||
v_chg_pm_wh := v_grid_target_wh;
|
||||
v_dis_am_wh := 0;
|
||||
v_dis_pm_wh := v_discharge_target_wh;
|
||||
elsif v_n_pm <= 0 then
|
||||
v_chg_am_wh := v_grid_target_wh;
|
||||
v_chg_pm_wh := 0;
|
||||
v_dis_am_wh := v_discharge_target_wh;
|
||||
v_dis_pm_wh := 0;
|
||||
else
|
||||
v_chg_am_wh := v_grid_target_wh / 2.0;
|
||||
v_chg_pm_wh := v_grid_target_wh - v_chg_am_wh;
|
||||
v_dis_am_wh := v_discharge_target_wh / 2.0;
|
||||
v_dis_pm_wh := v_discharge_target_wh - v_dis_am_wh;
|
||||
end if;
|
||||
|
||||
-- charge mask (sloupce temp tabulky kvalifikujeme: RETURNS TABLE dělá PL proměnné stejných jmen)
|
||||
if v_charge_buf <= 0 then
|
||||
update _ems_plan_slot_wk wk set allow_charge = true;
|
||||
@@ -314,9 +354,23 @@ begin
|
||||
select wk.slot_ord
|
||||
from _ems_plan_slot_wk wk
|
||||
where wk.pv_surplus_w <= 0
|
||||
and extract(hour from wk.interval_start at time zone 'Europe/Prague') < 12
|
||||
order by wk.buy_price, wk.slot_ord
|
||||
loop
|
||||
exit when v_cum >= v_grid_target_wh;
|
||||
exit when v_cum >= v_chg_am_wh;
|
||||
exit when v_per_slot_charge_wh <= 0;
|
||||
update _ems_plan_slot_wk wk set allow_charge = true where wk.slot_ord = r_slot.slot_ord;
|
||||
v_cum := v_cum + v_per_slot_charge_wh;
|
||||
end loop;
|
||||
v_cum := 0;
|
||||
for r_slot in
|
||||
select wk.slot_ord
|
||||
from _ems_plan_slot_wk wk
|
||||
where wk.pv_surplus_w <= 0
|
||||
and extract(hour from wk.interval_start at time zone 'Europe/Prague') >= 12
|
||||
order by wk.buy_price, wk.slot_ord
|
||||
loop
|
||||
exit when v_cum >= v_chg_pm_wh;
|
||||
exit when v_per_slot_charge_wh <= 0;
|
||||
update _ems_plan_slot_wk wk set allow_charge = true where wk.slot_ord = r_slot.slot_ord;
|
||||
v_cum := v_cum + v_per_slot_charge_wh;
|
||||
@@ -334,9 +388,22 @@ begin
|
||||
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 wk.sell_price desc, wk.slot_ord desc
|
||||
loop
|
||||
exit when v_cum >= v_discharge_target_wh;
|
||||
exit when v_cum >= v_dis_am_wh;
|
||||
exit when v_per_slot_discharge_wh <= 0;
|
||||
update _ems_plan_slot_wk wk set allow_discharge_export = true where wk.slot_ord = r_slot.slot_ord;
|
||||
v_cum := v_cum + v_per_slot_discharge_wh;
|
||||
end loop;
|
||||
v_cum := 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 wk.sell_price desc, wk.slot_ord desc
|
||||
loop
|
||||
exit when v_cum >= v_dis_pm_wh;
|
||||
exit when v_per_slot_discharge_wh <= 0;
|
||||
update _ems_plan_slot_wk wk set allow_discharge_export = true where wk.slot_ord = r_slot.slot_ord;
|
||||
v_cum := v_cum + v_per_slot_discharge_wh;
|
||||
@@ -363,4 +430,6 @@ end;
|
||||
$fn$;
|
||||
|
||||
comment on function ems.fn_load_planning_slots_full(int, timestamptz, timestamptz, numeric) is
|
||||
'15min sloty s cenami, forecastem, baseline a maskami proti mikro-cyklu (charge/discharge-export).';
|
||||
'15min sloty s cenami, forecastem, baseline a maskami proti mikro-cyklu (charge/discharge-export). '
|
||||
'Masky charge/discharge-export se berou zvlášť pro 00–12 a 12–24 Europe/Prague (polovina budgetu na segment). '
|
||||
'Strop SoC pro výpočet energie k dobití: coalesce(planner_max_soc_percent, max_soc_percent).';
|
||||
|
||||
Reference in New Issue
Block a user