fix(strommix): discard SMARD snapshot when aligned timestamp >90 min stale
When SMARD's load filter (id 410) lags 12+ hours, the aligned-min strategy in fetchSmardSnapshot produces a snapshot stamped with that 12-hour-old timestamp — and the widget surfaces it as the live "Stand HH:MM" header. With Energy-Charts already returning fresher numbers through the CMS path, falling back entirely is the right move. Threshold is 90 min: tight enough to catch obvious lag, loose enough to keep normal 30–60 min SMARD delay as the canonical source.
This commit is contained in:
@@ -127,7 +127,7 @@ async function fetchPriceAtNow(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const GET: RequestHandler = async ({ fetch }) => {
|
export const GET: RequestHandler = async ({ fetch }) => {
|
||||||
const [smard, energyCharts, cross, priceDe, priceFr] = await Promise.all([
|
const [smardRaw, energyCharts, cross, priceDe, priceFr] = await Promise.all([
|
||||||
fetchSmardSnapshot(fetch),
|
fetchSmardSnapshot(fetch),
|
||||||
// Energy-Charts via the CMS — used as per-field fallback when SMARD
|
// Energy-Charts via the CMS — used as per-field fallback when SMARD
|
||||||
// returns null for a specific filter (notably load 410 when SMARD's
|
// returns null for a specific filter (notably load 410 when SMARD's
|
||||||
@@ -138,6 +138,17 @@ export const GET: RequestHandler = async ({ fetch }) => {
|
|||||||
fetchPriceAtNow("FR", fetch),
|
fetchPriceAtNow("FR", fetch),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
// SMARD aligned-min picks the earliest "latest" across filters. If
|
||||||
|
// one filter (typically load 410) lags 12+ hours, the snapshot ends
|
||||||
|
// up labelled with a stale timestamp like "12:15 Uhr morgens" while
|
||||||
|
// newer Energy-Charts data is right there. Discard the SMARD snapshot
|
||||||
|
// when it is older than 90 min so the aggregator falls back to
|
||||||
|
// Energy-Charts entirely. 90 min lets typical 30–60 min SMARD lag
|
||||||
|
// still win.
|
||||||
|
const nowSec = Math.floor(Date.now() / 1000);
|
||||||
|
const smard =
|
||||||
|
smardRaw && nowSec - smardRaw.measuredAtUnix < 90 * 60 ? smardRaw : null;
|
||||||
|
|
||||||
const ec = energyCharts.data ?? {};
|
const ec = energyCharts.data ?? {};
|
||||||
|
|
||||||
// Per-field fallback. SMARD value `null` = filter unavailable; we
|
// Per-field fallback. SMARD value `null` = filter unavailable; we
|
||||||
|
|||||||
Reference in New Issue
Block a user