oprava import/export kwh
This commit is contained in:
@@ -3,6 +3,74 @@
|
||||
-- EMS Platform – funkce pro výpočet efektivní ceny per site
|
||||
-- Repeatable migration – nasazuje se při každé změně
|
||||
-- =============================================================
|
||||
-- Pomocné (audit/ekonomika): sjednocení import/export Wh — musí běžet před R__012/R__056.
|
||||
create or replace function ems.fn_audit_grid_import_wh_for_economics(
|
||||
p_import_wh numeric,
|
||||
p_export_wh numeric,
|
||||
p_grid_power_w int
|
||||
)
|
||||
returns numeric
|
||||
language sql
|
||||
stable
|
||||
as $$
|
||||
select case
|
||||
when coalesce(p_import_wh, 0) > 0 and coalesce(p_export_wh, 0) > 0 then
|
||||
coalesce(
|
||||
p_import_wh,
|
||||
greatest(coalesce(p_grid_power_w, 0), 0)::numeric / 4
|
||||
)
|
||||
when coalesce(p_export_wh, 0) = 0 then
|
||||
greatest(
|
||||
coalesce(
|
||||
p_import_wh,
|
||||
greatest(coalesce(p_grid_power_w, 0), 0)::numeric / 4
|
||||
),
|
||||
greatest(coalesce(p_grid_power_w, 0), 0)::numeric / 4
|
||||
)
|
||||
else
|
||||
coalesce(
|
||||
p_import_wh,
|
||||
greatest(coalesce(p_grid_power_w, 0), 0)::numeric / 4
|
||||
)
|
||||
end;
|
||||
$$;
|
||||
|
||||
create or replace function ems.fn_audit_grid_export_wh_for_economics(
|
||||
p_import_wh numeric,
|
||||
p_export_wh numeric,
|
||||
p_grid_power_w int
|
||||
)
|
||||
returns numeric
|
||||
language sql
|
||||
stable
|
||||
as $$
|
||||
select case
|
||||
when coalesce(p_import_wh, 0) > 0 and coalesce(p_export_wh, 0) > 0 then
|
||||
coalesce(
|
||||
p_export_wh,
|
||||
abs(least(coalesce(p_grid_power_w, 0), 0))::numeric / 4
|
||||
)
|
||||
when coalesce(p_import_wh, 0) = 0 then
|
||||
greatest(
|
||||
coalesce(
|
||||
p_export_wh,
|
||||
abs(least(coalesce(p_grid_power_w, 0), 0))::numeric / 4
|
||||
),
|
||||
abs(least(coalesce(p_grid_power_w, 0), 0))::numeric / 4
|
||||
)
|
||||
else
|
||||
coalesce(
|
||||
p_export_wh,
|
||||
abs(least(coalesce(p_grid_power_w, 0), 0))::numeric / 4
|
||||
)
|
||||
end;
|
||||
$$;
|
||||
|
||||
comment on function ems.fn_audit_grid_import_wh_for_economics(numeric, numeric, int) is
|
||||
'Import Wh pro audit/ekonomiku: u čistého importu max(uložený čítač, max(0,P_grid)×¼ h).';
|
||||
|
||||
comment on function ems.fn_audit_grid_export_wh_for_economics(numeric, numeric, int) is
|
||||
'Export Wh pro audit/ekonomiku: u čistého exportu max(uložený čítač, |min(0,P_grid)|×¼ h).';
|
||||
|
||||
CREATE OR REPLACE FUNCTION ems.fn_effective_buy_price(
|
||||
p_site_id INT,
|
||||
|
||||
Reference in New Issue
Block a user