fix graf v sql
This commit is contained in:
@@ -101,8 +101,11 @@ AS $$
|
|||||||
cbs.avg_power_w + 0.5 * COALESCE(cbs.stddev_power_w, 100),
|
cbs.avg_power_w + 0.5 * COALESCE(cbs.stddev_power_w, 100),
|
||||||
550
|
550
|
||||||
)::INT AS confidence_w
|
)::INT AS confidence_w
|
||||||
FROM generate_series(p_from, p_to - INTERVAL '15 minutes',
|
FROM generate_series(
|
||||||
INTERVAL '15 minutes') AS gs(slot)
|
date_bin(interval '15 minutes', p_from, timestamptz '1970-01-01T00:00:00Z'),
|
||||||
|
date_bin(interval '15 minutes', p_to, timestamptz '1970-01-01T00:00:00Z') - interval '15 minutes',
|
||||||
|
interval '15 minutes'
|
||||||
|
) AS gs(slot)
|
||||||
LEFT JOIN ems.consumption_baseline_stats cbs
|
LEFT JOIN ems.consumption_baseline_stats cbs
|
||||||
ON cbs.site_id = p_site_id
|
ON cbs.site_id = p_site_id
|
||||||
AND cbs.day_of_week = EXTRACT(DOW FROM gs.slot AT TIME ZONE 'Europe/Prague')::INT
|
AND cbs.day_of_week = EXTRACT(DOW FROM gs.slot AT TIME ZONE 'Europe/Prague')::INT
|
||||||
|
|||||||
@@ -11,11 +11,11 @@ stable
|
|||||||
as $fn$
|
as $fn$
|
||||||
with bounds as (
|
with bounds as (
|
||||||
select
|
select
|
||||||
p_from as ts_from,
|
date_bin(interval '15 minutes', p_from, timestamptz '1970-01-01T00:00:00Z') as ts_from,
|
||||||
case
|
case
|
||||||
when p_to <= p_from then p_from + interval '15 minutes'
|
when p_to <= p_from then date_bin(interval '15 minutes', p_from, timestamptz '1970-01-01T00:00:00Z') + interval '15 minutes'
|
||||||
when p_to > p_from + interval '60 days' then p_from + interval '60 days'
|
when p_to > p_from + interval '60 days' then date_bin(interval '15 minutes', p_from, timestamptz '1970-01-01T00:00:00Z') + interval '60 days'
|
||||||
else p_to
|
else date_bin(interval '15 minutes', p_to, timestamptz '1970-01-01T00:00:00Z')
|
||||||
end as ts_to
|
end as ts_to
|
||||||
),
|
),
|
||||||
slot_spine as (
|
slot_spine as (
|
||||||
|
|||||||
@@ -23,11 +23,11 @@ as $fn$
|
|||||||
),
|
),
|
||||||
bounds as (
|
bounds as (
|
||||||
select
|
select
|
||||||
p_from as ts_from,
|
date_bin(interval '15 minutes', p_from, timestamptz '1970-01-01T00:00:00Z') as ts_from,
|
||||||
case
|
case
|
||||||
when p_to <= p_from then p_from + interval '15 minutes'
|
when p_to <= p_from then date_bin(interval '15 minutes', p_from, timestamptz '1970-01-01T00:00:00Z') + interval '15 minutes'
|
||||||
when p_to > p_from + interval '60 days' then p_from + interval '60 days'
|
when p_to > p_from + interval '60 days' then date_bin(interval '15 minutes', p_from, timestamptz '1970-01-01T00:00:00Z') + interval '60 days'
|
||||||
else p_to
|
else date_bin(interval '15 minutes', p_to, timestamptz '1970-01-01T00:00:00Z')
|
||||||
end as ts_to
|
end as ts_to
|
||||||
),
|
),
|
||||||
slot_spine as (
|
slot_spine as (
|
||||||
|
|||||||
@@ -84,17 +84,19 @@ function DayChart({
|
|||||||
strokeWidth={2}
|
strokeWidth={2}
|
||||||
dot={false}
|
dot={false}
|
||||||
connectNulls
|
connectNulls
|
||||||
|
isAnimationActive={false}
|
||||||
/>
|
/>
|
||||||
{showForecast ? (
|
{showForecast ? (
|
||||||
<Line
|
<Line
|
||||||
type="monotone"
|
type="monotone"
|
||||||
dataKey="forecast_kw"
|
dataKey="forecast_kw"
|
||||||
name="Předpověď"
|
name="Předpověď"
|
||||||
stroke="#ef9f27"
|
stroke="#fbbf24"
|
||||||
strokeWidth={1.5}
|
strokeWidth={1.5}
|
||||||
dot={false}
|
dot={false}
|
||||||
connectNulls
|
connectNulls
|
||||||
strokeDasharray="5 4"
|
strokeDasharray="5 4"
|
||||||
|
isAnimationActive={false}
|
||||||
/>
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
{showCorrected ? (
|
{showCorrected ? (
|
||||||
@@ -102,11 +104,12 @@ function DayChart({
|
|||||||
type="monotone"
|
type="monotone"
|
||||||
dataKey="corrected_kw"
|
dataKey="corrected_kw"
|
||||||
name="Korigovaná"
|
name="Korigovaná"
|
||||||
stroke="#ef9f27"
|
stroke="#fde68a"
|
||||||
strokeWidth={1.5}
|
strokeWidth={1.5}
|
||||||
dot={false}
|
dot={false}
|
||||||
connectNulls
|
connectNulls
|
||||||
strokeDasharray="2 3"
|
strokeDasharray="2 3"
|
||||||
|
isAnimationActive={false}
|
||||||
/>
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
</LineChart>
|
</LineChart>
|
||||||
@@ -167,9 +170,15 @@ export default function ForecastVsActual() {
|
|||||||
|
|
||||||
const byInterval = useMemo(() => {
|
const byInterval = useMemo(() => {
|
||||||
const map = new Map<string, { tel?: Telemetry15mRow; pv?: ForecastPvSlotCorrectedRow; base?: BaselineLoadSlotRow }>()
|
const map = new Map<string, { tel?: Telemetry15mRow; pv?: ForecastPvSlotCorrectedRow; base?: BaselineLoadSlotRow }>()
|
||||||
for (const r of telemetry) map.set(r.slot_start, { ...(map.get(r.slot_start) ?? {}), tel: r })
|
for (const r of telemetry) {
|
||||||
for (const r of pvSlots) map.set(r.interval_start, { ...(map.get(r.interval_start) ?? {}), pv: r })
|
map.set(r.slot_start, { ...(map.get(r.slot_start) ?? {}), tel: r })
|
||||||
for (const r of baselineSlots) map.set(r.interval_start, { ...(map.get(r.interval_start) ?? {}), base: r })
|
}
|
||||||
|
for (const r of pvSlots) {
|
||||||
|
map.set(r.interval_start, { ...(map.get(r.interval_start) ?? {}), pv: r })
|
||||||
|
}
|
||||||
|
for (const r of baselineSlots) {
|
||||||
|
map.set(r.interval_start, { ...(map.get(r.interval_start) ?? {}), base: r })
|
||||||
|
}
|
||||||
return map
|
return map
|
||||||
}, [telemetry, pvSlots, baselineSlots])
|
}, [telemetry, pvSlots, baselineSlots])
|
||||||
|
|
||||||
@@ -211,8 +220,11 @@ export default function ForecastVsActual() {
|
|||||||
byDay.set(day, arr)
|
byDay.set(day, arr)
|
||||||
}
|
}
|
||||||
return [...byDay.entries()]
|
return [...byDay.entries()]
|
||||||
.sort((a, b) => a[0].localeCompare(b[0]))
|
.sort((a, b) => b[0].localeCompare(a[0]))
|
||||||
.map(([day, points]) => ({ day, points }))
|
.map(([day, points]) => ({
|
||||||
|
day,
|
||||||
|
points: points.sort((p, q) => new Date(p.k).getTime() - new Date(q.k).getTime()),
|
||||||
|
}))
|
||||||
}, [byInterval, metric])
|
}, [byInterval, metric])
|
||||||
|
|
||||||
const title = metric === 'pv' ? 'FVE (výroba)' : metric === 'load' ? 'Spotřeba (bazál)' : 'Síť (signed)'
|
const title = metric === 'pv' ? 'FVE (výroba)' : metric === 'load' ? 'Spotřeba (bazál)' : 'Síť (signed)'
|
||||||
@@ -270,6 +282,15 @@ export default function ForecastVsActual() {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{siteReady && siteId != null ? (
|
||||||
|
<p className="text-xs text-slate-500">
|
||||||
|
Legenda: <span className="text-slate-200">plná šedá</span> = skutečnost z telemetrie (15m CA),{' '}
|
||||||
|
<span className="text-amber-200">čárkovaná žlutá</span> = předpověď (FVE: Open‑Meteo/pvlib; spotřeba: baseline
|
||||||
|
z historie), <span className="text-yellow-100">tečkovaná světlá</span> = korigovaná FVE (delta profil z historie).
|
||||||
|
U sítě zatím nemáme samostatnou „předpověď“ řady (jen skutečnost).
|
||||||
|
</p>
|
||||||
|
) : null}
|
||||||
|
|
||||||
{error ? (
|
{error ? (
|
||||||
<div className="rounded-xl border border-red-500/40 bg-red-950/40 px-4 py-3 text-sm text-red-200" role="alert">
|
<div className="rounded-xl border border-red-500/40 bg-red-950/40 px-4 py-3 text-sm text-red-200" role="alert">
|
||||||
{error}
|
{error}
|
||||||
|
|||||||
Reference in New Issue
Block a user