feat: build Onyx SSR shell and plan hero with mock data
This commit is contained in:
1 parent
84c20992f9
commit
2db494fb10
34 files changed
+3197
-2
No files matched your search
@@ -0,0 +1,242 @@
|
||||
<script setup lang="ts">
|
||||
import { iconArrowRight, iconCircleInformation, iconFlash } from '@sit-onyx/icons'
|
||||
import { addDays, applyScenario, buildStaffing, planWeekStart } from '#shared/staffing'
|
||||
import type { ContextResponse, ForecastResponse, Scenario, ScenarioPreset, Sensor } from '#shared/types'
|
||||
import { formatEuro, formatShortDate, formatWeekday, formatWeekdayShort, weekLabel } from '~/utils/format'
|
||||
|
||||
useHead({ title: 'Simulate a scenario — PulseCast' })
|
||||
|
||||
const config = useRuntimeConfig()
|
||||
const demoNow = String(config.public.demoNow)
|
||||
const weekStart = planWeekStart(demoNow)
|
||||
const weekEnd = addDays(weekStart, 6)
|
||||
|
||||
const sensorId = ref('hn-stadtgalerie-01')
|
||||
const scenario = ref<Scenario>('sunny-saturday-market')
|
||||
|
||||
const { data: sensors } = await useFetch<Sensor[]>('/api/sensors')
|
||||
const { data: context } = await useFetch<ContextResponse>('/api/context')
|
||||
const { data: presets } = await useFetch<ScenarioPreset[]>('/api/scenarios')
|
||||
const { data: baseForecast } = await useFetch<ForecastResponse>('/api/forecast', {
|
||||
query: computed(() => ({ sensor: sensorId.value, horizon: '7d', scenario: 'base' })),
|
||||
})
|
||||
|
||||
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 activePreset = computed(() => presets.value?.find((preset) => preset.id === scenario.value))
|
||||
const radioOptions = computed(() =>
|
||||
(presets.value ?? []).map((preset) => ({
|
||||
value: preset.id,
|
||||
label: preset.label,
|
||||
description: preset.description,
|
||||
})),
|
||||
)
|
||||
|
||||
const scenarioPoints = computed(() =>
|
||||
applyScenario(baseForecast.value?.points ?? [], scenario.value),
|
||||
)
|
||||
|
||||
const versions = computed(() => ({
|
||||
data_version: baseForecast.value?.data_version ?? '',
|
||||
model_version: baseForecast.value?.model_version ?? '',
|
||||
context_version: baseForecast.value?.context_version ?? '',
|
||||
}))
|
||||
|
||||
function makePlan(points: typeof scenarioPoints.value) {
|
||||
return buildStaffing({
|
||||
sensor: sensorId.value,
|
||||
scenario: scenario.value,
|
||||
standard: 'standard',
|
||||
points,
|
||||
weekStart,
|
||||
...versions.value,
|
||||
})
|
||||
}
|
||||
|
||||
const basePlan = computed(() => makePlan(baseForecast.value?.points ?? []).response)
|
||||
const scenarioBuild = computed(() => makePlan(scenarioPoints.value))
|
||||
const scenarioPlan = computed(() => scenarioBuild.value.response)
|
||||
|
||||
const baseHours = computed(() => basePlan.value.hours.reduce((sum, hour) => sum + hour.scheduled_staff, 0))
|
||||
const scenarioHours = computed(() =>
|
||||
scenarioPlan.value.hours.reduce((sum, hour) => sum + hour.scheduled_staff, 0),
|
||||
)
|
||||
const deltaHours = computed(() => scenarioHours.value - baseHours.value)
|
||||
const deltaCost = computed(() => scenarioPlan.value.summary.cost_eur - basePlan.value.summary.cost_eur)
|
||||
|
||||
function peakStaffByDay(plan: ReturnType<typeof makePlan>) {
|
||||
const map: Record<string, number> = {}
|
||||
for (const [date, hours] of Object.entries(plan.byDate)) {
|
||||
map[date] = hours.reduce((peak, hour) => Math.max(peak, hour.required_staff), 0)
|
||||
}
|
||||
return map
|
||||
}
|
||||
const basePeaks = computed(() => peakStaffByDay(makePlan(baseForecast.value?.points ?? [])))
|
||||
const scenarioPeaks = computed(() => peakStaffByDay(scenarioBuild.value))
|
||||
|
||||
const days = computed(() =>
|
||||
Object.keys(basePeaks.value)
|
||||
.sort()
|
||||
.map((date) => ({
|
||||
date,
|
||||
base: basePeaks.value[date] ?? 0,
|
||||
scenario: scenarioPeaks.value[date] ?? 0,
|
||||
})),
|
||||
)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="page page-stack">
|
||||
<header class="page-header">
|
||||
<div>
|
||||
<p class="eyebrow">Simulate · {{ weekLabel(weekStart, weekEnd) }}</p>
|
||||
<OnyxHeadline is="h1">Change the weather, watch the plan move.</OnyxHeadline>
|
||||
<p class="lede">
|
||||
A scenario changes forecast footfall, not history. Compare the shift requirement against the base week
|
||||
for <strong>{{ activeSensor?.name ?? 'Stadtgalerie' }}</strong>.
|
||||
</p>
|
||||
</div>
|
||||
<div style="min-width: 14rem">
|
||||
<OnyxSelect
|
||||
v-model="sensorId"
|
||||
label="Sensor"
|
||||
list-label="Inner-city sensors"
|
||||
:options="sensorOptions"
|
||||
density="compact"
|
||||
/>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="callout">
|
||||
<OnyxIcon :icon="iconCircleInformation" size="16px" color="primary" />
|
||||
Local selection for now. SSE broadcast to <code>/stage</code> and phones is the next slice; this page makes the
|
||||
recommendation change visible on one screen.
|
||||
</div>
|
||||
|
||||
<div class="split-grid">
|
||||
<div class="card-stack">
|
||||
<OnyxCard>
|
||||
<div class="card-header">
|
||||
<div>
|
||||
<OnyxHeadline is="h2">Scenario</OnyxHeadline>
|
||||
<p class="small muted" style="margin: 0">The contract enum is fixed; perturbation sizes are mock assumptions.</p>
|
||||
</div>
|
||||
<OnyxBadge color="warning" density="compact">mock simulation</OnyxBadge>
|
||||
</div>
|
||||
<OnyxRadioGroup
|
||||
v-model="scenario"
|
||||
label="Choose a scenario"
|
||||
:options="radioOptions"
|
||||
orientation="vertical"
|
||||
/>
|
||||
</OnyxCard>
|
||||
|
||||
<OnyxCard>
|
||||
<div class="card-header">
|
||||
<div>
|
||||
<OnyxHeadline is="h2">Day by day</OnyxHeadline>
|
||||
<p class="small muted" style="margin: 0">Peak required staff per day, base vs scenario.</p>
|
||||
</div>
|
||||
</div>
|
||||
<OnyxTable striped :table-attrs="{ style: 'min-width: 30rem' }">
|
||||
<template #head>
|
||||
<tr>
|
||||
<th scope="col">Day</th>
|
||||
<th scope="col">Base peak</th>
|
||||
<th scope="col">Scenario peak</th>
|
||||
<th scope="col">Δ staff</th>
|
||||
</tr>
|
||||
</template>
|
||||
<tr v-for="day in days" :key="day.date">
|
||||
<th scope="row" style="text-align: left; font-weight: 600">
|
||||
{{ formatWeekday(day.date) }}
|
||||
<span class="muted" style="font-weight: 400">{{ formatShortDate(day.date) }}</span>
|
||||
</th>
|
||||
<td>{{ day.base }}</td>
|
||||
<td>{{ day.scenario }}</td>
|
||||
<td>
|
||||
<OnyxBadge :color="day.scenario > day.base ? 'warning' : day.scenario < day.base ? 'success' : 'neutral'" density="compact">
|
||||
{{ day.scenario === day.base ? '±0' : `${day.scenario > day.base ? '+' : ''}${day.scenario - day.base}` }}
|
||||
</OnyxBadge>
|
||||
</td>
|
||||
</tr>
|
||||
</OnyxTable>
|
||||
</OnyxCard>
|
||||
</div>
|
||||
|
||||
<aside class="card-stack">
|
||||
<OnyxCard>
|
||||
<div class="card-header">
|
||||
<OnyxHeadline is="h2">What changes</OnyxHeadline>
|
||||
<OnyxIcon :icon="iconFlash" size="24px" color="primary" />
|
||||
</div>
|
||||
<p style="margin-top: 0"><strong>{{ activePreset?.label ?? 'Base week' }}</strong></p>
|
||||
<p class="small muted" style="margin-top: 0">{{ activePreset?.description }}</p>
|
||||
<dl class="metric-list">
|
||||
<div><dt>Base staff-hours</dt><dd>{{ baseHours }}</dd></div>
|
||||
<div><dt>Scenario staff-hours</dt><dd>{{ scenarioHours }}</dd></div>
|
||||
<div><dt>Δ staff-hours</dt><dd>{{ deltaHours >= 0 ? '+' : '' }}{{ deltaHours }}</dd></div>
|
||||
<div><dt>Δ labour cost</dt><dd>{{ deltaCost >= 0 ? '+' : '' }}{{ formatEuro(deltaCost) }}</dd></div>
|
||||
<div><dt>Base cost</dt><dd>{{ formatEuro(basePlan.summary.cost_eur) }}</dd></div>
|
||||
<div><dt>Scenario cost</dt><dd>{{ formatEuro(scenarioPlan.summary.cost_eur) }}</dd></div>
|
||||
</dl>
|
||||
<div class="callout" style="margin-top: var(--onyx-density-md)">
|
||||
<p class="small" style="margin: 0">
|
||||
<template v-if="deltaHours > 0">
|
||||
This scenario adds {{ deltaHours }} staff-hours. Check that the Saturday block can be covered before
|
||||
approving.
|
||||
</template>
|
||||
<template v-else-if="deltaHours < 0">
|
||||
This scenario removes {{ Math.abs(deltaHours) }} staff-hours. The plan gets cheaper, but check the
|
||||
peak hour before cutting the block.
|
||||
</template>
|
||||
<template v-else>
|
||||
This scenario does not change the shift requirements in the mock. That is a result, not a bug.
|
||||
</template>
|
||||
</p>
|
||||
</div>
|
||||
<OnyxButton
|
||||
:label="`Apply to plan`"
|
||||
:icon="iconArrowRight"
|
||||
icon-position="right"
|
||||
color="primary"
|
||||
:link="`/plan?scenario=${scenario}`"
|
||||
style="margin-top: var(--onyx-density-md)"
|
||||
/>
|
||||
</OnyxCard>
|
||||
|
||||
<OnyxCard>
|
||||
<div class="card-header">
|
||||
<OnyxHeadline is="h3">Scenario rules</OnyxHeadline>
|
||||
</div>
|
||||
<ul class="why-list">
|
||||
<li><span><strong>Sunny Saturday + market</strong> — ×1.20 Saturday footfall.</span></li>
|
||||
<li><span><strong>Rainy Saturday</strong> — ×0.82 Saturday footfall.</span></li>
|
||||
<li><span><strong>Wednesday event</strong> — ×1.25 Wed 16:00–20:00.</span></li>
|
||||
<li><span>Base keeps the latest forecast weather and no event uplift.</span></li>
|
||||
</ul>
|
||||
<p class="small muted table-note">
|
||||
These multipliers are mock demo assumptions. The Go/ML implementation must publish the same numbers or
|
||||
the comparison is not comparable.
|
||||
</p>
|
||||
</OnyxCard>
|
||||
|
||||
<OnyxCard>
|
||||
<div class="card-header">
|
||||
<OnyxHeadline is="h3">Context</OnyxHeadline>
|
||||
</div>
|
||||
<p class="small muted" style="margin-top: 0">
|
||||
Weather now: {{ context?.weather.now.temp_c ?? '—' }} °C, {{ context?.weather.now.precip_mm ?? '—' }} mm
|
||||
precipitation.
|
||||
</p>
|
||||
<p class="small muted" style="margin: 0">
|
||||
{{ formatWeekdayShort(weekStart) }} {{ formatShortDate(weekStart) }} → {{ formatWeekdayShort(weekEnd) }}
|
||||
{{ formatShortDate(weekEnd) }} · Europe/Berlin.
|
||||
</p>
|
||||
</OnyxCard>
|
||||
</aside>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
Reference in new issue
Block a user