fix reload pv on dashboard
Some checks failed
CI and deploy / migration-check (push) Failing after 15s
CI and deploy / deploy (push) Has been skipped

This commit is contained in:
Dusan Vojacek
2026-04-27 18:39:13 +02:00
parent 16fc6a065e
commit e4d4fee24d
3 changed files with 45 additions and 56 deletions

View File

@@ -0,0 +1,8 @@
-- =============================================================
-- V067__asset_heat_pump_site_index.sql
-- Zrychlení filtrování asset_heat_pump podle site_id (PostgREST).
-- =============================================================
create index if not exists idx_asset_heat_pump_site
on ems.asset_heat_pump (site_id);

View File

@@ -67,9 +67,9 @@ COMMENT ON VIEW ems.vw_latest_ev_charger IS
CREATE OR REPLACE VIEW ems.vw_latest_heat_pump
WITH (security_invoker = false)
AS
SELECT DISTINCT ON (t.heat_pump_id)
t.site_id,
t.heat_pump_id,
SELECT
hp.site_id,
hp.id AS heat_pump_id,
hp.code AS heat_pump_code,
t.measured_at,
t.outdoor_temp_c,
@@ -81,11 +81,25 @@ SELECT DISTINCT ON (t.heat_pump_id)
t.defrost_active,
t.alarm_code,
-- Odhadovaný COP pro aktuální venkovní teplotu
ems.fn_cop_estimate(t.heat_pump_id, t.outdoor_temp_c) AS cop_estimated,
ems.fn_cop_estimate(hp.id, t.outdoor_temp_c) AS cop_estimated,
now() - t.measured_at AS data_age
FROM ems.telemetry_heat_pump t
JOIN ems.asset_heat_pump hp ON hp.id = t.heat_pump_id
ORDER BY t.heat_pump_id, t.measured_at DESC;
FROM ems.asset_heat_pump hp
LEFT JOIN LATERAL (
SELECT
thp.measured_at,
thp.outdoor_temp_c,
thp.tuv_tank_temp_c,
thp.water_outlet_temp_c,
thp.power_w,
thp.operating_mode,
thp.cop_actual,
thp.defrost_active,
thp.alarm_code
FROM ems.telemetry_heat_pump thp
WHERE thp.heat_pump_id = hp.id
ORDER BY thp.measured_at DESC
LIMIT 1
) t ON true;
COMMENT ON VIEW ems.vw_latest_heat_pump IS
'Nejnovější telemetrická data pro každé tepelné čerpadlo včetně odhadovaného COP.