Files
ems/db/migration/V072__pv_array_telemetry_group_and_sources.sql
Dusan Vojacek 9d37efb991
Some checks failed
CI and deploy / migration-check (push) Failing after 24s
CI and deploy / deploy (push) Has been skipped
telemetrie per pv_array, fix predictinos
2026-04-29 13:03:41 +02:00

53 lines
2.2 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- =============================================================
-- V072 asset_pv_array.telemetry_group + rozšíření telemetry_source
--
-- Cíl:
-- - umožnit mapování PV pole → měřicí kanál (pv1/pv2/pv_strings/pv_total/gen_port),
-- - umožnit sdílené měření pro více polí (telemetry_group) a následnou alokaci (v routines).
-- =============================================================
alter table ems.asset_pv_array
add column if not exists telemetry_group text;
comment on column ems.asset_pv_array.telemetry_source is
'Který sloupec v telemetry_inverter odpovídá tomuto poli.
gen_port = gen_port_power_w (AC-coupled pole na GEN portu),
pv1 = pv1_power_w (DC string 1 / MPPT1),
pv2 = pv2_power_w (DC string 2 / MPPT2),
pv_strings = pv1_power_w + pv2_power_w (souhrn DC stringů, pokud nejde rozlišit),
pv_total = pv_power_w (souhrnné PV, pokud nejde rozlišit).
NULL = pole nemá přímou telemetrii (fallback na forecast).';
comment on column ems.asset_pv_array.telemetry_group is
'Volitelná skupina pro sdílené měření: pokud více pv_array sdílí jeden telemetrický kanál (např. GEN port rozdělený do více orientací),
pak mají shodné (site_id, telemetry_source, telemetry_group) a routines alokují actual proporčně podle forecastu.';
-- --- Seed / upgrade stávajících referenčních lokalit ---
-- home-01: dvě GEN pole sdílí jeden GEN port → stejné telemetry_group
update ems.asset_pv_array
set telemetry_source = 'gen_port',
telemetry_group = 'gen_port_1'
where site_id = (select id from ems.site where code = 'home-01')
and code in ('pv-b', 'pv-b-flat');
-- BA81: stringy mapujeme na PV1/PV2, mikroinvertory sdílí GEN port (alokace podle forecastu).
update ems.asset_pv_array
set telemetry_source = 'pv1',
telemetry_group = null
where site_id = (select id from ems.site where code = 'BA81')
and code = 'pv-str-1';
update ems.asset_pv_array
set telemetry_source = 'pv2',
telemetry_group = null
where site_id = (select id from ems.site where code = 'BA81')
and code = 'pv-str-2';
update ems.asset_pv_array
set telemetry_source = 'gen_port',
telemetry_group = 'gen_port_1'
where site_id = (select id from ems.site where code = 'BA81')
and code in ('pv-mi-1', 'pv-mi-2');