feat: add operational use cases console
ci / check (push) Successful in 1m17s
ci / check (pull_request) Successful in 1m13s

This commit is contained in:
Noel Sabia committed 2026-11-14 21:39:15 +01:00
1 parent 78d1f0e308
commit 8d687ad05b
19 files changed
+4707 -12

No files matched your search

+1 -1
View File
@@ -41,7 +41,7 @@ const comparisonRows = [
<span>Try the engine</span>
<Icon name="material-symbols:arrow-forward" class="text-[18px] group-hover:translate-x-0.5 transition-transform text-[#081723]" />
</a>
<a class="inline-flex items-center justify-center gap-2 px-6 h-12 rounded-xl bg-[#0e2233] text-[#FFFFFF] border border-[#1e3a52] font-label-md text-label-md hover:bg-[#132b40] transition-all shadow-sm" href="#use-cases">
<a class="inline-flex items-center justify-center gap-2 px-6 h-12 rounded-xl bg-[#0e2233] text-[#FFFFFF] border border-[#1e3a52] font-label-md text-label-md hover:bg-[#132b40] transition-all shadow-sm" href="/use-cases">
<Icon name="material-symbols:visibility-outline" class="text-[18px] text-[#00C3CD]" />
<span>See live use cases</span>
</a>
+305
View File
@@ -0,0 +1,305 @@
<script setup lang="ts">
import type { CoolRouteBundle, CoolTime } from '#shared/cool'
import { pendingCoolRouteBundle } from '#shared/cool'
import type { ContextResponse, MetaResponse, ScenarioState, Sensor, StaffingResponse } from '#shared/types'
import type { UseCaseId, PrezeroBundle } from '#shared/use-cases'
import {
DEFAULT_USE_CASE,
USE_CASE_TABS,
isCoolTimeValue,
isUseCaseId,
} from '#shared/use-cases'
import LiveTelemetryBar from '~/components/use-cases/LiveTelemetryBar.vue'
import PrezeroPanel from '~/components/use-cases/PrezeroPanel.vue'
import RoutingPanel from '~/components/use-cases/RoutingPanel.vue'
import StaffingPanel from '~/components/use-cases/StaffingPanel.vue'
import UseCaseTabs from '~/components/use-cases/UseCaseTabs.vue'
interface BuildingPolygon {
name: string | null
kind: string
points: Array<[number, number]>
}
interface BuildingsBundle {
source: string
generated: string
buildings: BuildingPolygon[]
}
interface PlacePoint {
name: string | null
lat: number
lon: number
near_routes_m?: Record<string, number>
}
interface PlacesBundle {
cool_places: PlacePoint[]
water: PlacePoint[]
benches: PlacePoint[]
}
const route = useRoute()
const active = computed<UseCaseId>(() =>
isUseCaseId(route.query.uc) ? route.query.uc : DEFAULT_USE_CASE,
)
const time = computed<CoolTime>(() =>
isCoolTimeValue(route.query.t) ? route.query.t : '16:00',
)
const activeTab = computed(() => USE_CASE_TABS.find((tab) => tab.id === active.value) ?? USE_CASE_TABS[1]!)
function selectTime(value: CoolTime) {
void navigateTo({ query: { ...route.query, t: value } }, { replace: true })
}
const latency = useState<Record<string, number>>('use-cases-latency', () => ({
routing: 0,
staffing: 0,
prezero: 0,
}))
const activeLatency = computed(() => latency.value[active.value] ?? 0)
function startLatency(key: keyof typeof latency.value) {
const started = typeof performance === 'undefined' ? Date.now() : performance.now()
return () => {
const ended = typeof performance === 'undefined' ? Date.now() : performance.now()
latency.value = { ...latency.value, [key]: Math.max(1, Math.round(ended - started)) }
}
}
const { data: initialScenario } = await useFetch<ScenarioState>('/api/scenario')
const live = useLiveScenario(initialScenario.value)
let finishRouteLatency: (() => void) | undefined
const routeFetch = useFetch<CoolRouteBundle>('/cool-city/route.json', {
key: 'use-cases-route-bundle',
onRequest: () => {
finishRouteLatency = startLatency('routing')
},
onResponse: () => finishRouteLatency?.(),
})
const buildingsFetch = useFetch<BuildingsBundle>('/cool-city/buildings.json', {
key: 'use-cases-buildings',
})
const placesFetch = useFetch<PlacesBundle>('/cool-city/places.json', {
key: 'use-cases-places',
})
let finishPrezeroLatency: (() => void) | undefined
const prezeroFetch = useFetch<PrezeroBundle>('/prezero/priority.json', {
key: 'use-cases-prezero',
onRequest: () => {
finishPrezeroLatency = startLatency('prezero')
},
onResponse: () => finishPrezeroLatency?.(),
})
const sensorsFetch = useFetch<Sensor[]>('/api/sensors', { key: 'use-cases-sensors' })
const contextFetch = useFetch<ContextResponse>('/api/context', { key: 'use-cases-context' })
const metaFetch = useFetch<MetaResponse>('/api/meta', { key: 'use-cases-meta' })
const sensorId = ref('hn-stadtgalerie-01')
let finishPlanLatency: (() => void) | undefined
const planFetch = useFetch<StaffingResponse>('/api/staffing', {
key: 'use-cases-plan',
query: computed(() => ({
sensor: sensorId.value,
scenario: live.scenarioId,
standard: 'standard',
})),
onRequest: () => {
finishPlanLatency = startLatency('staffing')
},
onResponse: () => finishPlanLatency?.(),
})
await Promise.all([
routeFetch,
buildingsFetch,
placesFetch,
prezeroFetch,
sensorsFetch,
contextFetch,
metaFetch,
planFetch,
])
const { data: routeBundle, error: routeError } = routeFetch
const { data: buildings } = buildingsFetch
const { data: places } = placesFetch
const { data: prezero, error: prezeroError } = prezeroFetch
const { data: sensors } = sensorsFetch
const { data: context } = contextFetch
const { data: meta } = metaFetch
const { data: plan, error: planError, pending: planPending, refresh: refreshPlan } = planFetch
watch(
sensors,
(list) => {
if (list?.length && !list.some((sensor) => sensor.id === sensorId.value)) {
sensorId.value = list[0]!.id
}
},
{ immediate: true },
)
watch(
() => live.revision,
() => {
void refreshPlan()
},
)
const bundle = computed(() => routeBundle.value ?? pendingCoolRouteBundle())
const routePending = computed(() => !routeBundle.value || bundle.value.status !== 'ready')
const sensorCount = computed(() => meta.value?.coverage.sensors ?? sensors.value?.length ?? 0)
const cadenceMin = computed(() => meta.value?.coverage.cadence_min ?? null)
const scenarioName = computed(() => live.scenarioId)
const routeErrorText = computed(() =>
routeError.value ? 'The route bundle could not be loaded.' : '',
)
const planErrorText = computed(() =>
planError.value ? 'The live staffing plan is unavailable. The last known response is not invented.' : '',
)
const prezeroErrorText = computed(() =>
prezeroError.value ? 'The PreZero snapshot could not be loaded.' : '',
)
useHead({
title: 'Pulse Engine · SIT',
meta: [
{
name: 'description',
content:
'Three operational decisions from one privacy-preserving sensing engine: staffing, smart micro-climate routing and PreZero container priority.',
},
{ name: 'theme-color', content: '#081723' },
],
})
</script>
<template>
<div class="flex min-h-dvh flex-col">
<main class="w-full flex-1 bg-[#081723] pt-16">
<div class="mx-auto flex w-full max-w-[1240px] flex-col gap-6 px-4 pb-12 pt-4 md:px-8">
<!-- Section heading -->
<section class="flex flex-col justify-between gap-4 pt-4 md:flex-row md:items-end">
<div class="flex max-w-2xl flex-col gap-1.5">
<div class="flex flex-wrap items-center gap-2">
<span class="text-[11px] font-bold uppercase tracking-widest text-[#00C3CD]">
Section 03 / Operational decisions
</span>
<span class="text-[#64748B]" aria-hidden="true">•</span>
<span class="text-[12px] font-medium text-[#94A3B8]">{{ activeTab.title }}</span>
</div>
<h1 class="text-2xl font-bold leading-tight tracking-tight text-white md:text-3xl lg:text-[34px]">
Real-time decision intelligence.
</h1>
<p class="max-w-2xl text-sm font-normal text-[#94A3B8] md:text-base">
One crisp answer per use case, with the real mathematical rationale attached. No invented confidence
scores.
</p>
</div>
<div class="flex items-center gap-3 self-start rounded-xl border border-[#1e3a52] bg-[#0e2233] px-4 py-2.5 md:self-auto">
<Icon name="material-symbols:bolt" class="text-[22px] text-[#00C3CD]" />
<div class="flex flex-col">
<span class="text-[11px] font-semibold uppercase tracking-wider text-[#94A3B8]">Decision latency</span>
<span class="font-mono text-lg font-bold leading-tight text-[#00C3CD]">
{{ activeLatency ? `${activeLatency} ms` : '—' }}
</span>
<span class="text-[9px] text-[#64748B]">last data load</span>
</div>
</div>
</section>
<UseCaseTabs :active="active" />
<LiveTelemetryBar
:status="live.status"
:scenario-id="scenarioName"
:sensor-count="sensorCount"
:cadence-min="cadenceMin"
:last-event-at="live.lastEventAt"
/>
<div
v-if="active === 'routing' && routeErrorText"
class="rounded-xl border border-[#1e3a52] bg-[#132b40] p-4 text-sm text-[#94A3B8]"
role="alert"
>
{{ routeErrorText }} The map and comparison are hidden rather than filled with estimates.
</div>
<div
v-if="active === 'routing' && routePending && !routeErrorText"
class="rounded-xl border border-[#1e3a52] bg-[#132b40] p-4 text-sm text-[#94A3B8]"
role="status"
>
Route/shade bundle pending. No estimates shown.
</div>
<RoutingPanel
v-if="active === 'routing'"
:bundle="bundle"
:buildings="buildings?.buildings ?? null"
:places="places"
:sensors="sensors ?? null"
:time="time"
@update:time="selectTime"
/>
<StaffingPanel
v-else-if="active === 'staffing'"
:plan="plan ?? null"
:sensors="sensors ?? null"
:context="context ?? null"
:sensor-id="sensorId"
:pending="planPending"
:error="planErrorText"
@update:sensor-id="sensorId = $event"
@refresh="refreshPlan"
/>
<PrezeroPanel
v-else
:bundle="prezero ?? null"
:error="prezeroErrorText"
/>
</div>
</main>
<footer class="w-full border-t border-[#1e3a52] bg-[#0e2233] py-6">
<div class="mx-auto flex max-w-[1240px] flex-col items-center justify-between gap-4 px-4 text-xs font-normal text-[#94A3B8] md:flex-row md:px-8">
<div class="flex flex-wrap items-center gap-3">
<span>© 2026 Schwarz Digits. All rights reserved.</span>
<span class="text-[#64748B]" aria-hidden="true">|</span>
<span class="flex items-center gap-1 font-medium text-[#00C3CD]">
<Icon name="material-symbols:verified-user" class="text-[15px]" />
Counts, not identities · GDPR by design
</span>
</div>
<div class="flex flex-wrap items-center gap-3">
<span class="flex items-center gap-1.5">
<span
class="h-2 w-2 rounded-full"
:class="
live.status === 'live'
? 'animate-pulse bg-[#00C3CD]'
: live.status === 'offline'
? 'bg-[#64748B]'
: 'bg-[#94A3B8]'
"
aria-hidden="true"
/>
<span class="font-medium text-white">
{{ live.status === 'live' ? 'System status: stream live' : `System status: ${live.status}` }}
</span>
</span>
<span class="text-[#64748B]" aria-hidden="true">|</span>
<span class="rounded border border-[#1e3a52] bg-[#132b40] px-2 py-0.5 font-mono text-[11px] font-semibold text-[#00C3CD]">
v1.10-use-cases
</span>
</div>
</div>
</footer>
</div>
</template>