// open-predico dashboard. Static: draws the JSON that build.py writes to data/. No framework. "use strict"; const DATA = "data/"; const STEP = 900; const MON = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split(" "); const WEEKDAYS = "Mon Tue Wed Thu Fri Sat Sun".split(" "); const LABEL = { energy: "Energy", price: "Price", wind: "Wind", solar: "Solar", solar_be: "Solar" }; const cache = {}; const json = p => (cache[p] ??= fetch(DATA + p).then(r => { if (!r.ok) throw new Error(`${p}: HTTP ${r.status}`); return r.json(); })); const css = n => getComputedStyle(document.documentElement).getPropertyValue(n).trim(); const pad = v => String(v).padStart(2, "0"); const esc = s => String(s ?? "").replace(/[&<>"]/g, c => ({ "&": "&", "<": "<", ">": ">", '"': """ })[c]); const minus = s => String(s).replace(/^-/, "−"); const f1 = v => (v == null || Number.isNaN(v) ? "–" : minus(v.toFixed(1))); const f3 = v => (v == null || Number.isNaN(v) ? "–" : v.toFixed(3)); const pct = v => (v == null || Number.isNaN(v) ? "–" : `${Math.round(v * 100)}%`); const mean = a => { let s = 0, n = 0; for (const v of a) if (v != null && !Number.isNaN(v)) { s += v; n++; } return n ? s / n : null; }; const fmtUTC = s => { const d = new Date(s * 1000); return `${d.getUTCDate()} ${MON[d.getUTCMonth()]} ${d.getUTCFullYear()}, ${pad(d.getUTCHours())}:${pad(d.getUTCMinutes())} UTC`; }; const fmtDay = key => { const [y, m, d] = key.split("-"); return `${+d} ${MON[+m - 1]} ${y}`; }; // Madrid calendar for a UTC second, cached per hour (offsets are whole hours). Berlin shares // Madrid's offsets, so it serves the German markets too. const MAD = new Intl.DateTimeFormat("en-CA", { timeZone: "Europe/Madrid", year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", hourCycle: "h23", weekday: "short" }); const hourCache = new Map(); function madrid(sec) { const h = Math.floor(sec / 3600); let v = hourCache.get(h); if (!v) { const p = Object.fromEntries(MAD.formatToParts(new Date(h * 3600e3)).map(x => [x.type, x.value])); v = { day: `${p.year}-${p.month}-${p.day}`, month: `${p.year}-${p.month}`, hour: +p.hour, wd: WEEKDAYS.indexOf(p.weekday) }; hourCache.set(h, v); } return v; } // --- Charts: a registry so resizes and theme switches redraw every chart -------------------- const charts = new Set(); function mount(el, build, height) { const h = () => (typeof height === "function" ? height(el.clientWidth) : height); const c = { el, build: () => build(el.clientWidth || 600, h()), inst: null, h }; c.inst = c.build(); charts.add(c); new ResizeObserver(() => { if (!document.body.contains(el)) { c.inst?.destroy(); charts.delete(c); return; } if (el.clientWidth && c.inst) c.inst.setSize({ width: el.clientWidth, height: c.h() }); }).observe(el); return c; } function redrawAll() { for (const c of charts) { if (!document.body.contains(c.el)) { charts.delete(c); continue; } const x = c.inst?.scales?.x; const keep = x && { min: x.min, max: x.max }; c.inst?.destroy(); c.inst = c.build(); if (keep && c.keepX) c.inst.setScale("x", keep); } } matchMedia("(prefers-color-scheme: dark)").addEventListener("change", redrawAll); new MutationObserver(redrawAll).observe(document.documentElement, { attributes: true, attributeFilter: ["data-theme"] }); function axisBase() { return { stroke: css("--ink-soft"), font: `11px ${css("--mono")}`, labelFont: `12px ${css("--sans")}`, grid: { stroke: css("--grid"), width: 1 }, ticks: { stroke: css("--grid"), width: 1, size: 4 }, }; } function timeValues(u, splits, ax, space, incr) { return splits.map(s => { const d = new Date(s * 1000), date = `${pad(d.getUTCDate())}-${pad(d.getUTCMonth() + 1)}`; if (incr >= 86400 * 25) return `${MON[d.getUTCMonth()]} ${d.getUTCFullYear()}`; if (incr >= 86400) return date; const hm = `${pad(d.getUTCHours())}:${pad(d.getUTCMinutes())}`; return d.getUTCHours() === 0 && d.getUTCMinutes() === 0 ? `${hm}\n${date}` : hm; }); } const yValues = (u, s) => s.map(v => minus(Math.abs(v) >= 1000 ? Math.round(v).toLocaleString("en-GB") : +v.toFixed(2))); function axes(yLabel, xValues = timeValues, xOpts = {}) { const a = axisBase(); return [{ ...a, values: xValues, space: 64, size: 44, ...xOpts }, { ...a, label: yLabel, labelSize: yLabel ? 20 : 0, size: 58, values: yValues }]; } const tzUTC = ts => uPlot.tzDate(new Date(ts * 1000), "Etc/UTC"); function tooltip(rows) { let tt; return { hooks: { init: u => { tt = document.createElement("div"); tt.className = "tt"; tt.hidden = true; u.over.appendChild(tt); }, setCursor: u => { const { left, top, idx } = u.cursor; const html = idx == null || left < 0 ? null : rows(u, idx); if (!html) { tt.hidden = true; return; } tt.innerHTML = html; tt.hidden = false; const w = tt.offsetWidth, h = tt.offsetHeight, W = u.over.clientWidth, H = u.over.clientHeight; const x = left + 16 + w > W ? Math.max(0, left - 16 - w) : left + 16; tt.style.transform = `translate(${x}px, ${Math.min(Math.max(0, top - h / 2), Math.max(0, H - h))}px)`; }, }, }; } const ttHTML = (title, rows) => `
${esc(title)}
` + rows.map(([c, k, v, dash]) => `
${esc(k)}${v}
`).join(""); // Default tooltip: every visible series with a `tt` label. const seriesRows = fmtX => (u, idx) => { const rows = []; u.series.forEach((s, i) => { if (i && s.show && s.tt) { const v = u.data[i][idx]; if (v != null) rows.push([s._color, s.tt, f1(v)]); } }); return rows.length ? ttHTML(fmtX(u.data[0][idx]), rows) : null; }; function line(label, color, opts = {}) { return { label, tt: label, stroke: color, _color: color, width: 2, points: { show: false }, ...opts }; } // Shades [start, end) spans (seconds) behind the series: the playground days. function shade(spans) { return { hooks: { drawAxes: u => { const { left, top, width, height } = u.bbox; u.ctx.save(); u.ctx.fillStyle = css("--pg"); for (const [a, b] of spans) { const x0 = Math.max(u.valToPos(a, "x", true), left), x1 = Math.min(u.valToPos(b, "x", true), left + width); if (x1 > x0) u.ctx.fillRect(x0, top, x1 - x0, height); } u.ctx.restore(); }, }, }; } function nowMarker(nowSec) { return { hooks: { drawAxes: u => { const { left, top, width, height } = u.bbox, x = Math.max(u.valToPos(nowSec, "x", true), left); if (x >= left + width) return; u.ctx.save(); u.ctx.fillStyle = css("--future"); u.ctx.fillRect(x, top, left + width - x, height); u.ctx.restore(); }, draw: u => { const { left, top, width, height } = u.bbox, x = u.valToPos(nowSec, "x", true), dpr = devicePixelRatio || 1; if (x < left || x > left + width) return; const ctx = u.ctx; ctx.save(); ctx.strokeStyle = css("--ink-soft"); ctx.setLineDash([4 * dpr, 3 * dpr]); ctx.lineWidth = dpr; ctx.beginPath(); ctx.moveTo(x, top); ctx.lineTo(x, top + height); ctx.stroke(); const d = new Date(nowSec * 1000); ctx.fillStyle = css("--ink-soft"); ctx.font = `${10 * dpr}px ${css("--mono")}`; ctx.fillText(`NOW ${pad(d.getUTCHours())}:${pad(d.getUTCMinutes())} UTC`, x + 6 * dpr, top + 12 * dpr); ctx.restore(); }, }, }; } const chartHeight = w => Math.max(280, Math.min(440, w * 0.45)); // UI bits function seg(id, options, value) { return `
${options.map(([v, l]) => ``).join("")}
`; } function onSeg(root, id, fn) { const g = root.querySelector(`#${id}`); g?.addEventListener("click", e => { const b = e.target.closest("button"); if (!b) return; g.querySelectorAll("button").forEach(x => x.setAttribute("aria-pressed", String(x === b))); fn(b.dataset.v); }); } // The selected country and variable (COUNTRIES, below), merged: id = its data key (build.py // MARKETS), name = "Spain mFRR energy", resources = [its Predico resource]. const mk = () => { const c = COUNTRIES.find(x => x.id === sel.c), v = c.vars.find(x => x.id === sel.v); return { ...c, ...v, c: c.id, v: v.id, id: v.data ?? c.data, name: `${c.name} ${v.name}`, resources: [v.resource] }; }; const shortsOf = (m, meta) => m.resources.map(r => meta.short[r]); const targetSeg = (id, shorts, value) => (shorts.length > 1 ? seg(id, shorts.map(t => [t, LABEL[t]]), value) : ""); const kpi = (k, v, d = "", cls = "") => `
${esc(k)}${v}${d}
`; const relClass = r => (r == null || Math.abs(r - 1) < 5e-4 ? "" : r < 1 ? "good" : "bad"); const relText = r => (r == null ? "no baseline" : `${f3(r)} × baseline`); // Colours per model family, dash per variant: the same config always looks the same. const FAMILY = [["slot_climatology", "--ink-soft"], ["t0", "--accent-ink"], ["chronos", "#3b6fd1"], ["timesfm", "#8a63d2"], ["timestral", "#d08a1e"], ["timeh2o", "#1f9a8a"], ["ciproto", "#7a8f2a"]]; const DASHES = [[], [7, 4], [2, 3], [10, 3, 2, 3], [4, 4], [1, 2]]; let CONFIGS = []; function configStyle(name) { const fam = FAMILY.find(([p]) => name.startsWith(p)); const color = fam ? (fam[1].startsWith("--") ? css(fam[1]) : fam[1]) : "#c2456b"; const sibs = CONFIGS.filter(c => (fam ? c.startsWith(fam[0]) : !FAMILY.some(([p]) => c.startsWith(p)))); return { color, dash: DASHES[Math.max(0, sibs.indexOf(name)) % DASHES.length] }; } // A line swatch with the config's colour and dash, as in the charts. const swatch = name => { const st = configStyle(name); return ``; }; // Config names as readable parts: t0gamma_cov_ecmwfd2_knmi_ctx90 -> t0-gamma, covariates, 90 d, // IFS + ICON-D2 + KNMI. `wx` = the market's weather models (weather.json), what a plain `cov` // config reads. Unknown parts land in `notes` as they are. const MODEL_NAMES = [["slot_climatology", "Climatology"], ["t0gamma", "t0-gamma"], ["t0chronos2", "t0-gamma + Chronos-2"], ["chronos2", "Chronos-2"], ["timesfm3", "TimesFM 3"], ["timestral5m", "Timestral 5M"], ["timeh2o", "TimeH2O (H2O.ai)"], ["ciproto", "CI Proto (Continuous Intelligence)"], ["elia", "Elia (TSO)"], ["entsoe", "TSO (ENTSO-E)"]]; const WX = { ecmwf: "IFS", icond2: "ICON-D2", knmi: "KNMI", aifs: "AIFS" }; const wxShort = name => name.replace("ECMWF ", "").replace("KNMI HARMONIE-AROME", "KNMI"); function parseConfig(name, wx = []) { const known = MODEL_NAMES.find(([p]) => name === p || name.startsWith(p + "_")); const parts = name.slice(known ? known[0].length : name.indexOf("_") + 1 || name.length).split("_").filter(Boolean); const r = { model: known ? known[1] : name.split("_")[0], cov: null, ctx: null, weather: null, notes: [] }; let explicit = null; for (const p of parts) { let x; if (p === "cov" || p === "uni") r.cov = p === "cov"; else if ((x = p.match(/^ctx(\d+)$/) ?? p.match(/^(\d+)d$/))) r.ctx = +x[1]; else if (p === "ecmwfd2") (explicit ??= []).push("IFS", "ICON-D2"); else if (WX[p]) (explicit ??= []).push(WX[p]); // WeatherNext 3 (BigQuery, not in weather.json): `wn3` = the market's models + WN3 else if (p === "wn3") (explicit ??= wx.map(wxShort)).push("WN3"); else if (p === "wn3only") explicit = ["WN3"]; // the noX ablations predate KNMI and AIFS: IFS + ICON-D2 minus one else if (p === "noecmwf") explicit = ["ICON-D2"]; else if (p === "noicond2") explicit = ["IFS"]; else if (p === "cap") r.notes.push("+ PV capacity"); else if ((x = p.match(/^o(\d\d)(\d\d)$/))) r.notes.push(`origin ${x[1]}:${x[2]}`); else if ((x = p.match(/^no(\d+)$/))) r.notes.push(`without ESIOS ${x[1]}`); else if ((x = p.match(/^dayahead(\d+)h$/))) r.notes.push(`issued ${x[1]}:00 D-1`); else if (p === "a69") r.notes.push("day-ahead (A69)"); else r.notes.push(p); } if (r.cov) r.weather = explicit ?? wx.map(wxShort); return r; } const cfgLabel = (name, wx) => { const p = parseConfig(name, wx); return [p.model, p.cov == null ? "" : p.cov ? "cov" : "uni", p.ctx == null ? "" : `${p.ctx} d`, p.weather?.join(" + ") ?? "", ...p.notes].filter(Boolean).join(" · "); }; // --- Daily scores (same formulas as src/openpredico/evaluation/metrics.py) ------------------ function dailyScores(x, q10, q50, q90, obs) { const days = new Map(); for (let i = 0; i < x.length; i++) { const o = obs[i], m = q50[i]; if (o == null || m == null) continue; const key = madrid(x[i]).day; let d = days.get(key); if (!d) days.set(key, (d = { key, t: x[i], n: 0, se: 0, ae: 0, wk: 0, cov: 0 })); d.n++; d.se += (o - m) ** 2; d.ae += Math.abs(o - m); d.wk += q90[i] - q10[i] + 10 * Math.max(0, q10[i] - o) + 10 * Math.max(0, o - q90[i]); if (o >= q10[i] && o <= q90[i]) d.cov++; } return [...days.values()].map(d => ({ key: d.key, t: d.t, n: d.n, rmse: Math.sqrt(d.se / d.n), mae: d.ae / d.n, winkler: d.wk / d.n, coverage: d.cov / d.n })); } // --- Live -------------------------------------------------------------------------------- // q*: our continuous forecast as it stood at the gate. s*: what Predico registered as our session // submission (the values it scores). b*: slot climatology from the same run's inputs. async function renderLive(root) { const [live, meta] = await Promise.all([json("live.json"), json("meta.json")]); const m = mk(), shorts = shortsOf(m, meta); const head = `

Live forecasts

What we sent to Predico for ${esc(m.name)}, published only after each gate (${m.gateLocal}), next to the measured values from ${m.source}.

`; if (!live.available || !shorts.some(s => live.targets[s])) { root.innerHTML = `${head}

No live forecasts are published yet. The first ones appear here half an hour after the next gate.

`; return; } let target = shorts[0]; root.innerHTML = `${head}
${targetSeg("lv-t", shorts, target)}
`; onSeg(root, "lv-t", v => { target = v; draw(); }); draw(); function draw() { const T = live.targets[target], unit = meta.units[target]; const n = T.q50.length, x = Array.from({ length: n }, (_, i) => T.start + i * STEP); const nul = () => new Array(n).fill(null); const [s10, s50, s90] = ["s10", "s50", "s90"].map(k => T[k] ?? nul()); // Scored = Predico's registered values where it has them, else our continuous forecast. const pick = (s, q) => s.map((v, i) => v ?? q[i]); const e10 = pick(s10, T.q10), e50 = pick(s50, T.q50), e90 = pick(s90, T.q90); const model = dailyScores(x, e10, e50, e90, T.obs); const base = new Map(dailyScores(x, T.b10, T.b50, T.b90, T.obs).map(d => [d.key, d])); // Day record: registered by Predico, model forecast only (not submitted), or none. const dayInfo = new Map(); for (let i = 0; i < n; i++) { const key = madrid(x[i]).day; let d = dayInfo.get(key); if (!d) dayInfo.set(key, (d = { key, i0: i, i1: i, rows: 0, sub: 0 })); d.i1 = i; if (e50[i] != null) d.rows++; if (s50[i] != null) d.sub++; } const record = [...dayInfo.values()]; const counts = { sub: 0, cont: 0, miss: 0 }; for (const d of record) { d.state = d.rows === 0 ? "miss" : d.sub ? "sub" : "cont"; d.pg = T.env_days?.[d.key] === "playground"; } const pgDays = record.filter(d => d.pg), PG = "* playground: qualifying runs on the Predico playground, never scored by Predico"; record.forEach(d => counts[d.state]++); const STATE = { sub: "submitted", cont: "not submitted", miss: "no forecast" }; const envNote = live.demo ? `` : T.env === "playground" ? `` : pgDays.length ? `` : ""; const t50 = T.t50 ?? nul(), hasTso = t50.some(v => v != null); const body = root.querySelector("#lv-body"); body.innerHTML = `${envNote}

Forecast vs measured

Dotted: our model's forecast as of the gate. Solid underneath: what Predico registered; days without it were not submitted. ${unit} · times in UTC

${seg("lv-r", [["7", "7 days"], ["30", "30 days"], ["all", "All"]], "7")}
${hasTso ? `` : ""}
drag to zoom · double-click to reset · scores follow the view

Scores against climatology

Climatology is the slot climatology of the last 28 days, built from the same run's inputs. Ratio = our score ÷ climatology on the days both have; below 1 beats it. Coverage target is 80%. Lower is better for every other metric.

Predico's official scores

How Predico scored our submissions and where we ranked among all forecasters on that challenge. Only our own results are shown.

Submission record

One square per target day (${m.city}). Click a day to show it in the chart.

${record.map(d => ``).join("")}
■ submitted · ${counts.sub}⋯ not submitted · ${counts.cont}▨ missed · ${counts.miss}${pgDays.length ? `* playground · ${pgDays.length}` : ""}

Model and inputs

Latest run ${esc(T.last_run.slice(0, 16).replace("T", " "))} UTC · ${T.runs} run${T.runs === 1 ? "" : "s"} published

${esc(T.env)}

${esc(T.model)}: t0-gamma (The Forecasting Company, Apache-2.0), zero-shot, 90 days of context, with covariates. D+2 to D+10 fall back to slot climatology. Backtest results

${(T.features.length ? T.features : ["(feature list arrives with the first published run)"]).map(f => `${esc(f)}`).join("")}

Daily scores

Every target day, newest first. Click a row to show it in the chart.

`; const data = [x, e10, e90, s50, T.q50, T.b50, T.obs, t50]; const span = x[n - 1] - x[0]; let range = "7"; const setRange = r => { range = r; const max = x[n - 1] + STEP, min = r === "all" ? x[0] : Math.max(x[0], max - +r * 86400); main.inst.setScale("x", { min, max }); }; const shown = [true, true, true, true, true, false, true, hasTso]; const main = mount(root.querySelector("#lv-chart"), (w, h) => new uPlot({ width: w, height: h, tzDate: tzUTC, legend: { show: false }, scales: { x: { time: true } }, cursor: { drag: { x: true, y: false }, points: { size: 7, width: 2, fill: css("--surface") }, bind: { dblclick: () => () => { setRange(range); return null; } } }, series: [{}, { stroke: css("--accent"), width: 1, dash: [2, 3], points: { show: false } }, { stroke: css("--accent"), width: 1, dash: [2, 3], points: { show: false } }, line("Submitted", css("--sub"), { width: 6 }), line("Model", css("--cont"), { width: 2, dash: [2, 4], cap: "round" }), line("Climatology", css("--base"), { width: 1.5, dash: [6, 4] }), line("Observed", css("--obs"), { width: 2 }), line("TSO forecast", css("--tso"), { width: 1.5, dash: [8, 3, 2, 3] }), ].map((s, i) => (i ? { ...s, show: shown[i] } : s)), bands: [{ series: [2, 1], fill: css("--band") }], axes: axes(`${LABEL[target]} (${unit})`), hooks: { setScale: [(u, k) => k === "x" && summary(u.scales.x.min, u.scales.x.max)] }, plugins: [shade(pgDays.map(d => [x[d.i0], x[d.i1] + STEP])), nowMarker(Date.now() / 1000), tooltip((u, i) => { const rows = [], on = k => u.series[k].show; if (on(6) && T.obs[i] != null) rows.push([css("--obs"), "Observed", `${f1(T.obs[i])} ${unit}`]); if (on(3) && s50[i] != null) rows.push([css("--sub"), "Submitted", `${f1(s50[i])} ${unit}`]); if (on(4) && T.q50[i] != null) rows.push([css("--cont"), "Model", `${f1(T.q50[i])} ${unit}`, true]); if (on(1) && e10[i] != null) rows.push([css("--accent"), "q10–q90", `${f1(e10[i])} … ${f1(e90[i])}`]); if (on(5) && T.b50[i] != null) rows.push([css("--base"), "Climatology", `${f1(T.b50[i])} ${unit}`]); if (on(7) && t50[i] != null) rows.push([css("--tso"), `${m.source} forecast`, `${f1(t50[i])} ${unit}`]); return rows.length ? ttHTML(fmtUTC(x[i]) + (dayInfo.get(madrid(x[i]).day)?.pg ? " · playground" : ""), rows) : null; })], }, data, root.querySelector("#lv-chart")), chartHeight); main.keepX = true; setRange(span < 7 * 86400 ? "all" : "7"); onSeg(root, "lv-r", setRange); root.querySelector("#lv-legend").addEventListener("click", e => { const b = e.target.closest("button"); if (!b) return; const on = b.getAttribute("aria-pressed") !== "true"; b.setAttribute("aria-pressed", String(on)); b.dataset.s.split(",").forEach(i => { shown[+i] = on; main.inst.setSeries(+i, { show: on }); }); }); const zoomDay = k => { const d = dayInfo.get(k); main.inst.setScale("x", { min: x[d.i0], max: x[d.i1] + STEP }); }; root.querySelector("#lv-days").addEventListener("click", e => { const b = e.target.closest("button"); if (b) zoomDay(b.dataset.k); }); // Summary table: the days in the chart's view; ratios only on days with a baseline. const METRICS = [["rmse", "RMSE (q50)", f1, unit], ["mae", "MAE (q50)", f1, unit], ["winkler", "Winkler (q10–q90)", f1, unit], ["coverage", "Coverage (q10–q90)", pct, "target 80%"]]; const covClass = c => (c == null ? "" : Math.abs(c - 0.8) <= 0.05 ? "good" : "warn"); function summary(lo, hi) { const inView = model.filter(d => d.t >= lo - 3600 && d.t < hi), both = inView.filter(d => base.has(d.key)); root.querySelector("#lv-span").textContent = inView.length ? `${inView.length} scored day${inView.length === 1 ? "" : "s"} in view: ${fmtDay(inView[0].key)} – ${fmtDay(inView[inView.length - 1].key)}` : "No measured days in view yet."; root.querySelector("#lv-sum").innerHTML = `${METRICS.map(([m, label, f, u]) => { const ours = mean(inView.map(d => d[m])), clim = mean(both.map(d => base.get(d.key)[m])); const r = m === "coverage" || !both.length ? null : mean(both.map(d => d[m])) / clim; return ``; }).join("")}
MetricOur forecastClimatologyRatioUnit
${label}${f(ours)}${f(clim)}${r == null ? "–" : f3(r)}${u}
`; } summary(main.inst.scales.x.min, main.inst.scales.x.max); // Official scores: one column per variable and metric, value with our rank among N. const off = T.official ?? [], offEl = root.querySelector("#lv-off"); if (!off.length) offEl.innerHTML = `

No official scores yet. Predico scores a day once its measurements are in, usually a day or two after delivery.

`; else { const cols = [...new Set(off.map(r => `${r.variable} ${r.metric}`))].sort(); const byDay = new Map(); for (const r of off) (byDay.get(r.day) ?? byDay.set(r.day, {}).get(r.day))[`${r.variable} ${r.metric}`] = r; const days = [...byDay.keys()].sort().reverse(); const rankCell = r => (r ? `${f1(r.value)} · ${r.rank <= 3 ? `${r.rank}` : r.rank}/${r.participants}` : `–`); const latest = byDay.get(days[0]); offEl.innerHTML = `
${cols.map(c => { const r = latest[c]; return kpi(`${c} · ${fmtDay(days[0])}`, r ? `${r.rank} / ${r.participants}` : "–", r ? `score ${f1(r.value)}` : ""); }).join("")}
${cols.map(c => ``).join("")}${days.map(d => `${cols.map(c => rankCell(byDay.get(d)[c])).join("")}`).join("")}
Day${esc(c)} · rank
${fmtDay(d)}
`; } // Daily table, newest first; days without measurements still show their status. const scoredDay = new Map(model.map(d => [d.key, d])); const cell = (d, b, m, f) => { const v = d?.[m], c = b?.[m], r = m === "coverage" || v == null || c == null ? null : v / c; return `${f(v)}${f(c)}${m === "coverage" ? "" : `${r == null ? "–" : f3(r)}`}`; }; root.querySelector("#lv-daily").innerHTML = `${["ours", "clim.", "ratio", "ours", "clim.", "ratio", "ours", "clim.", "ratio", "ours", "clim."].map(h => ``).join("")}${[...record].reverse().map(r => { const d = scoredDay.get(r.key), b = base.get(r.key); return `${d ? cell(d, b, "rmse", f1) + cell(d, b, "mae", f1) + cell(d, b, "winkler", f1) + cell(d, b, "coverage", pct) : ``}`; }).join("")}
DayStatusRMSE (${unit})MAE (${unit})Winkler (${unit})Coverage
${h}
${fmtDay(r.key)}${r.pg ? `*` : ""}${STATE[r.state]}${r.pg ? " · playground" : ""}${r.state === "miss" ? "no forecast" : "awaiting measurements"}
`; root.querySelector("#lv-daily").addEventListener("click", e => { const tr = e.target.closest("tr[data-k]"); if (tr) zoomDay(tr.dataset.k); }); } } // --- Backtest ---------------------------------------------------------------------------- function leaderboard(days, baseline) { const rows = {}; for (const [t, d] of Object.entries(days)) { for (const [c, s] of Object.entries(d.configs)) { const r = (rows[c] ??= { config: c }); for (const m of ["rmse", "winkler"]) { const a = s[m], b = d.configs[baseline][m]; let sa = 0, sb = 0, nb = 0; for (let i = 0; i < a.length; i++) if (a[i] != null && b[i] != null) { sa += a[i]; sb += b[i]; nb++; } r[`${t} ${m}`] = mean(a); r[`${t} ${m} rel`] = nb ? sa / sb : null; } r[`${t} coverage`] = mean(s.coverage); r[`${t} days`] = s.rmse.filter(v => v != null).length; } } const out = Object.values(rows); for (const r of out) { const rel = Object.keys(r).filter(k => k.endsWith(" rel")).map(k => r[k]); r.score = rel.every(v => v) ? Math.exp(mean(rel.map(Math.log))) : null; } out.sort((a, b) => (a.score ?? 9) - (b.score ?? 9)); out.forEach((r, i) => (r.rank = r.score == null ? null : i + 1)); return out; } async function renderBacktest(root) { const [allDays, meta, prof, wxAll] = await Promise.all([json("days.json"), json("meta.json"), json("profiles.json"), json("weather.json").catch(() => ({}))]); const m = mk(), wx = (wxAll[m.id]?.models ?? []).map(r => r.name), targets = shortsOf(m, meta).filter(t => allDays[t]); if (!targets.length) { root.innerHTML = `

Backtest

No backtest of ${esc(m.name)} is published yet.

`; return; } const days = Object.fromEntries(targets.map(t => [t, allDays[t]])); CONFIGS = meta.configs.map(c => c.name).filter(c => targets.some(t => days[t].configs[c])); const type = Object.fromEntries(meta.configs.map(c => [c.name, c.type])); const info = Object.fromEntries(CONFIGS.map(c => [c, parseConfig(c, wx)])); const label = c => cfgLabel(c, wx); const lb = leaderboard(days, meta.baseline), t0 = targets[0], live = meta.live_config[m.id]; const top = lb.filter(r => r.config !== live && r.config !== meta.baseline).slice(0, 2).map(r => r.config); let sel = [live, meta.baseline, ...top].filter(c => CONFIGS.includes(c)), types = new Set(), absolute = false, sortK = "rank", sortDir = 1; root.innerHTML = `

Backtest

Test year 1 Nov 2025 – 31 Oct 2026. Each forecast is made at 14:00 ${m.city} on D-1 from data published before then, and scored per local day as Predico does. Lower is better. ${m.missingTruth}

Leaderboard

Scores relative to ${esc(meta.baseline)} (= 1.000) on the days both are scored. Highlighted: the live config. Hover a model for its config name; click a column to sort.

${["baseline", "TSO forecast", "foundation model", "ML"].filter(t => CONFIGS.some(c => type[c] === t)).map(t => ``).join("")}
How the scores work

Configs in the charts below

Same colour = same model family; dash = variant.

Day viewer

The configs selected above, line styles as there. Times in UTC.

${targetSeg("dv-t", targets, t0)}
lines: q50 of each configq10–q90 (first selected)actual

By month

${targetSeg("mo-t", targets, t0)}${seg("mo-m", [["rmse", "RMSE"], ["winkler", "Winkler"]], "rmse")}

Absolute error of q50 by hour and weekday

${m.city} time.

${targetSeg("pr-t", targets, t0)}

Win rate

Cell (row A, column B): share of days scored for both where A has the lower score. Read across a row.

${targetSeg("wr-t", targets, t0)}${seg("wr-m", [["rmse", "RMSE"], ["winkler", "Winkler"]], "rmse")}
`; const lbEl = root.querySelector("#bt-lb"); // Sortable columns: [key, header, value for sorting, cell html, numeric]. const yesNo = v => (v == null ? "–" : v ? "yes" : "no"); function drawLb() { const rows = lb.filter(r => !types.size || types.has(type[r.config])); const cols = targets.flatMap(t => [[`${t} rmse rel`, `${LABEL[t]} RMSE`, f3], [`${t} winkler rel`, `${LABEL[t]} Winkler`, f3], [`${t} coverage`, `${LABEL[t]} cov.`, pct], ...(absolute ? [[`${t} rmse`, `${LABEL[t]} RMSE abs`, f1], [`${t} winkler`, `${LABEL[t]} Winkler abs`, f1], [`${t} days`, "days", String]] : [])]); const notes = rows.some(r => info[r.config].notes.length), weather = rows.some(r => info[r.config].weather?.length); const COLS = [ ["rank", "Rank", r => r.rank, r => (r.rank <= 3 ? `${r.rank}` : r.rank ?? "–"), true], ["model", "Model", r => info[r.config].model, r => `${esc(info[r.config].model)}${r.config === live ? ' live' : ""}`], ["cov", "Covariates", r => yesNo(info[r.config].cov), r => yesNo(info[r.config].cov)], ["ctx", "Context", r => info[r.config].ctx, r => (info[r.config].ctx == null ? "–" : `${info[r.config].ctx} d`), true], ...(weather ? [["wx", "Weather", r => info[r.config].weather?.join(", ") ?? "", r => esc(info[r.config].weather?.join(", ") || "–")]] : []), ...(notes ? [["notes", "Notes", r => info[r.config].notes.join(", "), r => esc(info[r.config].notes.join(", "))]] : []), ["type", "Type", r => type[r.config], r => esc(type[r.config])], ["score", "Score", r => r.score, r => `${f3(r.score)}`, true], ...cols.map(([k, h, f]) => [k, h, r => r[k], r => f(r[k]), true]), ]; const col = COLS.find(c => c[0] === sortK) ?? COLS[0]; const val = r => col[2](r); const sorted = [...rows].sort((a, b) => { const x = val(a), y = val(b); if (x == null || x === "") return 1; if (y == null || y === "") return -1; // empty last return (col[4] ? x - y : String(x).localeCompare(String(y))) * sortDir; }); const cls = k => (k === "score" || k.endsWith("rel") ? "rel" : ""); lbEl.innerHTML = `${COLS.map(([k, h, , , num]) => ``).join("")}${sorted.map(r => `${COLS.map(([k, , v, html, num]) => ``).join("")}`).join("")}
${h}${k === sortK ? (sortDir > 0 ? " ↑" : " ↓") : ""}
${html(r)}
`; } lbEl.addEventListener("click", e => { const th = e.target.closest("th[data-k]"); if (!th) return; sortDir = th.dataset.k === sortK ? -sortDir : 1; sortK = th.dataset.k; drawLb(); }); drawLb(); root.querySelector("#bt-types").addEventListener("click", e => { const b = e.target.closest("button"); if (!b) return; types.has(b.dataset.v) ? types.delete(b.dataset.v) : types.add(b.dataset.v); b.setAttribute("aria-pressed", String(types.has(b.dataset.v))); drawLb(); }); root.querySelector("#bt-abs").addEventListener("change", e => { absolute = e.target.checked; drawLb(); }); const selEl = root.querySelector("#bt-sel"); const drawSel = () => (selEl.innerHTML = lb.map(r => ``).join("")); drawSel(); selEl.addEventListener("click", e => { const b = e.target.closest("button"); if (!b) return; sel = sel.includes(b.dataset.v) ? sel.filter(c => c !== b.dataset.v) : [...sel, b.dataset.v]; b.setAttribute("aria-pressed", String(sel.includes(b.dataset.v))); redrawSel(); }); const cfgSeries = c => { const st = configStyle(c); return line(label(c), st.color, { dash: st.dash, width: c === live ? 2.5 : 1.75 }); }; // By month let moT = t0, moM = "rmse"; const months = t => [...new Set(days[t].days.map(d => d.slice(0, 7)))]; const mo = mount(root.querySelector("#mo-chart"), (w, h) => { const ms = months(moT), x = ms.map((m, i) => i); const ys = sel.map(c => ms.map(m => mean(days[moT].days.map((d, i) => (d.startsWith(m) ? days[moT].configs[c]?.[moM][i] : null))))); return new uPlot({ width: w, height: h, legend: { show: false }, scales: { x: { time: false } }, cursor: { points: { size: 6, width: 2, fill: css("--surface") } }, series: [{}, ...sel.map(c => ({ ...cfgSeries(c), points: { show: true, size: 5 } }))], axes: axes(`${moM === "rmse" ? "RMSE" : "Winkler"} (${meta.units[moT]})`, (u, s) => s.map(i => (Number.isInteger(i) && ms[i] ? `${MON[+ms[i].slice(5) - 1]}\n${ms[i].slice(0, 4)}` : "")), { space: 40 }), plugins: [tooltip(seriesRows(i => { const m = ms[i]; return `${MON[+m.slice(5) - 1]} ${m.slice(0, 4)}`; }))], }, [x, ...ys], root.querySelector("#mo-chart")); }, 300); onSeg(root, "mo-t", v => { moT = v; rebuild(mo); }); onSeg(root, "mo-m", v => { moM = v; rebuild(mo); }); // Profiles let prT = t0; const prof1 = (el, key, labels) => mount(el, (w, h) => { const x = labels.map((_, i) => i); return new uPlot({ width: w, height: h, legend: { show: false }, scales: { x: { time: false } }, cursor: { points: { size: 6, width: 2, fill: css("--surface") } }, series: [{}, ...sel.map(cfgSeries)], axes: axes(`MAE (${meta.units[prT]})`, (u, s) => s.map(i => labels[i] ?? ""), { space: 34 }), plugins: [tooltip(seriesRows(i => labels[i]))], }, [x, ...sel.map(c => prof[prT][c]?.[key] ?? x.map(() => null))], el); }, 260); const ph = prof1(root.querySelector("#pr-h"), "hour", Array.from({ length: 24 }, (_, h) => `${pad(h)}:00`)); const pw = prof1(root.querySelector("#pr-w"), "weekday", WEEKDAYS); onSeg(root, "pr-t", v => { prT = v; rebuild(ph); rebuild(pw); }); // Day viewer let dvT = t0; const target = await json(`target/${mk().id}.json`); const off = (meta.start - target.start) / STEP; const x = Array.from({ length: meta.n }, (_, i) => meta.start + i * STEP); const dayIdx = new Map(); x.forEach((s, i) => { const k = madrid(s).day; const r = dayIdx.get(k); r ? (r[1] = i) : dayIdx.set(k, [i, i]); }); const dv = { el: root.querySelector("#dv-chart") }; async function drawDay() { const key = root.querySelector("#dv-d").value, r = dayIdx.get(key); if (!r) return; const steps = await Promise.all(sel.map(c => json(`steps/${dvT}/${c}.json`))); const [i0, i1] = r, sl = a => a.slice(i0, i1 + 1); const xs = sl(x), obs = target[dvT].slice(off + i0, off + i1 + 1); const k = days[dvT].days.indexOf(key); root.querySelector("#dv-s").innerHTML = k < 0 ? "" : `This day:${sel.map(c => `${swatch(c)} RMSE ${f1(days[dvT].configs[c].rmse[k])} · Winkler ${f1(days[dvT].configs[c].winkler[k])}`).join("")}`; const first = steps[0]; const build = (w, h) => new uPlot({ width: w, height: h, tzDate: tzUTC, legend: { show: false }, scales: { x: { time: true } }, cursor: { points: { size: 6, width: 2, fill: css("--surface") } }, series: [{}, { stroke: "transparent", points: { show: false } }, { stroke: "transparent", points: { show: false } }, ...sel.map(cfgSeries), line("Actual", css("--obs"), { width: 2.25 })], bands: first ? [{ series: [2, 1], fill: css("--band") }] : [], axes: axes(`${LABEL[dvT]} (${meta.units[dvT]})`), plugins: [tooltip(seriesRows(fmtUTC))], }, [xs, first ? sl(first.q10) : xs.map(() => null), first ? sl(first.q90) : xs.map(() => null), ...steps.map(s => sl(s.q50)), obs], dv.el); if (dv.c) { dv.c.build = () => build(dv.el.clientWidth, chartHeight(dv.el.clientWidth)); rebuild(dv.c); } else dv.c = mount(dv.el, build, chartHeight); } onSeg(root, "dv-t", v => { dvT = v; drawDay(); }); root.querySelector("#dv-d").addEventListener("change", drawDay); await drawDay(); function redrawSel() { rebuild(mo); rebuild(ph); rebuild(pw); drawDay(); drawWr(); } // Win rate let wrT = t0, wrM = "rmse"; function drawWr() { const order = lb.map(r => r.config).filter(c => sel.includes(c)); const d = days[wrT].configs; const cell = (a, b) => { let w = 0, n = 0; const A = d[a][wrM], B = d[b][wrM]; for (let i = 0; i < A.length; i++) if (A[i] != null && B[i] != null) { n++; if (A[i] < B[i]) w++; } return n ? w / n : null; }; root.querySelector("#wr").innerHTML = order.length < 2 ? `

Select at least two configs above.

` : `${order.map(c => ``).join("")}${order.map(a => `${order.map(b => { if (a === b) return ``; const v = cell(a, b), g = v == null ? 0 : (v - 0.5) * 2; const bg = g >= 0 ? `color-mix(in srgb, var(--accent) ${Math.round(g * 70)}%, transparent)` : `color-mix(in srgb, var(--bad) ${Math.round(-g * 55)}%, transparent)`; return ``; }).join("")}`).join("")}
A \\ B${esc(label(c))}
${esc(label(a))}${pct(v)}
`; } drawWr(); onSeg(root, "wr-t", v => { wrT = v; drawWr(); }); onSeg(root, "wr-m", v => { wrM = v; drawWr(); }); } function rebuild(c) { c.inst?.destroy(); c.inst = c.build(); } // --- Target data ------------------------------------------------------------------------- async function renderTarget(root) { const [target, meta] = await Promise.all([json(`target/${mk().id}.json`), json("meta.json")]); const mkt = mk(), shorts = shortsOf(mkt, meta), scatter = "price" in target; const n = target[shorts[0]].length, x = Array.from({ length: n }, (_, i) => target.start + i * STEP); const cal = x.map(madrid); let t = shorts[0]; root.innerHTML = `

Target data

${mkt.about(fmtDay(cal[0].day), fmtDay(cal[n - 1].day))}

${targetSeg("tg-t", shorts, t)}

Time series

Every quarter-hour of the history. Times in UTC.

${seg("tg-r", [["14", "14 days"], ["90", "90 days"], ["all", "All"]], "90")}
drag to zoom · double-click to reset

Typical patterns

Mean (line) and q10–q90 (band) over the whole history, ${mkt.city} time.

Distribution

Clipped to the 0.5–99.5% range for display.

${scatter ? `

Price vs energy

A random sample of 5,000 quarter-hours.

` : ""}

Per day

${seg("tg-mk", [["miss", "Missing"], ["zero", "Exact zeros"]], "miss")}
`; let range = "90", kind = "miss"; const ts = mount(root.querySelector("#tg-ts"), (w, h) => new uPlot({ width: w, height: h, tzDate: tzUTC, legend: { show: false }, scales: { x: { time: true } }, cursor: { drag: { x: true, y: false }, points: { size: 6, width: 2, fill: css("--surface") }, bind: { dblclick: () => () => { setR(range); return null; } } }, series: [{}, line(LABEL[t], css("--accent-ink"), { width: 1.25 })], axes: axes(`${LABEL[t]} (${meta.units[t]})`), plugins: [tooltip(seriesRows(fmtUTC))], }, [x, target[t]], root.querySelector("#tg-ts")), chartHeight); ts.keepX = true; const setR = r => { range = r; ts.inst.setScale("x", { min: r === "all" ? x[0] : x[n - 1] - +r * 86400, max: x[n - 1] }); }; onSeg(root, "tg-r", setR); function quant(a, q) { if (!a.length) return null; const s = Float64Array.from(a).sort(); const p = (s.length - 1) * q, lo = Math.floor(p); return s[lo] + (s[Math.min(lo + 1, s.length - 1)] - s[lo]) * (p - lo); } function profile(keyFn, keys) { const g = new Map(keys.map(k => [k, []])); target[t].forEach((v, i) => { if (v != null) g.get(keyFn(i))?.push(v); }); return { mean: keys.map(k => mean(g.get(k))), q10: keys.map(k => quant(g.get(k), 0.1)), q90: keys.map(k => quant(g.get(k), 0.9)) }; } const months = [...new Set(cal.map(c => c.month))]; const monthIdx = new Map(months.map((m, i) => [m, i])); const monthName = i => `${MON[+months[i].slice(5) - 1]} ${months[i].slice(0, 4)}`; const PROFILES = [ ["tg-p1", "Quarter-hour of day", i => cal[i].hour * 4 + Math.floor((x[i] % 3600) / 900), Array.from({ length: 96 }, (_, i) => i), i => `${pad(i / 4)}:00`, i => `${pad(Math.floor(i / 4))}:${pad((i % 4) * 15)}`, 16], ["tg-p2", "Weekday", i => cal[i].wd, [0, 1, 2, 3, 4, 5, 6], i => WEEKDAYS[i], i => WEEKDAYS[i], 1], ["tg-p3", "Month", i => monthIdx.get(cal[i].month), months.map((_, i) => i), i => `${MON[+months[i].slice(5) - 1]}\n${months[i].slice(2, 4)}`, monthName, 3], ]; const profCharts = PROFILES.map(([id, title, keyFn, keys, tick, ttl, step]) => mount(root.querySelector(`#${id}`), (w, h) => { const p = profile(keyFn, keys); return new uPlot({ width: w, height: h, title, legend: { show: false }, scales: { x: { time: false } }, cursor: { points: { size: 5, width: 2, fill: css("--surface") } }, series: [{}, { stroke: css("--accent"), width: 1, points: { show: false } }, { stroke: css("--accent"), width: 1, points: { show: false } }, line("Mean", css("--accent-ink"), { width: 2 })], bands: [{ series: [2, 1], fill: css("--band") }], axes: axes("", (u, s) => s.map(i => (Number.isInteger(i) && i in keys ? tick(i) : "")), { space: 20, incrs: [step] }), plugins: [tooltip((u, i) => ttHTML(ttl(i), [[css("--accent-ink"), "Mean", f1(p.mean[i])], [css("--accent"), "q10–q90", `${f1(p.q10[i])} … ${f1(p.q90[i])}`]]))], }, [keys, p.q10, p.q90, p.mean], root.querySelector(`#${id}`)); }, 230)); function stats() { const v = target[t].filter(a => a != null), s = Float64Array.from(v).sort(), m = mean(v); const sd = Math.sqrt(mean(v.map(a => (a - m) ** 2))); root.querySelector("#tg-k").innerHTML = kpi("Mean", f1(m), meta.units[t]) + kpi("Std", f1(sd)) + kpi("Exact zeros", pct(v.filter(a => a === 0).length / v.length)) + kpi("Negative", pct(v.filter(a => a < 0).length / v.length)) + kpi("Min / max", `${minus(Math.round(s[0]))} / ${Math.round(s[s.length - 1])}`); return s; } const hist = mount(root.querySelector("#tg-h"), (w, h) => { const s = stats(), lo = quant(s, 0.005), hi = quant(s, 0.995), bins = 80, width = (hi - lo) / bins; const counts = new Array(bins).fill(0); for (const v of s) counts[Math.min(bins - 1, Math.max(0, Math.floor((Math.min(Math.max(v, lo), hi) - lo) / width)))]++; const centers = counts.map((_, i) => lo + (i + 0.5) * width); return new uPlot({ width: w, height: h, legend: { show: false }, scales: { x: { time: false } }, cursor: { points: { show: false } }, series: [{}, { label: "Quarter-hours", stroke: css("--accent-ink"), fill: css("--band"), paths: uPlot.paths.bars({ size: [0.92, 100] }), points: { show: false } }], axes: axes("Quarter-hours", (u, sp) => sp.map(v => minus(Math.round(v))), { space: 50 }), plugins: [tooltip((u, i) => ttHTML(`${f1(centers[i] - width / 2)} … ${f1(centers[i] + width / 2)}`, [[css("--accent-ink"), "Quarter-hours", counts[i].toLocaleString("en-GB")]]))], }, [centers, counts], root.querySelector("#tg-h")); }, 280); // Scatter on a plain canvas (5,000 points; static). Spain only: price vs energy. const scEl = root.querySelector("#tg-sc"); const pairs = []; if (scatter) for (let i = 0; i < n; i++) if (target.energy[i] != null && target.price[i] != null) pairs.push([target.energy[i], target.price[i]]); let seed = 1; const rnd = () => ((seed = (seed * 16807) % 2147483647) / 2147483647); const sample = Array.from({ length: Math.min(5000, pairs.length) }, () => pairs[Math.floor(rnd() * pairs.length)]); const drawScatter = w => { const dpr = devicePixelRatio || 1, h = 360; scEl.width = w * dpr; scEl.height = h * dpr; const ctx = scEl.getContext("2d"); ctx.scale(dpr, dpr); ctx.clearRect(0, 0, w, h); const xs = sample.map(p => p[0]), ys = sample.map(p => p[1]); const qx = [quant(xs, 0.002), quant(xs, 0.998)], qy = [quant(ys, 0.002), quant(ys, 0.998)]; const L = 58, B = 40, X = v => L + ((v - qx[0]) / (qx[1] - qx[0])) * (w - L - 12), Y = v => h - B - ((v - qy[0]) / (qy[1] - qy[0])) * (h - B - 10); ctx.font = `11px ${css("--mono")}`; ctx.fillStyle = css("--ink-soft"); ctx.strokeStyle = css("--grid"); for (let k = 0; k <= 4; k++) { const vx = qx[0] + ((qx[1] - qx[0]) * k) / 4, vy = qy[0] + ((qy[1] - qy[0]) * k) / 4; ctx.beginPath(); ctx.moveTo(X(vx), 10); ctx.lineTo(X(vx), h - B); ctx.stroke(); ctx.fillText(minus(Math.round(vx)), X(vx) - 14, h - B + 16); ctx.beginPath(); ctx.moveTo(L, Y(vy)); ctx.lineTo(w - 12, Y(vy)); ctx.stroke(); ctx.fillText(minus(Math.round(vy)), 8, Y(vy) + 4); } ctx.font = `12px ${css("--sans")}`; ctx.fillText("Net mFRR energy (MWh)", L, h - 6); ctx.fillStyle = css("--accent-ink"); ctx.globalAlpha = 0.28; for (const [a, b] of sample) if (a >= qx[0] && a <= qx[1] && b >= qy[0] && b <= qy[1]) ctx.fillRect(X(a) - 1.2, Y(b) - 1.2, 2.4, 2.4); ctx.globalAlpha = 1; ctx.fillStyle = css("--ink-soft"); ctx.fillText("Price (EUR/MWh) ↑", L + 6, 22); }; if (scatter) mount(scEl, w => { drawScatter(w); return { destroy() {}, setSize: ({ width }) => drawScatter(width) }; }, 360); function heat() { const per = new Map(); target[t].forEach((v, i) => { const k = cal[i].day; per.set(k, (per.get(k) ?? 0) + (kind === "miss" ? v == null : v === 0)); }); const max = Math.max(1, ...per.values()), total = [...per.values()].reduce((a, b) => a + b, 0); root.querySelector("#tg-ms").textContent = `${kind === "miss" ? "Missing" : "Exactly zero"} quarter-hours per day: ${total.toLocaleString("en-GB")} of ${n.toLocaleString("en-GB")} (${pct(total / n)}).${t === "energy" && kind === "miss" ? " Energy gaps were filled with 0 upstream: use Exact zeros to see them." : ""}`; let html = `${Array.from({ length: 31 }, (_, d) => `${d % 5 === 0 ? d + 1 : ""}`).join("")}`; for (const m of months) { html += `${MON[+m.slice(5) - 1]} ${m.slice(2, 4)}`; for (let d = 1; d <= 31; d++) { const k = `${m}-${pad(d)}`, v = per.get(k); html += v == null ? `
` : `
`; } } root.querySelector("#tg-heat").innerHTML = html; } heat(); setR(range); onSeg(root, "tg-mk", v => { kind = v; heat(); }); onSeg(root, "tg-t", v => { t = v; heat(); rebuild(ts); setR(range); profCharts.forEach(rebuild); rebuild(hist); }); } // --- Input features ---------------------------------------------------------------------- async function renderInputs(root) { const cat = await json("catalog.json"), used = await liveFeatures(mk()); const groups = new Set(cat.flatMap(r => (r.group ? r.group.split(", ") : []))); const cats = [...new Set(cat.map(r => r.category))].map(c => ({ c, n: cat.filter(r => r.category === c).length, used: cat.filter(r => r.category === c && r.used).length })).sort((a, b) => b.used - a.used || b.n - a.n); root.innerHTML = `

Input features

Every series we could feed a model. ESIOS serves indicators (time series), offer indicators (bid curves) and archives (bulk files). Calendar columns are computed. Used marks series in a feature group of configs/groups.toml; availability future = known for the target day before the gate, past = only known up to the forecast origin. Categories come from keyword rules on the English name, so a few rows may sit in the wrong bucket.

${used.size ? `

Used by the live model

The ${used.size} input columns of the latest live run (besides the target's own history).

${[...used].sort().map(f => `${esc(f)}`).join("")}
` : ""}
${kpi("Series", cat.length.toLocaleString("en-GB"))}${kpi("Used", String(cat.filter(r => r.used).length))}${kpi("Feature groups", String(groups.size))}

Catalog

`; let limit = 200; const draw = () => { const c = root.querySelector("#in-c").value, u = root.querySelector("#in-u").checked, q = root.querySelector("#in-q").value.trim().toLowerCase(); const rows = cat.filter(r => (!c || r.category === c) && (!u || r.used) && (!q || [r.name, r.name_es, r.description].some(s => (s ?? "").toLowerCase().includes(q)) || String(r.id) === q)); root.querySelector("#in-n").textContent = `${rows.length.toLocaleString("en-GB")} of ${cat.length.toLocaleString("en-GB")} series`; root.querySelector("#in-more").hidden = rows.length <= limit; root.querySelector("#in-t").innerHTML = `${rows.slice(0, limit).map(r => ``).join("")}
UsedCategorySourceIDNameGroupAvailabilityColumnsDescription
${r.used ? 'used' : ""}${esc(r.category)}${r.subcategory ? `
${esc(r.subcategory)}` : ""}
${esc(r.source)}${esc(r.id)}${esc(r.name)}${r.area ? `
${esc(r.area)}` : ""}
${esc(r.group)}${esc(r.availability)}${esc(r.column)}${esc(r.description)}
`; }; ["in-c", "in-u"].forEach(id => root.querySelector(`#${id}`).addEventListener("change", draw)); root.querySelector("#in-q").addEventListener("input", draw); root.querySelector("#in-more").addEventListener("click", () => { limit = Infinity; draw(); }); draw(); } // Feature columns the latest live run of each of the market's targets used (live.json). async function liveFeatures(m) { const [live, meta] = await Promise.all([json("live.json").catch(() => null), json("meta.json")]), out = new Set(); for (const t of shortsOf(m, meta)) for (const f of live?.targets?.[t]?.features ?? []) out.add(f); return out; } // Outside Spain: the market's feature columns from configs/groups.toml (build.py writes them), // and a map of the weather points with their weights where the market reads Open-Meteo. async function renderFeatures(root) { const m = mk(), rows = (await json("features.json"))[m.id], used = await liveFeatures(m); const geo = (await json("geo.json").catch(() => ({})))[m.id]; const wx = (await json("weather.json").catch(() => ({})))[m.id]; root.innerHTML = `

Input features

The columns the ${esc(m.name)} models see, one line each in configs/groups.toml. Availability future = known for the target day before the gate, past = only known up to the forecast origin. Live marks the columns the latest live run used.

${geo ? `

Weather sampling

${geo.sets.map(s => `${s.points.length} points (${s.weighted ? "weighted by PV capacity; dot size = weight" : "plain mean"}): ${s.runs.join(" and ")} run of D-1`).join(" · ")}. Outline: ${esc(geo.label)}.

Boundaries: ${esc(geo.credit)}.

` : ""} ${wx ? weatherTimeline(wx, m) : ""}

Feature columns

${rows.length} columns · ${rows.filter(r => used.has(r.column)).length} in the latest live run

${rows.map(r => ``).join("")}
LiveGroupColumnSourceAvailabilityDescription
${used.has(r.column) ? 'live' : ""}${esc(r.group)}${esc(r.column)}${esc(r.source)}${esc(r.availability)}${esc(r.description)}
`; // In the chart registry, so a theme switch redraws it in the new colours. if (geo && window.L) mount(root.querySelector("#ft-map"), () => drawMap(root.querySelector("#ft-map"), geo, CITIES[m.c] ?? []), 440); } // A few major cities as labels on the plain map. const CITIES = { be: [["Brussels", 50.85, 4.35], ["Antwerp", 51.22, 4.40], ["Ghent", 51.05, 3.72], ["Liège", 50.63, 5.57], ["Charleroi", 50.41, 4.44]], de: [["Berlin", 52.52, 13.40], ["Hamburg", 53.55, 9.99], ["Leipzig", 51.34, 12.37], ["Dresden", 51.05, 13.74], ["Rostock", 54.09, 12.10]], }; function drawMap(el, geo, cities) { const map = L.map(el, { scrollWheelZoom: false, attributionControl: false }); const regions = L.geoJSON(geo.regions, { style: { color: css("--accent-ink"), weight: 1.5, fillColor: css("--accent"), fillOpacity: 0.12 }, onEachFeature: (f, layer) => layer.bindTooltip(esc(f.properties.name)), }); const bounds = regions.getBounds(); for (const s of geo.sets) for (const [lat, lon] of s.points) bounds.extend([lat, lon]); map.fitBounds(bounds.pad(0.05)); // view first: vector layers added to a map without one throw // No tiles: the country on the grey background, the regions we use, a few cities. if (geo.country) L.geoJSON(geo.country, { interactive: false, style: { color: css("--ink-soft"), weight: 1.5, fillColor: css("--surface"), fillOpacity: 1 } }).addTo(map); regions.addTo(map); for (const [name, lat, lon] of cities) L.marker([lat, lon], { icon: L.divIcon({ className: "city", html: `${esc(name)}`, iconSize: null, iconAnchor: [3, 8] }), interactive: false, keyboard: false }).addTo(map); for (const s of geo.sets) for (const [lat, lon, w] of s.points) { const r = s.weighted ? 5 + Math.sqrt(w) * 30 : 7; L.circleMarker([lat, lon], { radius: r, color: css("--surface"), weight: 2, fillColor: css("--tso"), fillOpacity: 0.9 }) .bindTooltip(`${lat.toFixed(2)}, ${lon.toFixed(2)}${s.weighted ? ` · weight ${(w * 100).toFixed(1)}%` : ""}
${s.runs.join(", ")}`) .addTo(map); } return { destroy: () => map.remove(), setSize: () => map.invalidateSize() }; } // --- Weather runs timeline (Input features, targets that read Open-Meteo) ------------------- // One row per weather model: each archived run as a bar from init to when it is on the API // (openmeteo.LATENCY), the run we read highlighted; origin, submit and gate as vertical lines. // Intraday: the target day, no chosen run yet, a gate every hour. The axis is in the market's // local time, like the origin and gate; runs keep their UTC names in the hover text and table. function weatherTimeline(w, m) { const intraday = !!m.intraday, H = 3600, OTHER = "color-mix(in srgb, var(--ink-soft) 40%, transparent)"; const t0 = intraday ? w.day_start : Math.min(...w.models.map(r => r.used)) - 6 * H; const t1 = intraday ? w.day_end : w.gate + 2 * H; const L = 150, R = 20, W = 900, rowH = 30, top = 22, n = w.models.length, plotH = n * rowH, Hh = top + plotH + 30; const X = s => L + ((s - t0) / (t1 - t0)) * (W - L - R); const hm = s => { const d = new Date(s * 1000); return `${pad(d.getUTCHours())}:${pad(d.getUTCMinutes())}`; }; const local = new Intl.DateTimeFormat("en-GB", { timeZone: m.tz, hour: "2-digit", minute: "2-digit", hourCycle: "h23" }); const loc = s => local.format(new Date(s * 1000)); const date = new Intl.DateTimeFormat("en-GB", { timeZone: m.tz, day: "numeric", month: "short" }); const dur = s => `${Math.floor(s / H)}h${pad(Math.round((s % H) / 60))}`; // ponytail: one UTC offset for the whole window (no DST switch inside it). const utc = new Intl.DateTimeFormat("en-GB", { timeZone: m.tz, timeZoneName: "shortOffset" }).formatToParts(new Date(t0 * 1000)).find(p => p.type === "timeZoneName").value.replace("GMT", "UTC"); const off = (+utc.slice(3) || 0) * H, city = m.city, zone = `${city} time (${utc})`; let svg = `${esc(zone)}`; for (let s = Math.ceil((t0 + off) / (3 * H)) * 3 * H - off; s <= t1; s += 3 * H) { // grid every 3 local hours svg += ``; svg += `${loc(s)}`; if (loc(s) === "00:00") svg += `${date.format(new Date(s * 1000))}`; } w.models.forEach((r, i) => { const y = top + i * rowH + rowH / 2; svg += `${esc(r.name)}`; const inits = []; for (let s = Math.floor((t0 - r.latency) / r.cycle) * r.cycle; s < t1; s += r.cycle) inits.push(s); inits.sort((p, q) => (p === r.used) - (q === r.used)); // the run we read drawn last, on top // A run slower than the cycle (IFS: out 6h40 after init, every 6 h) overlaps the next one: // alternate lanes so each bar keeps its own end. const lanes = Math.ceil(r.latency / r.cycle); for (const s of inits) { const a = Math.max(s, t0), b = Math.min(s + r.latency, t1), used = !intraday && s === r.used; if (b <= a) continue; const yl = y + (lanes > 1 ? ((Math.round(s / r.cycle) % lanes) - (lanes - 1) / 2) * 9 : 0); const title = `${r.name} ${hm(s)} UTC run (${loc(s)} ${city}): on Open-Meteo ~${loc(s + r.latency)} ${city} (${hm(s + r.latency)} UTC), ${dur(r.latency)} after init${used ? "; the run we read" : ""}`; svg += `${esc(title)}`; if (s + r.latency <= t1) svg += ``; svg += ``; } }); const vline = (s, color, dash, label) => `${esc(label)}`; if (intraday) for (let s = Math.ceil(t0 / H) * H; s < t1; s += H) svg += vline(s, "var(--ink-soft)", "2 3", `Hourly intraday gate ${loc(s)} ${m.city}`); else { svg += vline(w.origin, "var(--base)", "6 4", `Origin ${loc(w.origin)} ${m.city} (${hm(w.origin)} UTC)`); svg += vline(w.submit, "var(--cont)", "2 3", `Live run ${loc(w.submit)} ${m.city} (${hm(w.submit)} UTC)`); svg += vline(w.gate, "var(--ink)", "", `Predico gate ${loc(w.gate)} ${m.city} (${hm(w.gate)} UTC)`); } const legend = intraday ? `run: init → on Open-Meteohourly intraday gates` : `run we readother runs: init → on Open-Meteoorigin ${loc(w.origin)} ${m.city}live run ${loc(w.submit)}Predico gate ${loc(w.gate)} ${m.city}`; const rows = w.models.map(r => { const runs = Array.from({ length: 24 / (r.cycle / H) }, (_, k) => pad((k * r.cycle) / H)).join(", "); return `${esc(r.name)}${runs}${dur(r.latency)}${intraday ? `not chosen yet` : `${hm(r.used)} UTC, ${fmtDay(new Date(r.used * 1000).toISOString().slice(0, 10))}${loc(r.used + r.latency)}${dur(w.origin - r.used - r.latency)}`}`; }).join(""); return `

Weather runs and gates

${intraday ? `Today (${fmtDay(w.day)}), chart in ${esc(zone)}. Each archived run from init to when Open-Meteo serves it; Predico's intraday sessions close every hour. Which run the intraday forecasts read is not decided yet.` : `For tomorrow's session (D-1 = ${fmtDay(w.day)}), chart in ${esc(zone)}; runs keep their UTC names. Each archived run from init to when Open-Meteo serves it (typical delays, measured Nov 2026); the run we read is one that is out well before the ${loc(w.origin)} ${m.city} origin, the same in the backtest and live. Hover a bar for its times.`}

${svg}
${legend}
${intraday ? "" : ``}${rows}
ModelRuns (UTC)Out afterRun we readOut at (${esc(city)})Margin to origin
`; } // --- Countries and variables (Predico resources) ------------------------------------------- // data: build.py MARKETS key (target/.json, features.json, geo.json, weather.json). // city/tz/gateLocal/source/missingTruth/about: tab texts. const de50Hertz = what => (from, to) => `The truth series from v2/target_50hertz.parquet: ENTSO-E actual generation, ${what}, 50Hertz control area, MW (mean per quarter-hour), 15-min, ${from} – ${to}. As Predico does, points the curve omits repeat the previous value (curve type A03), each series before summing.`; const COUNTRIES = [ { id: "es", name: "Spain", program: "EDP", data: "es-mfrr", catalog: true, city: "Madrid", tz: "Europe/Madrid", gateLocal: "17:00 Madrid on D-1", source: "ESIOS", missingTruth: "Quarter-hours without truth (no mFRR activation, so no price) are left out.", about: (from, to) => `The truth series from v1/target.parquet: mFRR activated energy (net, MWh per quarter-hour, upward positive) and mFRR price (EUR/MWh), Spain, 15-min, ${from} – ${to}. Missing energy is filled with 0 (no activation); missing price stays empty. No data during the Iberian blackout (28 Apr – 6 May 2025). Prices rise from Jul 2026 (monthly mean ~100 → ~157 EUR/MWh).`, vars: [{ id: "energy", name: "mFRR energy", resource: "spain_mfrr_energy" }, { id: "price", name: "mFRR price", resource: "spain_mfrr_price" }] }, { id: "de", name: "Germany", program: "50Hertz", city: "Berlin", tz: "Europe/Berlin", gateLocal: "15:00 Berlin on D-1", source: "ENTSO-E", missingTruth: "", vars: [ { id: "wind", name: "Wind", resource: "germany_wind_50hertz_ca", data: "de-wind", about: de50Hertz("wind offshore + onshore (A75 B18 + B19)") }, { id: "solar", name: "Solar", resource: "germany_solar_50hertz_ca", data: "de-solar", about: de50Hertz("solar (A75 B16)") }, ] }, { id: "be", name: "Belgium", program: "Elia", data: "be-solar", city: "Brussels", tz: "Europe/Brussels", gateLocal: "10:00 Brussels on D-1", source: "Elia", missingTruth: "", about: (from, to) => `The truth series from target_elia.parquet: Elia's measured PV generation, Belgium total (TSO + DSO connected), MW (mean per quarter-hour), 15-min, ${from} – ${to}. Elia dataset ods032 up to 25 Oct 2026, then ods209 (and ods210 for the latest hours), as Predico scores it. The same series scores the D+1 and the intraday sessions.`, vars: [ { id: "solar", name: "Solar D+1", resource: "belgium_solar_opendata_elia" }, { id: "solar-intraday", name: "Solar intraday", resource: "belgium_solar_opendata_elia", intraday: true, gateLocal: "every hour, intraday" }, ] }, ]; const TABS = { live: renderLive, backtest: renderBacktest, target: renderTarget, inputs: root => (mk().catalog ? renderInputs : renderFeatures)(root) }; const TAB_NAMES = { live: "Live", backtest: "Backtest", target: "Target data", inputs: "Input features" }; const saved = (() => { try { return JSON.parse(localStorage.getItem("sel")) ?? {}; } catch { return {}; } })(); let sel = { c: "es", v: "energy", tab: "live" }; // Hash: #//
; missing parts fall back to the last choice. function parseHash() { const [a, b, c] = location.hash.slice(1).split("/"); if (TABS[a]) return { ...sel, ...saved, tab: a }; // old links: #live, #backtest, ... const C = COUNTRIES.find(x => x.id === a) ?? COUNTRIES.find(x => x.id === saved.c) ?? COUNTRIES[0]; const V = C.vars.find(x => x.id === b) ?? C.vars.find(x => x.id === saved.v) ?? C.vars[0]; return { c: C.id, v: V.id, tab: TABS[c] ? c : TABS[saved.tab] ? saved.tab : "live" }; } const href = (c, v, tab) => `#${c}/${v}/${tab}`; // Live and backtest of the intraday sessions: not wired yet, say so without inventing data. function intradaySoon(root, tab) { const m = mk(); root.innerHTML = `

${esc(TAB_NAMES[tab])}: ${esc(m.name)}

being added

Predico's Elia program also runs hourly intraday sessions for Belgian solar, with challenges that start the same day. Our hourly intraday submissions are being added; the D+1 forecast does not cover them. ${tab === "live" ? "Their forecasts appear here after each gate, once they run." : "A backtest follows once the intraday runs exist."}

Predico resource
${esc(m.resource)}
Gates
every hour, intraday
Truth
Elia Open Data, Belgium total (same as D+1)
Benchmark
Elia's most recent forecast (mostrecentforecast in ods032/ods209/ods210)

Target data and input features (with the weather runs against the hourly gates) are the D+1 ones.

`; } function drawNav() { const C = COUNTRIES.find(x => x.id === sel.c); document.getElementById("countries").innerHTML = COUNTRIES.map(c => `${esc(c.name)}`).join(""); document.getElementById("vars").innerHTML = C.vars.map(v => `${esc(v.name)}`).join(""); document.getElementById("sections").innerHTML = Object.entries(TAB_NAMES).map(([k, l]) => `${esc(l)}`).join(""); } function show() { sel = parseHash(); try { localStorage.setItem("sel", JSON.stringify(sel)); } catch {} drawNav(); const tab = sel.tab; document.querySelectorAll("section[data-tab]").forEach(s => (s.hidden = s.dataset.tab !== tab)); const root = document.getElementById(`tab-${tab}`), key = `${sel.c}/${sel.v}`; if (root.dataset.key === key) return; root.dataset.key = key; if (mk().intraday && (tab === "live" || tab === "backtest")) return intradaySoon(root, tab); root.innerHTML = `

Loading…

`; TABS[tab](root).catch(e => { root.innerHTML = `

Could not load this tab: ${esc(e.message)}

`; console.error(e); }); } addEventListener("hashchange", show); (document.fonts?.ready ?? Promise.resolve()).then(show);