dalsi uprava vypoctu delty (ignorujeme orezane vyroby)
Some checks failed
CI and deploy / migration-check (push) Failing after 17s
CI and deploy / deploy (push) Has been skipped

This commit is contained in:
Dusan Vojacek
2026-04-22 22:42:12 +02:00
parent 568b584748
commit 1dfab8c7a1
11 changed files with 174 additions and 12 deletions

View File

@@ -27,16 +27,16 @@ BEGIN
/ 3600.0, 2
) AS lead_time_hours,
CASE
WHEN v.is_curtailed_learning_slot THEN NULL
WHEN v.exclude_actual_for_learning THEN NULL
ELSE slot.avg_actual_w::INT
END AS actual_power_w,
now() AS actual_filled_at,
CASE
WHEN v.is_curtailed_learning_slot THEN NULL
WHEN v.exclude_actual_for_learning THEN NULL
ELSE fpi.power_w - COALESCE(slot.avg_actual_w::INT, 0)
END AS error_w,
CASE
WHEN v.is_curtailed_learning_slot THEN NULL
WHEN v.exclude_actual_for_learning THEN NULL
WHEN slot.avg_actual_w IS NOT NULL
AND slot.avg_actual_w > 0
THEN ROUND(
@@ -85,21 +85,34 @@ BEGIN
AND l.new_state IS FALSE
)
)
) AS is_curtailed_learning_slot
) AS is_curtailed_learning_slot,
EXISTS (
SELECT 1
FROM ems.telemetry_inverter ti_d
WHERE ti_d.site_id = fpr.site_id
AND ti_d.measured_at >= fpi.interval_start
AND ti_d.measured_at < fpi.interval_start + INTERVAL '15 minutes'
AND (
coalesce(ti_d.is_export_limited, false) IS TRUE
OR (ti_d.pv_derating_flags IS NOT NULL AND ti_d.pv_derating_flags <> 0)
)
) AS is_telemetry_derated_slot
) flags ON true
LEFT JOIN LATERAL (
SELECT
CASE
WHEN flags.before_learn_cutoff THEN false
WHEN flags.is_curtailed_learning_slot THEN false
WHEN flags.is_telemetry_derated_slot THEN false
ELSE true
END AS learning_eligible,
CASE
WHEN flags.before_learn_cutoff THEN 'before_delta_learn_min'
WHEN flags.is_telemetry_derated_slot THEN 'telemetry_derating'
WHEN flags.is_curtailed_learning_slot THEN 'curtailment_or_export_cutoff'
ELSE NULL
END AS learning_exclude_reason,
flags.is_curtailed_learning_slot
(flags.is_curtailed_learning_slot OR flags.is_telemetry_derated_slot) AS exclude_actual_for_learning
) v ON true
LEFT JOIN LATERAL (
SELECT AVG(
@@ -133,7 +146,8 @@ $$;
COMMENT ON FUNCTION ems.fn_fill_forecast_accuracy(INT, INT) IS
'Doplní skutečné hodnoty výroby do forecast_accuracy z telemetrie.
learning_eligible / learning_exclude_reason: před delta_learn_min_ts (kalibrace site) se nepočítá do učení delty;
po pv_curtailment_policy_effective_from sloty s curtailment / gen cutoff / cutoff_switch_log (export off) mají NULL actual a jsou vyloučeny z učení.
po pv_curtailment_policy_effective_from sloty s curtailment / gen cutoff / cutoff_switch_log (export off) mají NULL actual a jsou vyloučeny z učení;
telemetrie: is_export_limited nebo pv_derating_flags <> 0 v okně slotu → stejné vyloučení (telemetry_derating).
Volat každých 15 minut (spolu s audit_filler) pro inkrementální plnění.
p_lookback_hours: kolik hodin zpět zpracovat (default 48h pro catch-up).
Pro první backfill: SELECT ems.fn_fill_forecast_accuracy(2, 8760) -- 1 rok';

View File

@@ -234,6 +234,12 @@ as $fn$
),
'[]'::jsonb
),
'pv_forecast_calibration',
(
select to_jsonb(c.*)
from ems.site_pv_forecast_calibration c
where c.site_id = p_site_id
),
'operational',
jsonb_build_object(
'heartbeat_last_seen',