pry oprava uplne chybneho rizeni (prodaval za levneji nez nakoupil)
Some checks failed
CI and deploy / migration-check (push) Failing after 11s
CI and deploy / deploy (push) Has been skipped

This commit is contained in:
Dusan Vojacek
2026-05-16 15:39:07 +02:00
parent 7490ac3d70
commit 1426c0e153
4 changed files with 114 additions and 22 deletions

View File

@@ -60,6 +60,7 @@ declare
v_reserve_wh numeric;
v_daytime_en boolean;
v_night_buf_pct numeric;
v_degrad_czk_kwh numeric;
begin
drop table if exists _ems_plan_slot_wk;
create temp table _ems_plan_slot_wk on commit drop as
@@ -199,7 +200,8 @@ begin
greatest(coalesce(ab.discharge_efficiency, 1::numeric), 0.0001::numeric),
(ab.reserve_soc_percent / 100.0 * ab.usable_capacity_wh)::numeric,
coalesce(ab.planner_daytime_charge_target_enabled, true),
coalesce(ab.planner_night_baseload_buffer_percent, 20::numeric)
coalesce(ab.planner_night_baseload_buffer_percent, 20::numeric),
coalesce(ab.degradation_cost_czk_kwh, 0.15::numeric)
into
v_charge_buf,
v_discharge_buf,
@@ -212,7 +214,8 @@ begin
v_discharge_eff,
v_reserve_wh,
v_daytime_en,
v_night_buf_pct
v_night_buf_pct,
v_degrad_czk_kwh
from ems.asset_battery ab
join ems.asset_inverter ai on ai.id = ab.inverter_id and ai.site_id = ab.site_id
where ab.site_id = p_site_id
@@ -331,6 +334,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
order by wk.sell_price desc, wk.slot_ord desc
loop
exit when v_cum >= v_discharge_target_wh;