Files
web-nuxt/app/pages/playground.vue
T
2026-11-14 21:07:06 +01:00

1001 lines
47 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
import { SCENARIO_PRESETS } from '#shared/scenarios'
import type {
Horizon,
MetaResponse,
PlaygroundForecastResponse,
Point,
Scenario,
ScenarioPreset,
Sensor,
SeriesResponse,
} from '#shared/types'
import { apiErrorMessage } from '~/utils/api-error'
import {
formatDate,
formatDateTime,
formatNumber,
formatPercent,
formatShortDate,
formatWeekdayShort,
} from '~/utils/format'
import {
buildHeatmap,
formatBand,
scenarioDelta,
summarizeForecast,
} from '~/utils/playground'
const DEFAULT_SENSOR = 'hn-stadtgalerie-01'
const DEFAULT_HORIZON: Horizon = '48h'
const DEFAULT_SCENARIO: Scenario = 'base'
const DEFAULT_TEMP_C = 22
const DEFAULT_PRECIP_MM = 0
const HORIZON_OPTIONS: Horizon[] = ['15m', '1h', '48h', '7d']
const sensorId = ref(DEFAULT_SENSOR)
const horizon = ref<Horizon>(DEFAULT_HORIZON)
const scenario = ref<Scenario>(DEFAULT_SCENARIO)
const tempOverride = ref(false)
const tempC = ref(DEFAULT_TEMP_C)
const precipOverride = ref(false)
const precipMm = ref(DEFAULT_PRECIP_MM)
const holiday = ref(false)
const {
data: sensors,
error: sensorsError,
} = await useFetch<Sensor[]>('/api/sensors', { key: 'playground-sensors' })
const { data: presets } = await useFetch<ScenarioPreset[]>('/api/scenarios', {
key: 'playground-scenarios',
})
const {
data: meta,
error: metaError,
refresh: refreshMeta,
pending: metaPending,
} = await useFetch<MetaResponse>('/api/meta', { key: 'playground-meta' })
if (sensors.value?.length && !sensors.value.some((sensor) => sensor.id === sensorId.value)) {
sensorId.value = sensors.value[0]!.id
}
function buildQuery(target: {
sensor: string
horizon: Horizon
scenario: Scenario
}): Record<string, string | number | boolean> {
const query: Record<string, string | number | boolean> = { ...target }
if (tempOverride.value) query.temp_c = tempC.value
if (precipOverride.value) query.precip_mm = precipMm.value
if (holiday.value) query.is_holiday = true
return query
}
interface InitialPlayground {
forecast: PlaygroundForecastResponse
observed: Point[]
observedError: string
}
const initialQuery = buildQuery({
sensor: sensorId.value,
horizon: DEFAULT_HORIZON,
scenario: DEFAULT_SCENARIO,
})
const {
data: initial,
error: initialError,
} = await useAsyncData<InitialPlayground>('playground-initial', async () => {
const [forecastResult, seriesResult] = await Promise.allSettled([
$fetch<PlaygroundForecastResponse>('/api/playground', { query: initialQuery }),
$fetch<SeriesResponse>('/api/series', {
query: { sensor: sensorId.value, step: '1h' },
}),
])
if (forecastResult.status === 'rejected') throw forecastResult.reason
return {
forecast: forecastResult.value,
observed: seriesResult.status === 'fulfilled' ? seriesResult.value.points : [],
observedError:
seriesResult.status === 'rejected'
? apiErrorMessage(seriesResult.reason, 'Observed series unavailable.')
: '',
}
})
const result = ref<PlaygroundForecastResponse | null>(initial.value?.forecast ?? null)
const observedPoints = ref<Point[]>(initial.value?.observed ?? [])
const observedError = ref(initial.value?.observedError ?? '')
const comparisonBase = ref<PlaygroundForecastResponse | null>(null)
const comparisonError = ref('')
const loading = ref(false)
const errorMessage = ref(
initialError.value
? apiErrorMessage(
initialError.value,
'The playground forecast is unavailable. Start the Go and Python services and retry.',
)
: '',
)
const presetList = computed(() =>
presets.value?.length ? presets.value : SCENARIO_PRESETS,
)
function scenarioLabel(id: Scenario | undefined): string {
if (!id) return '—'
return presetList.value.find((preset) => preset.id === id)?.label ?? id
}
const resultSensorName = computed(
() =>
sensors.value?.find((sensor) => sensor.id === result.value?.sensor)?.name ??
result.value?.sensor ??
'—',
)
const summary = computed(() => summarizeForecast(result.value?.points ?? []))
const baseSummary = computed(() =>
comparisonBase.value ? summarizeForecast(comparisonBase.value.points) : null,
)
const delta = computed(() =>
baseSummary.value ? scenarioDelta(summary.value, baseSummary.value) : null,
)
const heatmap = computed(() => buildHeatmap(result.value?.points ?? []))
const isBaseScenario = computed(() => result.value?.scenario === 'base')
const interpolated = computed(
() => result.value?.horizon === '15m' || result.value?.horizon === '1h',
)
const weatherSourceLabel = computed(() =>
result.value?.weather_source === 'override' ? 'Your weather override' : 'Forecast weather',
)
const holidayForced = computed(() => result.value?.request?.is_holiday === true)
const observedWindow = computed(() => {
const cutoff = Date.parse(result.value?.points[0]?.t ?? '')
const sorted = [...observedPoints.value].sort(
(a, b) => Date.parse(a.t) - Date.parse(b.t),
)
const before = Number.isFinite(cutoff)
? sorted.filter((point) => Date.parse(point.t) < cutoff)
: sorted
const last = before.at(-1)
if (!last || !Number.isFinite(cutoff)) return []
// Only draw observed history when it is contiguous with the forecast start.
// A multi-day gap would make the chart look like a continuous signal.
if (cutoff - Date.parse(last.t) > 24 * 60 * 60 * 1000) return []
return before.slice(-24)
})
const comparisonRows = computed(() => {
if (!comparisonBase.value || !baseSummary.value) return []
const selectedPeak = summary.value.peak?.v ?? 0
const basePeak = baseSummary.value.peak?.v ?? 0
const selectedMean = summary.value.mean
const baseMean = baseSummary.value.mean
return [
{
label: 'Peak devices/hour',
selected: selectedPeak,
base: basePeak,
max: Math.max(selectedPeak, basePeak, 1),
delta: delta.value?.peakDelta ?? 0,
pct: delta.value?.peakDeltaPct ?? null,
},
{
label: 'Mean devices/hour',
selected: selectedMean,
base: baseMean,
max: Math.max(selectedMean, baseMean, 1),
delta: delta.value?.meanDelta ?? 0,
pct: delta.value?.meanDeltaPct ?? null,
},
]
})
const metaErrorMessage = computed(() =>
metaError.value ? apiErrorMessage(metaError.value, 'Model metadata is unavailable.') : '',
)
const sensorsMessage = computed(() =>
sensorsError.value
? apiErrorMessage(sensorsError.value, 'The sensor list is unavailable.')
: '',
)
const statusMessage = computed(() => {
if (loading.value) return 'Running the live forecast model.'
if (errorMessage.value) return 'The latest run failed.'
if (!result.value) return 'No forecast loaded yet.'
return `${summary.value.count} forecast points loaded.`
})
function signed(value: number, suffix = ''): string {
const rounded = Math.round(value * 10) / 10
if (rounded === 0) return `0${suffix}`
return `${rounded > 0 ? '+' : ''}${formatNumber(rounded)}${suffix}`
}
async function run() {
if (loading.value) return
loading.value = true
errorMessage.value = ''
comparisonError.value = ''
const target = {
sensor: sensorId.value,
horizon: horizon.value,
scenario: scenario.value,
}
try {
const [selectedResult, seriesResult, baseResult] = await Promise.allSettled([
$fetch<PlaygroundForecastResponse>('/api/playground', {
query: buildQuery(target),
}),
$fetch<SeriesResponse>('/api/series', {
query: { sensor: target.sensor, step: '1h' },
}),
target.scenario === 'base'
? Promise.resolve<PlaygroundForecastResponse | null>(null)
: $fetch<PlaygroundForecastResponse>('/api/playground', {
query: buildQuery({ ...target, scenario: 'base' }),
}),
])
if (selectedResult.status === 'rejected') {
errorMessage.value = apiErrorMessage(
selectedResult.reason,
'The forecast API could not complete this run.',
)
return
}
result.value = selectedResult.value
if (seriesResult.status === 'fulfilled') {
observedPoints.value = seriesResult.value.points
observedError.value = ''
} else {
observedPoints.value = []
observedError.value = apiErrorMessage(
seriesResult.reason,
'Observed series unavailable.',
)
}
if (baseResult.status === 'fulfilled' && baseResult.value) {
comparisonBase.value = baseResult.value
} else {
comparisonBase.value = null
if (baseResult.status === 'rejected') {
comparisonError.value = apiErrorMessage(
baseResult.reason,
'The base comparison is unavailable.',
)
}
}
} finally {
loading.value = false
}
}
function resetDefaults() {
sensorId.value = sensors.value?.some((sensor) => sensor.id === DEFAULT_SENSOR)
? DEFAULT_SENSOR
: sensors.value?.[0]?.id ?? DEFAULT_SENSOR
horizon.value = DEFAULT_HORIZON
scenario.value = DEFAULT_SCENARIO
tempOverride.value = false
tempC.value = DEFAULT_TEMP_C
precipOverride.value = false
precipMm.value = DEFAULT_PRECIP_MM
holiday.value = false
comparisonBase.value = null
comparisonError.value = ''
void run()
}
</script>
<template>
<div class="min-h-dvh flex flex-col">
<main class="w-full flex-1 pt-16 bg-[#081723]">
<div class="max-w-[1200px] w-full mx-auto px-margin-desktop py-space-2xl flex flex-col gap-space-2xl">
<header class="flex flex-col gap-space-sm max-w-3xl">
<div class="flex flex-wrap items-center gap-space-sm">
<span class="font-label-sm text-[11px] leading-none tracking-[0.12em] text-[#00C3CD] uppercase font-semibold">
Section 04 / Interactive simulation
</span>
<span class="w-1.5 h-1.5 rounded-full bg-[#334e68]"></span>
<span class="inline-flex items-center gap-1.5 rounded-full bg-[#00C3CD]/10 border border-[#00C3CD]/25 px-2.5 py-1 font-label-sm text-[10px] leading-none text-[#00C3CD]">
<span class="w-1.5 h-1.5 rounded-full bg-[#00C3CD] animate-pulse"></span>
Live model inference
</span>
</div>
<h1 class="text-[32px] leading-[38px] sm:text-[44px] sm:leading-[50px] tracking-[-0.03em] font-semibold text-[#FFFFFF]">
Run the engine yourself.
</h1>
<p class="font-body-lg text-[16px] leading-relaxed text-[#94A3B8]">
Pick a sensor, horizon and scenario, then override the weather. Every point, band,
peak and version below is returned by the live forecast API or computed from its points.
</p>
</header>
<div class="grid grid-cols-1 lg:grid-cols-12 gap-gutter-desktop items-start">
<!-- Controls -->
<section
aria-labelledby="playground-controls-heading"
class="lg:col-span-4 min-w-0 flex flex-col gap-space-lg bg-[#0e2233] border border-[#1e3a52] rounded-xl p-space-lg shadow-sm"
>
<div class="flex items-center justify-between gap-2">
<div class="flex items-center gap-2 min-w-0">
<Icon name="material-symbols:tune" class="text-[20px] text-[#00C3CD] shrink-0" />
<h2 id="playground-controls-heading" class="font-headline-sm text-[16px] text-[#FFFFFF] font-semibold">
Simulation controls
</h2>
</div>
<button
type="button"
class="inline-flex items-center gap-1 font-label-sm text-[11px] text-[#94A3B8] hover:text-[#00C3CD] transition-colors disabled:opacity-50"
:disabled="loading"
@click="resetDefaults"
>
<Icon name="material-symbols:restart-alt" class="text-[15px]" />
Reset defaults
</button>
</div>
<p v-if="sensorsMessage" class="text-[10px] leading-snug text-[#fbbf24]">
{{ sensorsMessage }} Using {{ sensorId }}.
</p>
<div class="flex flex-col gap-space-md">
<div class="flex flex-col gap-1.5">
<label for="playground-sensor" class="font-label-sm text-[11px] text-[#94A3B8] uppercase tracking-wider">
Sensor
</label>
<select
id="playground-sensor"
v-model="sensorId"
class="w-full h-10 rounded-lg bg-[#132b40] border border-[#1e3a52] px-3 font-body-md text-[13px] text-[#FFFFFF] focus:outline-none focus:border-[#00C3CD] focus:ring-1 focus:ring-[#00C3CD] [color-scheme:dark]"
>
<option
v-for="sensor in sensors ?? []"
:key="sensor.id"
:value="sensor.id"
>
{{ sensor.name }}
</option>
<option v-if="!sensors?.length" :value="DEFAULT_SENSOR">
{{ DEFAULT_SENSOR }}
</option>
</select>
</div>
<fieldset class="flex flex-col gap-1.5">
<legend class="font-label-sm text-[11px] text-[#94A3B8] uppercase tracking-wider mb-1.5">
Horizon
</legend>
<div class="grid grid-cols-4 gap-1 bg-[#081723] p-1 rounded-lg border border-[#1e3a52]">
<button
v-for="option in HORIZON_OPTIONS"
:key="option"
type="button"
class="py-1.5 rounded font-label-sm text-[11px] transition-all focus:outline-none focus-visible:ring-1 focus-visible:ring-[#00C3CD]"
:class="
horizon === option
? 'bg-[#132b40] text-[#00C3CD] font-semibold border border-[#00C3CD]/30'
: 'text-[#94A3B8] hover:text-[#FFFFFF] border border-transparent'
"
:aria-pressed="horizon === option"
@click="horizon = option"
>
{{ option }}
</button>
</div>
</fieldset>
<div class="flex flex-col gap-1.5">
<label for="playground-scenario" class="font-label-sm text-[11px] text-[#94A3B8] uppercase tracking-wider">
Scenario
</label>
<select
id="playground-scenario"
v-model="scenario"
class="w-full h-10 rounded-lg bg-[#132b40] border border-[#1e3a52] px-3 font-body-md text-[13px] text-[#FFFFFF] focus:outline-none focus:border-[#00C3CD] focus:ring-1 focus:ring-[#00C3CD] [color-scheme:dark]"
>
<option v-for="preset in presetList" :key="preset.id" :value="preset.id">
{{ preset.label }}
</option>
</select>
</div>
<div class="flex flex-col gap-2 bg-[#132b40] border border-[#1e3a52] p-space-md rounded-lg">
<div class="flex items-center justify-between gap-2">
<label for="playground-temp-toggle" class="inline-flex items-center gap-2 font-label-sm text-[11px] text-[#94A3B8] cursor-pointer">
<input
id="playground-temp-toggle"
v-model="tempOverride"
type="checkbox"
class="h-4 w-4 accent-[#00C3CD] rounded border-[#1e3a52]"
/>
Override temperature
</label>
<span class="font-tabular-stat-md text-[13px] font-semibold text-[#00C3CD]">
{{ tempOverride ? `${tempC}°C` : 'Forecast' }}
</span>
</div>
<input
v-model.number="tempC"
type="range"
min="10"
max="35"
step="1"
:disabled="!tempOverride"
class="w-full h-1.5 accent-[#00C3CD] cursor-pointer disabled:opacity-35 disabled:cursor-not-allowed"
aria-label="Temperature override in degrees Celsius"
/>
<p class="text-[10px] leading-snug text-[#64748B]">
When off, the API uses its baked hourly weather forecast.
</p>
</div>
<div class="flex flex-col gap-2 bg-[#132b40] border border-[#1e3a52] p-space-md rounded-lg">
<div class="flex items-center justify-between gap-2">
<label for="playground-rain-toggle" class="inline-flex items-center gap-2 font-label-sm text-[11px] text-[#94A3B8] cursor-pointer">
<input
id="playground-rain-toggle"
v-model="precipOverride"
type="checkbox"
class="h-4 w-4 accent-[#00C3CD] rounded border-[#1e3a52]"
/>
Override rain
</label>
<span class="font-tabular-stat-md text-[13px] font-semibold text-[#00C3CD]">
{{ precipOverride ? `${precipMm} mm` : 'Forecast' }}
</span>
</div>
<input
v-model.number="precipMm"
type="range"
min="0"
max="10"
step="0.5"
:disabled="!precipOverride"
class="w-full h-1.5 accent-[#00C3CD] cursor-pointer disabled:opacity-35 disabled:cursor-not-allowed"
aria-label="Rain override in millimetres"
/>
<p class="text-[10px] leading-snug text-[#64748B]">
When off, the API uses its baked hourly weather forecast.
</p>
</div>
<label class="inline-flex items-start gap-2 font-label-sm text-[11px] leading-snug text-[#94A3B8] cursor-pointer">
<input
v-model="holiday"
type="checkbox"
class="mt-0.5 h-4 w-4 accent-[#00C3CD] rounded border-[#1e3a52]"
/>
Force public-holiday flag
</label>
</div>
<button
type="button"
class="w-full h-11 px-4 rounded-lg bg-[#00C3CD] hover:bg-[#3ddae4] text-[#081723] transition-all flex items-center justify-center gap-2 font-label-md text-[13px] font-bold shadow-md active:scale-[0.99] disabled:opacity-60 disabled:cursor-wait"
:disabled="loading"
@click="run"
>
<Icon
:name="loading ? 'material-symbols:progress-activity' : 'material-symbols:bolt'"
class="text-[18px]"
:class="loading ? 'animate-spin' : ''"
/>
{{ loading ? 'Running forecast…' : 'Run forecast' }}
</button>
<p class="flex items-center gap-1.5 text-[10px] leading-snug text-[#94A3B8] border-t border-[#1e3a52]/70 pt-space-sm">
<Icon name="material-symbols:verified" class="text-[14px] text-[#00C3CD] shrink-0" />
Live model · aggregate counts · no identifiers
</p>
</section>
<!-- Results -->
<section class="lg:col-span-8 min-w-0 flex flex-col gap-space-lg">
<p class="sr-only" role="status" aria-live="polite">{{ statusMessage }}</p>
<div
v-if="loading"
class="flex items-center gap-2 rounded-lg border border-[#00C3CD]/30 bg-[#00C3CD]/[0.06] px-space-md py-2.5 text-[12px] text-[#00C3CD]"
role="status"
>
<Icon name="material-symbols:progress-activity" class="text-[16px] animate-spin shrink-0" />
Running the live forecast model…
</div>
<div
v-if="errorMessage"
class="flex items-start gap-3 rounded-lg border border-[#fbbf24]/40 bg-[#fbbf24]/10 px-space-md py-3 text-[12px] text-[#fde68a]"
role="alert"
>
<Icon name="material-symbols:error" class="text-[18px] shrink-0 mt-0.5" />
<div class="min-w-0 flex-1">
<p class="font-semibold text-[#FFFFFF]">The forecast could not be completed.</p>
<p class="mt-0.5 leading-relaxed break-words">{{ errorMessage }}</p>
<p v-if="result" class="mt-1 text-[11px] text-[#fbbf24]">
Showing the last successful run below.
</p>
</div>
<button
type="button"
class="shrink-0 h-8 px-3 rounded-lg border border-[#fbbf24]/40 text-[11px] font-semibold text-[#FFFFFF] hover:bg-[#fbbf24]/20 transition-colors"
:disabled="loading"
@click="run"
>
Retry
</button>
</div>
<div
v-if="!result && !loading"
class="flex flex-col items-center gap-2 rounded-xl border border-dashed border-[#1e3a52] bg-[#0e2233] p-space-xl text-center"
>
<Icon name="material-symbols:cloud-off" class="text-[28px] text-[#94A3B8]" />
<p class="font-headline-sm text-[15px] text-[#FFFFFF]">No forecast available</p>
<p class="max-w-md text-[12px] leading-relaxed text-[#94A3B8]">
Start the Go and Python services, then retry. The page never substitutes demo
numbers for an unavailable model.
</p>
<button
type="button"
class="mt-1 h-9 px-4 rounded-lg bg-[#00C3CD] text-[#081723] font-label-md text-[12px] font-bold"
@click="run"
>
Try again
</button>
</div>
<template v-if="result">
<!-- Result summary -->
<article class="relative overflow-hidden rounded-xl border border-[#1e3a52] bg-[#0e2233] p-space-lg shadow-sm flex flex-col gap-space-md">
<div class="absolute inset-y-0 left-0 w-1.5 bg-[#00C3CD]"></div>
<div class="flex flex-col gap-2 pl-2 sm:flex-row sm:items-start sm:justify-between">
<div class="min-w-0">
<p class="font-label-sm text-[10px] uppercase tracking-wider text-[#00C3CD] font-semibold">
Selected forecast
</p>
<h2 class="font-headline-lg text-[24px] leading-[30px] tracking-tight text-[#FFFFFF] font-semibold mt-0.5 break-words">
{{ resultSensorName }}
</h2>
<div class="mt-1.5 flex flex-wrap items-center gap-1.5">
<span class="rounded bg-[#132b40] border border-[#1e3a52] px-2 py-0.5 text-[10px] text-[#FFFFFF] font-semibold">
{{ scenarioLabel(result.scenario) }}
</span>
<span class="rounded bg-[#132b40] border border-[#1e3a52] px-2 py-0.5 text-[10px] text-[#94A3B8] font-semibold">
{{ result.horizon }}
</span>
<span
class="inline-flex items-center gap-1 rounded border px-2 py-0.5 text-[10px] font-semibold"
:class="
result.weather_source === 'override'
? 'border-[#00C3CD]/35 bg-[#00C3CD]/10 text-[#00C3CD]'
: 'border-[#1e3a52] bg-[#132b40] text-[#94A3B8]'
"
>
<Icon
:name="result.weather_source === 'override' ? 'material-symbols:water-drop' : 'material-symbols:partly-cloudy-day'"
class="text-[13px]"
/>
{{ weatherSourceLabel }}
</span>
<span
v-if="holidayForced"
class="rounded border border-[#1e3a52] bg-[#132b40] px-2 py-0.5 text-[10px] text-[#94A3B8] font-semibold"
>
Holiday flag forced
</span>
<span
v-if="interpolated"
class="rounded border border-[#1e3a52] bg-[#132b40] px-2 py-0.5 text-[10px] text-[#94A3B8] font-semibold"
>
Interpolated from hourly model
</span>
</div>
</div>
<div class="shrink-0 rounded-lg border border-[#1e3a52] bg-[#132b40] px-3 py-2">
<p class="font-label-sm text-[9px] uppercase tracking-wider text-[#94A3B8]">Peak band</p>
<p class="font-tabular-stat-md text-[16px] text-[#00C3CD] font-semibold mt-0.5">
{{ formatBand(summary.peak?.lo, summary.peak?.hi) }}
</p>
<p class="text-[9px] text-[#64748B]">devices/hour</p>
</div>
</div>
<div v-if="result.points.length" class="grid grid-cols-2 lg:grid-cols-4 gap-space-sm pl-2">
<div class="flex flex-col rounded-lg border border-[#1e3a52] bg-[#132b40] px-3 py-2">
<span class="font-label-sm text-[10px] text-[#94A3B8]">Peak estimate</span>
<span class="font-tabular-stat-md text-[18px] text-[#FFFFFF] font-semibold mt-0.5">
{{ summary.peak ? formatNumber(summary.peak.v) : '—' }}
</span>
<span class="text-[10px] text-[#64748B]">devices/hour</span>
<span class="mt-1 text-[10px] text-[#00C3CD]">
{{ summary.peak ? formatDateTime(summary.peak.t) : 'No points' }}
</span>
</div>
<div class="flex flex-col rounded-lg border border-[#1e3a52] bg-[#132b40] px-3 py-2">
<span class="font-label-sm text-[10px] text-[#94A3B8]">Mean estimate</span>
<span class="font-tabular-stat-md text-[18px] text-[#FFFFFF] font-semibold mt-0.5">
{{ formatNumber(summary.mean) }}
</span>
<span class="text-[10px] text-[#64748B]">devices/hour</span>
<span class="mt-1 text-[10px] text-[#64748B]">{{ summary.count }} points</span>
</div>
<div class="flex flex-col rounded-lg border border-[#1e3a52] bg-[#132b40] px-3 py-2">
<span class="font-label-sm text-[10px] text-[#94A3B8]">Modeled device-hours</span>
<span class="font-tabular-stat-md text-[18px] text-[#FFFFFF] font-semibold mt-0.5">
{{ formatNumber(Math.round(summary.total)) }}
</span>
<span class="text-[10px] text-[#64748B]">aggregate estimate</span>
<span class="mt-1 text-[10px] text-[#64748B]">
Σ v × {{ summary.intervalHours }} h
</span>
</div>
<div class="flex flex-col rounded-lg border border-[#1e3a52] bg-[#132b40] px-3 py-2">
<span class="font-label-sm text-[10px] text-[#94A3B8]">Peak 80% band</span>
<span class="font-tabular-stat-md text-[18px] text-[#00C3CD] font-semibold mt-0.5">
{{ formatBand(summary.peak?.lo, summary.peak?.hi) }}
</span>
<span class="text-[10px] text-[#64748B]">devices/hour</span>
<span class="mt-1 text-[10px] text-[#64748B]">empirical residual range</span>
</div>
</div>
<p v-else class="pl-2 text-[12px] text-[#fbbf24]">
The API returned no points for this run. Change an input and try again.
</p>
<div class="grid grid-cols-1 sm:grid-cols-3 gap-2 border-t border-[#1e3a52]/70 pt-space-sm pl-2">
<div class="min-w-0">
<p class="font-label-sm text-[9px] uppercase tracking-wider text-[#94A3B8]">Model version</p>
<p class="mt-0.5 font-mono text-[10px] leading-snug text-[#FFFFFF] break-all">
{{ result.model_version || '—' }}
</p>
</div>
<div class="min-w-0">
<p class="font-label-sm text-[9px] uppercase tracking-wider text-[#94A3B8]">Data version</p>
<p class="mt-0.5 font-mono text-[10px] leading-snug text-[#FFFFFF] break-all">
{{ result.data_version || '—' }}
</p>
</div>
<div class="min-w-0">
<p class="font-label-sm text-[9px] uppercase tracking-wider text-[#94A3B8]">Context version</p>
<p class="mt-0.5 font-mono text-[10px] leading-snug text-[#FFFFFF] break-all">
{{ result.context_version || '—' }}
</p>
</div>
</div>
</article>
<!-- Chart -->
<article class="rounded-xl border border-[#1e3a52] bg-[#0e2233] p-space-lg shadow-sm flex flex-col gap-space-md min-w-0">
<div class="flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between">
<div>
<h2 class="font-headline-sm text-[16px] text-[#FFFFFF] font-semibold">
Forecast with 80% band
</h2>
<p class="text-[12px] leading-relaxed text-[#94A3B8]">
Estimated devices per hour. Observed history is the last 24 hourly points
before the forecast starts.
</p>
</div>
<div class="flex flex-wrap items-center gap-3 font-label-sm text-[10px] text-[#94A3B8] shrink-0">
<span v-if="observedWindow.length" class="inline-flex items-center gap-1">
<span class="w-3 h-0.5 bg-[#FFFFFF]"></span>
Observed
</span>
<span class="inline-flex items-center gap-1">
<span class="w-3 h-0.5 bg-[#00C3CD]"></span>
Forecast
</span>
<span class="inline-flex items-center gap-1">
<span class="w-2.5 h-2.5 rounded-sm bg-[#00C3CD]/20 border border-[#00C3CD]/40"></span>
80% band
</span>
</div>
</div>
<div class="rounded-lg border border-[#1e3a52] bg-[#081723] p-2 min-w-0">
<PlaygroundChart
:observed="observedWindow"
:forecast="result.points"
/>
</div>
<p v-if="interpolated" class="text-[10px] leading-relaxed text-[#94A3B8]">
Interpolated from hourly model. The 15m and 1h horizons are resampled, not a
native quarter-hour model.
</p>
<p v-if="observedError" class="text-[10px] leading-relaxed text-[#fbbf24]">
Observed history unavailable: {{ observedError }}
</p>
<p
v-else-if="observedPoints.length && !observedWindow.length"
class="text-[10px] leading-relaxed text-[#94A3B8]"
>
No contiguous observed hours immediately before the forecast start; showing forecast only.
</p>
</article>
<!-- Heatmap + comparison -->
<div class="grid grid-cols-1 xl:grid-cols-2 gap-space-lg items-start min-w-0">
<article class="rounded-xl border border-[#1e3a52] bg-[#0e2233] p-space-lg shadow-sm flex flex-col gap-space-sm min-w-0">
<div>
<h2 class="font-headline-sm text-[16px] text-[#FFFFFF] font-semibold">
Weekday × hour heatmap
</h2>
<p class="text-[11px] leading-relaxed text-[#94A3B8]">
Mean forecast devices/hour by local Berlin weekday and hour.
</p>
</div>
<div v-if="heatmap.rows.length" class="overflow-x-auto pb-1">
<div class="min-w-[300px] grid grid-cols-[minmax(58px,1fr)_repeat(6,minmax(32px,1fr))] gap-1 items-center">
<span class="font-label-sm text-[9px] uppercase tracking-wider text-[#64748B]">Day</span>
<span
v-for="hour in heatmap.hours"
:key="`hh-${hour}`"
class="text-center font-label-sm text-[9px] text-[#94A3B8] uppercase"
>
{{ String(hour).padStart(2, '0') }}h
</span>
<template v-for="row in heatmap.rows" :key="row.date">
<span class="flex flex-col leading-tight">
<span class="font-label-sm text-[11px] text-[#FFFFFF] font-semibold">
{{ formatWeekdayShort(row.date) }}
</span>
<span class="text-[9px] text-[#64748B]">{{ formatShortDate(row.date) }}</span>
</span>
<div
v-for="cell in row.cells"
:key="`${row.date}-${cell.hour}`"
class="h-7 rounded border flex items-center justify-center text-[10px] font-semibold"
:class="
cell.value === null
? 'border-dashed border-[#1e3a52]/70'
: 'border-[#00C3CD]/30'
"
:style="
cell.value === null
? undefined
: {
backgroundColor: `rgba(0, 195, 205, ${0.06 + cell.intensity * 0.84})`,
color: cell.intensity > 0.55 ? '#081723' : '#FFFFFF',
}
"
:aria-label="
cell.value === null
? `No forecast at ${cell.hour}:00`
: `${formatNumber(Math.round(cell.value))} devices per hour at ${cell.hour}:00`
"
>
{{ cell.value === null ? '' : formatNumber(Math.round(cell.value)) }}
</div>
</template>
</div>
<div class="mt-2 flex items-center justify-between text-[9px] text-[#64748B]">
<span>Forecast window, not historical week 30.</span>
<span class="inline-flex items-center gap-1">
<span class="w-8 h-1.5 rounded bg-[linear-gradient(90deg,rgba(0,195,205,0.12),rgba(0,195,205,0.9))]"></span>
Low → peak
</span>
</div>
</div>
<p v-else class="text-[12px] text-[#94A3B8]">
No forecast points to bucket for this horizon.
</p>
</article>
<article class="rounded-xl border border-[#1e3a52] bg-[#0e2233] p-space-lg shadow-sm flex flex-col gap-space-sm min-w-0">
<div>
<h2 class="font-headline-sm text-[16px] text-[#FFFFFF] font-semibold">
Scenario comparison
</h2>
<p class="text-[11px] leading-relaxed text-[#94A3B8]">
Selected scenario against base on the same sensor, horizon and weather inputs.
</p>
</div>
<p
v-if="isBaseScenario"
class="rounded-lg border border-[#1e3a52] bg-[#132b40] px-space-md py-3 text-[12px] leading-relaxed text-[#94A3B8]"
>
Base is the reference. Choose another scenario to see a delta.
</p>
<template v-else-if="comparisonRows.length">
<div class="flex flex-col gap-space-sm">
<div
v-for="row in comparisonRows"
:key="row.label"
class="flex flex-col gap-1.5"
>
<div class="flex items-center justify-between gap-2 text-[11px]">
<span class="text-[#94A3B8]">{{ row.label }}</span>
<span class="font-semibold text-[#FFFFFF]">
{{ formatNumber(row.selected) }} vs {{ formatNumber(row.base) }}
</span>
</div>
<div class="flex flex-col gap-1">
<div class="w-full h-2 rounded-full bg-[#081723] border border-[#1e3a52] overflow-hidden">
<div
class="h-full rounded-full bg-[#00C3CD]"
:style="{ width: `${Math.max(2, (row.selected / row.max) * 100)}%` }"
></div>
</div>
<div class="w-full h-2 rounded-full bg-[#081723] border border-[#1e3a52] overflow-hidden">
<div
class="h-full rounded-full bg-[#64748B]"
:style="{ width: `${Math.max(2, (row.base / row.max) * 100)}%` }"
></div>
</div>
</div>
<div class="flex items-center justify-between gap-2 text-[10px]">
<span class="text-[#00C3CD]">Selected</span>
<span class="text-[#94A3B8]">Base</span>
<span
class="rounded border border-[#00C3CD]/30 bg-[#00C3CD]/10 px-1.5 py-0.5 font-semibold text-[#00C3CD]"
>
Δ {{ signed(row.delta) }} ({{ row.pct === null ? '—' : signed(row.pct, '%') }})
</span>
</div>
</div>
</div>
<p class="text-[10px] leading-relaxed text-[#64748B]">
Both requests use the same weather override, so the delta isolates the
scenario event uplift. Scenario presets are assumptions, not causal estimates.
</p>
</template>
<p
v-else-if="comparisonError"
class="rounded-lg border border-[#fbbf24]/40 bg-[#fbbf24]/10 px-space-md py-2 text-[11px] leading-relaxed text-[#fde68a]"
>
Comparison unavailable: {{ comparisonError }}
</p>
<p v-else class="text-[12px] text-[#94A3B8]">
Run the forecast again to load the base comparison.
</p>
</article>
</div>
<!-- Model context -->
<article class="rounded-xl border border-[#1e3a52] bg-[#0e2233] p-space-lg shadow-sm flex flex-col gap-space-md min-w-0">
<div class="flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between">
<div>
<h2 class="font-headline-sm text-[16px] text-[#FFFFFF] font-semibold">Model context</h2>
<p class="text-[11px] leading-relaxed text-[#94A3B8]">
Metadata reported by <code class="text-[#FFFFFF]">/api/meta</code>, not a
marketing model card.
</p>
</div>
<NuxtLink
to="/sensors"
class="inline-flex items-center gap-1.5 font-label-sm text-[11px] text-[#00C3CD] hover:text-[#3ddae4] transition-colors"
>
<Icon name="material-symbols:shield-lock" class="text-[15px]" />
Privacy design
<Icon name="material-symbols:arrow-forward" class="text-[14px]" />
</NuxtLink>
</div>
<template v-if="meta">
<div class="grid grid-cols-1 sm:grid-cols-3 gap-2">
<div class="rounded-lg border border-[#1e3a52] bg-[#132b40] px-3 py-2 min-w-0">
<p class="font-label-sm text-[9px] uppercase tracking-wider text-[#94A3B8]">Model</p>
<p class="mt-0.5 font-mono text-[10px] text-[#FFFFFF] break-all">{{ meta.model_version }}</p>
</div>
<div class="rounded-lg border border-[#1e3a52] bg-[#132b40] px-3 py-2 min-w-0">
<p class="font-label-sm text-[9px] uppercase tracking-wider text-[#94A3B8]">Data</p>
<p class="mt-0.5 font-mono text-[10px] text-[#FFFFFF] break-all">{{ meta.data_version }}</p>
</div>
<div class="rounded-lg border border-[#1e3a52] bg-[#132b40] px-3 py-2 min-w-0">
<p class="font-label-sm text-[9px] uppercase tracking-wider text-[#94A3B8]">Context</p>
<p class="mt-0.5 font-mono text-[10px] text-[#FFFFFF] break-all">{{ meta.context_version }}</p>
</div>
</div>
<div class="grid grid-cols-2 lg:grid-cols-4 gap-2">
<div class="rounded-lg border border-[#1e3a52] bg-[#132b40] px-3 py-2">
<p class="font-label-sm text-[9px] uppercase tracking-wider text-[#94A3B8]">Coverage</p>
<p class="mt-0.5 text-[12px] font-semibold text-[#FFFFFF]">{{ meta.coverage.sensors }} sensors</p>
<p class="text-[10px] text-[#64748B]">{{ meta.coverage.cadence_min }} min cadence</p>
<p class="mt-0.5 text-[9px] leading-snug text-[#64748B]">
{{ formatDate(meta.coverage.from) }} – {{ formatDate(meta.coverage.to) }}
</p>
</div>
<div class="rounded-lg border border-[#1e3a52] bg-[#132b40] px-3 py-2">
<p class="font-label-sm text-[9px] uppercase tracking-wider text-[#94A3B8]">MAE</p>
<p class="mt-0.5 text-[12px] font-semibold text-[#FFFFFF]">{{ formatNumber(meta.metrics.mae) }}</p>
<p class="text-[10px] text-[#64748B]">vs {{ formatNumber(meta.metrics.baseline_mae) }} baseline</p>
<p class="mt-0.5 text-[9px] text-[#64748B]">Holdout, devices/hour</p>
</div>
<div class="rounded-lg border border-[#1e3a52] bg-[#132b40] px-3 py-2">
<p class="font-label-sm text-[9px] uppercase tracking-wider text-[#94A3B8]">WAPE</p>
<p class="mt-0.5 text-[12px] font-semibold text-[#FFFFFF]">{{ formatPercent(meta.metrics.wape, 1) }}</p>
<p class="text-[10px] text-[#64748B]">vs {{ formatPercent(meta.metrics.baseline_wape, 1) }} baseline</p>
<p class="mt-0.5 text-[9px] text-[#64748B]">Holdout, lower is better</p>
</div>
<div class="rounded-lg border border-[#1e3a52] bg-[#132b40] px-3 py-2">
<p class="font-label-sm text-[9px] uppercase tracking-wider text-[#94A3B8]">R²</p>
<p class="mt-0.5 text-[12px] font-semibold text-[#FFFFFF]">{{ meta.metrics.r2.toFixed(3) }}</p>
<p class="text-[10px] text-[#64748B]">Holdout fit</p>
<p class="mt-0.5 text-[9px] text-[#64748B]">{{ meta.metrics.model }} model</p>
</div>
</div>
<div v-if="meta.limits?.length" class="flex flex-col gap-1">
<p class="font-label-sm text-[9px] uppercase tracking-wider text-[#94A3B8]">Known limits</p>
<ul class="flex flex-col gap-1">
<li
v-for="limit in meta.limits"
:key="limit"
class="flex items-start gap-1.5 text-[10px] leading-snug text-[#94A3B8]"
>
<Icon name="material-symbols:info" class="text-[12px] text-[#00C3CD] shrink-0 mt-0.5" />
{{ limit }}
</li>
</ul>
</div>
</template>
<div v-else class="flex items-center justify-between gap-3 rounded-lg border border-[#1e3a52] bg-[#132b40] px-space-md py-3">
<p class="text-[11px] leading-relaxed text-[#94A3B8]">
{{ metaErrorMessage || 'Model metadata is unavailable.' }}
</p>
<button
type="button"
class="shrink-0 h-8 px-3 rounded-lg border border-[#1e3a52] text-[11px] font-semibold text-[#FFFFFF] hover:border-[#00C3CD] transition-colors disabled:opacity-50"
:disabled="metaPending"
@click="refreshMeta()"
>
{{ metaPending ? 'Loading…' : 'Retry' }}
</button>
</div>
</article>
<!-- Transparency -->
<article class="rounded-xl border border-[#1e3a52] bg-[#0e2233] p-space-md flex items-start gap-space-sm">
<Icon name="material-symbols:verified" class="text-[20px] text-[#00C3CD] shrink-0 mt-0.5" />
<div class="flex flex-col gap-1">
<h2 class="font-headline-sm text-[13px] text-[#FFFFFF] font-semibold">
What this forecast is, and is not
</h2>
<p class="text-[11px] leading-relaxed text-[#94A3B8]">
Aggregate estimated-device counts, not people. Eight sensors in a ~580 m
inner-city cluster. Weather is observed in training and forecast in this demo.
Scenario uplifts are explicit assumptions, not causal estimates. The 80% bands
are empirical residuals, not calibrated guarantees.
</p>
</div>
</article>
</template>
</section>
</div>
</div>
</main>
<footer class="mt-auto w-full bg-[#081723] border-t border-[#1e3a52]/50 py-3">
<div class="max-w-[1200px] mx-auto px-margin-desktop flex flex-col sm:flex-row items-center justify-between gap-1 sm:gap-space-lg text-[11px] font-body-sm text-[#94A3B8] opacity-50 hover:opacity-100 transition-opacity duration-200">
<span>© 2026 Schwarz Digits · Privacy by design</span>
<span>Aggregate counts · No identifiers</span>
</div>
</footer>
</div>
</template>