CREATE OR REPLACE VIEW ems.vw_baseline_load_forecast_accuracy_daily AS
SELECT
    site_id,
    date_trunc('day', interval_start AT TIME ZONE 'Europe/Prague') AS day_prague,
    COUNT(*) AS slot_count,
    AVG(ABS(error_w))::NUMERIC(12,2) AS mae_w,
    AVG(error_pct) FILTER (WHERE error_pct IS NOT NULL)::NUMERIC(8,4) AS avg_error_pct
FROM ems.baseline_load_forecast_accuracy
GROUP BY site_id, date_trunc('day', interval_start AT TIME ZONE 'Europe/Prague');

COMMENT ON VIEW ems.vw_baseline_load_forecast_accuracy_daily IS
'Denní souhrn přesnosti predikce bazální spotřeby (|chyba| v průměru W).';
