Files
web-nuxt/app/pages/index.vue
T
Noel Sabia b33e6ff001 feat: wire Nitro API to Go, real staffing plan and train proxy
- Replace mock Nitro routes with server-side proxies to the Go API
- /plan reads Go /api/staffing; local assumption edits are a labeled preview
- /simulate reads base and scenario staffing from Go instead of local multipliers
- Route train upload and scenario POST through Nitro with server-only credentials
- Keep NUXT_PUBLIC_USE_MOCK=1 as an explicit dev fallback only
- Match Go's global-peak flat schedule and add a captured Go parity fixture
- Run the web runtime as numeric UID/GID 10001:10001
- Add make check, Gitea CI workflow and a proxy smoke script
2026-11-14 06:13:00 +01:00

269 lines
11 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 {
iconCalendar,
iconCloud,
iconLocationPin,
iconSunny,
iconTriangleWarning,
} from '@sit-onyx/icons'
import { weatherKind } from '#shared/insights'
import { berlinParts } from '#shared/staffing'
import type { ContextResponse, MetaResponse, Sensor, SeriesResponse } from '#shared/types'
import {
formatDate,
formatDateTime,
formatNumber,
formatPercent,
formatShortDate,
formatTime,
} from '~/utils/format'
useHead({ title: 'Now in Heilbronn — PulseCast' })
const config = useRuntimeConfig()
const demoNow = String(config.public.demoNow)
const { data: sensors } = await useFetch<Sensor[]>('/api/sensors')
const { data: context } = await useFetch<ContextResponse>('/api/context')
const { data: meta } = await useFetch<MetaResponse>('/api/meta')
const sensorId = ref(
sensors.value?.find((sensor) => sensor.id === 'hn-stadtgalerie-01')?.id ??
sensors.value?.[0]?.id ??
'hn-stadtgalerie-01',
)
const { data: series } = await useFetch<SeriesResponse>('/api/series', {
query: computed(() => ({ sensor: sensorId.value, step: '1h' })),
})
const activeSensor = computed(() => sensors.value?.find((sensor) => sensor.id === sensorId.value))
const sensorOptions = computed(() =>
(sensors.value ?? []).map((sensor) => ({ value: sensor.id, label: sensor.name })),
)
const lastPoint = computed(() => series.value?.points.at(-1))
const previousPoint = computed(() => series.value?.points.at(-25))
const deltaPct = computed(() => {
if (!lastPoint.value || !previousPoint.value || previousPoint.value.v === 0) return 0
return ((lastPoint.value.v - previousPoint.value.v) / previousPoint.value.v) * 100
})
const last24 = computed(() => series.value?.points.slice(-24) ?? [])
const barMax = computed(() => Math.max(...last24.value.map((point) => point.v), 1))
const nowWeather = computed(() => context.value?.weather.now)
const weatherIcon = computed(() =>
nowWeather.value && weatherKind(nowWeather.value) === 'sunny' ? iconSunny : iconCloud,
)
const weatherLabel = computed(() => {
if (!nowWeather.value) return '—'
const kind = weatherKind(nowWeather.value)
return kind === 'sunny' ? 'Sunny' : kind === 'partly-cloudy' ? 'Partly cloudy' : kind === 'rain' ? 'Rain' : 'Cloudy'
})
const today = berlinParts(demoNow).date
const todayHoliday = computed(() => context.value?.holidays.find((holiday) => holiday.date === today))
const lastHoliday = computed(() =>
context.value?.holidays.filter((holiday) => holiday.date < today).at(-1),
)
const nextHoliday = computed(() =>
context.value?.holidays.find((holiday) => holiday.date > today),
)
const latestPulse = computed(() => {
if (!sensors.value?.length) return 0
return Math.round(sensors.value.reduce((sum, sensor) => sum + sensor.mean, 0) / sensors.value.length)
})
</script>
<template>
<div class="page page-stack">
<header class="page-header">
<div>
<p class="eyebrow">Now · replay clock {{ formatDateTime(demoNow) }}</p>
<OnyxHeadline is="h1">The pulse is in the pedestrian core.</OnyxHeadline>
<p class="lede">
Eight fixed sensors around Stadtgalerie and Kaiserstraße. This is estimated device density, not people,
and not a city-wide heatmap. The decision lives on <NuxtLink to="/plan">Plan</NuxtLink>.
</p>
</div>
<div class="hero-actions">
<OnyxBadge color="warning">Replay, not live</OnyxBadge>
<OnyxBadge color="neutral" density="compact">{{ sensors?.length ?? 8 }} sensors</OnyxBadge>
</div>
</header>
<div class="split-grid">
<div class="card-stack">
<OnyxCard>
<div class="card-header">
<div>
<OnyxHeadline is="h2">Latest replay reading</OnyxHeadline>
<p class="small muted" style="margin: 0">Last available hour in the API series.</p>
</div>
<div style="min-width: 12rem">
<OnyxSelect
v-model="sensorId"
label="Sensor"
list-label="Inner-city sensors"
:options="sensorOptions"
density="compact"
/>
</div>
</div>
<div class="reading-row">
<p class="reading-value">{{ lastPoint ? formatNumber(lastPoint.v) : '—' }}</p>
<div>
<p style="margin: 0; font-weight: 600">estimated devices / hour</p>
<p class="small muted" style="margin: 0">
{{ activeSensor?.name }} · {{ activeSensor?.id }}
</p>
<OnyxBadge :color="deltaPct >= 0 ? 'success' : 'warning'" density="compact">
{{ deltaPct >= 0 ? '+' : '' }}{{ formatPercent(deltaPct, 0) }} vs 24 h earlier
</OnyxBadge>
</div>
</div>
<div class="bar-chart" role="img" :aria-label="`Last 24 hours for ${activeSensor?.name}`">
<div
v-for="(point, index) in last24"
:key="point.t"
class="bar-chart__bar"
:class="{ 'bar-chart__bar--now': index === last24.length - 1 }"
:style="{ height: `${Math.max(4, (point.v / barMax) * 100)}%` }"
:title="`${formatTime(point.t)} · ${point.v}`"
/>
</div>
<div class="legend" style="justify-content: space-between; margin-top: var(--onyx-density-2xs)">
<span class="small muted">{{ last24[0] ? formatTime(last24[0].t) : '—' }}</span>
<span class="small muted">{{ lastPoint ? formatDateTime(lastPoint.t) : '—' }}</span>
</div>
<p class="small muted table-note">
The CSV is static. The replay clock is {{ formatDateTime(demoNow) }}; the last measured point is
{{ lastPoint ? formatDateTime(lastPoint.t) : '—' }}. No live sensor feed is claimed.
</p>
</OnyxCard>
<OnyxCard>
<div class="card-header">
<div>
<OnyxHeadline is="h2">Sensor cluster</OnyxHeadline>
<p class="small muted" style="margin: 0">
Select a sensor to update the reading. Bounds are relative; the basemap is the next map slice.
</p>
</div>
<OnyxBadge color="info" density="compact">580 m cluster</OnyxBadge>
</div>
<SensorClusterMap :sensors="sensors ?? []" :active-id="sensorId" @select="sensorId = $event" />
</OnyxCard>
</div>
<aside class="card-stack">
<OnyxCard>
<div class="card-header">
<OnyxHeadline is="h2">Heilbronn weather</OnyxHeadline>
<OnyxBadge color="neutral" density="compact">Open-Meteo context</OnyxBadge>
</div>
<div class="reading-row">
<OnyxIcon :icon="weatherIcon" size="48px" color="primary" />
<div>
<p style="margin: 0; font-size: 2rem; font-weight: 700; line-height: 1">
{{ nowWeather ? `${nowWeather.temp_c} °C` : '—' }}
</p>
<p class="small muted" style="margin: 0">{{ weatherLabel }}</p>
</div>
</div>
<dl class="metric-list" style="margin-top: var(--onyx-density-md)">
<div><dt>Precipitation</dt><dd>{{ nowWeather?.precip_mm ?? '—' }} mm</dd></div>
<div><dt>Cloud cover</dt><dd>{{ nowWeather?.cloud_pct ?? '—' }}%</dd></div>
<div><dt>Wind</dt><dd>{{ nowWeather?.wind_kmh ?? '—' }} km/h</dd></div>
<div><dt>Humidity</dt><dd>{{ nowWeather?.humidity_pct ?? '—' }}%</dd></div>
</dl>
<p class="small muted table-note">
Updated {{ context ? formatDateTime(context.updated_at) : '—' }} · context
{{ context?.cached ? 'cached' : 'live' }}
</p>
</OnyxCard>
<OnyxCard>
<div class="card-header">
<OnyxHeadline is="h2">Holiday context</OnyxHeadline>
<OnyxIcon :icon="iconCalendar" size="24px" color="primary" />
</div>
<OnyxBadge v-if="todayHoliday" color="warning">{{ todayHoliday.name }} today</OnyxBadge>
<OnyxBadge v-else color="success">No public holiday today</OnyxBadge>
<p class="small muted" style="margin: var(--onyx-density-sm) 0 0">
<template v-if="nextHoliday">
Next: <strong>{{ nextHoliday.name }}</strong> on {{ formatDate(nextHoliday.date) }}.
</template>
<template v-else>No upcoming holiday in the holiday calendar.</template>
</p>
<p v-if="lastHoliday" class="small muted" style="margin: var(--onyx-density-xs) 0 0">
Last: {{ lastHoliday.name }} on {{ formatShortDate(lastHoliday.date) }}.
</p>
<p class="small muted table-note">
Baden-Württemberg public holidays; used as model context, not as a causal claim.
</p>
</OnyxCard>
<OnyxCard>
<div class="card-header">
<OnyxHeadline is="h3">What to do next</OnyxHeadline>
<OnyxIcon :icon="iconLocationPin" size="24px" color="primary" />
</div>
<p class="small" style="margin-top: 0">
The average sensor is at <strong>{{ latestPulse }}</strong> estimated devices/hour. That is context,
not a staffing decision. Open the plan to turn next week’s forecast into shifts.
</p>
<OnyxButton label="Open the staffing plan" link="/plan" color="primary" />
</OnyxCard>
</aside>
</div>
<OnyxCard>
<div class="card-header">
<div>
<OnyxHeadline is="h2">Eight sensors</OnyxHeadline>
<p class="small muted" style="margin: 0">Measured points, stable order by ID. Battery may be null in the API.</p>
</div>
<OnyxBadge color="neutral" density="compact">measured points only</OnyxBadge>
</div>
<OnyxTable striped with-page-scrolling :table-attrs="{ style: 'min-width: 36rem' }">
<template #head>
<tr>
<th scope="col">Sensor</th>
<th scope="col">Mean</th>
<th scope="col">P95</th>
<th scope="col">Battery</th>
<th scope="col">Source ID</th>
</tr>
</template>
<tr v-for="sensor in sensors" :key="sensor.id">
<th scope="row" style="text-align: left; font-weight: 600">
{{ sensor.name }}
<OnyxBadge v-if="sensor.id === sensorId" color="primary" density="compact" style="margin-left: 0.35rem">selected</OnyxBadge>
</th>
<td>{{ sensor.mean }}</td>
<td>{{ sensor.p95 }}</td>
<td>
<OnyxBadge :color="sensor.battery === null ? 'neutral' : sensor.battery >= 60 ? 'success' : 'warning'" density="compact">
{{ sensor.battery === null ? 'n/a' : `${sensor.battery}%` }}
</OnyxBadge>
</td>
<td class="mono">{{ sensor.id }}</td>
</tr>
</OnyxTable>
<p v-if="meta" class="small muted table-note">
Coverage {{ formatDate(meta.coverage.from) }} → {{ formatDate(meta.coverage.to) }} ·
{{ meta.coverage.cadence_min }}-min cadence · data {{ meta.data_version }} · model {{ meta.model_version }}
</p>
</OnyxCard>
<div v-if="!sensors?.length" class="callout callout--warning">
<OnyxIcon :icon="iconTriangleWarning" size="16px" color="warning" />
Sensor data is missing. Check that the Go API is running and that NUXT_API_INTERNAL_BASE points to it.
</div>
</div>
</template>