feat: add operational use cases console
This commit is contained in:
1 parent
78d1f0e308
commit
8d687ad05b
19 files changed
+4707
-12
No files matched your search
+5
-1
@@ -15,7 +15,11 @@ const usingMock = computed(() => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const isNewShell = computed(
|
const isNewShell = computed(
|
||||||
() => route.path === '/' || route.path.startsWith('/sensors') || route.path.startsWith('/playground'),
|
() =>
|
||||||
|
route.path === '/' ||
|
||||||
|
route.path.startsWith('/sensors') ||
|
||||||
|
route.path.startsWith('/playground') ||
|
||||||
|
route.path.startsWith('/use-cases'),
|
||||||
)
|
)
|
||||||
const isCool = computed(() => route.path.startsWith('/cool'))
|
const isCool = computed(() => route.path.startsWith('/cool'))
|
||||||
const isDarkPresentation = computed(
|
const isDarkPresentation = computed(
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
withDefaults(
|
||||||
|
defineProps<{
|
||||||
|
label: string
|
||||||
|
value: string
|
||||||
|
hint?: string
|
||||||
|
tone?: 'default' | 'accent'
|
||||||
|
mono?: boolean
|
||||||
|
}>(),
|
||||||
|
{
|
||||||
|
hint: '',
|
||||||
|
tone: 'default',
|
||||||
|
mono: true,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="flex flex-col rounded-lg border border-[#1e3a52] bg-[#0e2233] p-2.5">
|
||||||
|
<span class="text-[11px] text-[#94A3B8]">{{ label }}</span>
|
||||||
|
<span
|
||||||
|
class="mt-0.5 text-lg font-bold leading-tight"
|
||||||
|
:class="[tone === 'accent' ? 'text-[#00C3CD]' : 'text-[#FFFFFF]', mono ? 'font-mono' : '']"
|
||||||
|
>
|
||||||
|
{{ value }}
|
||||||
|
</span>
|
||||||
|
<span v-if="hint" class="text-[10px] text-[#64748B]">{{ hint }}</span>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { LIVE_LABELS, liveAge, scenarioLabel } from '#shared/live'
|
||||||
|
import type { LiveConnection } from '#shared/live'
|
||||||
|
import MiniBar from '~/components/use-cases/MiniBar.vue'
|
||||||
|
|
||||||
|
const props = withDefaults(
|
||||||
|
defineProps<{
|
||||||
|
status: LiveConnection
|
||||||
|
scenarioId: string
|
||||||
|
sensorCount: number
|
||||||
|
cadenceMin: number | null
|
||||||
|
lastEventAt: string
|
||||||
|
}>(),
|
||||||
|
{ cadenceMin: null, lastEventAt: '' },
|
||||||
|
)
|
||||||
|
|
||||||
|
const now = ref(Date.now())
|
||||||
|
let timer: ReturnType<typeof setInterval> | undefined
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
now.value = Date.now()
|
||||||
|
timer = setInterval(() => {
|
||||||
|
now.value = Date.now()
|
||||||
|
}, 1000)
|
||||||
|
})
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
if (timer) clearInterval(timer)
|
||||||
|
})
|
||||||
|
|
||||||
|
const age = computed(() => (props.lastEventAt ? liveAge(props.lastEventAt, now.value) : 'SSR payload'))
|
||||||
|
const isLive = computed(() => props.status === 'live')
|
||||||
|
const statusLabel = computed(() =>
|
||||||
|
isLive.value ? 'SCENARIO STREAM: LIVE' : `SCENARIO STREAM: ${LIVE_LABELS[props.status].toUpperCase()}`,
|
||||||
|
)
|
||||||
|
const coveragePct = computed(() => (props.sensorCount > 0 ? Math.min(100, (props.sensorCount / 8) * 100) : 0))
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<section
|
||||||
|
aria-label="Live telemetry"
|
||||||
|
class="relative flex w-full flex-col items-start justify-between gap-4 overflow-hidden rounded-xl border border-[#1e3a52] bg-[#0e2233] p-3.5 shadow-sm md:flex-row md:items-center"
|
||||||
|
>
|
||||||
|
<div class="absolute inset-y-0 left-0 w-1" :class="isLive ? 'bg-[#00C3CD]' : 'bg-[#475569]'" aria-hidden="true" />
|
||||||
|
<div class="flex flex-wrap items-center gap-4 pl-2">
|
||||||
|
<div
|
||||||
|
class="flex items-center gap-2 rounded border px-2.5 py-1"
|
||||||
|
:class="
|
||||||
|
isLive
|
||||||
|
? 'border-[#00C3CD]/30 bg-[#00C3CD]/15'
|
||||||
|
: 'border-white/10 bg-white/[0.06]'
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
class="h-2 w-2 rounded-full"
|
||||||
|
:class="isLive ? 'animate-pulse bg-[#00C3CD]' : 'bg-[#94A3B8]'"
|
||||||
|
aria-hidden="true"
|
||||||
|
/>
|
||||||
|
<span
|
||||||
|
class="text-[11px] font-bold tracking-wider"
|
||||||
|
:class="isLive ? 'text-[#00C3CD]' : 'text-[#94A3B8]'"
|
||||||
|
>
|
||||||
|
{{ statusLabel }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<span class="flex items-center gap-1.5 text-xs text-white md:text-sm">
|
||||||
|
<span class="text-[#94A3B8]">Sensor nodes:</span>
|
||||||
|
{{ sensorCount }} counted
|
||||||
|
</span>
|
||||||
|
<span class="hidden text-[#64748B] sm:inline" aria-hidden="true">•</span>
|
||||||
|
<span class="hidden items-center gap-1.5 text-xs text-[#94A3B8] sm:flex md:text-sm">
|
||||||
|
Cadence:
|
||||||
|
<span class="font-mono text-white">{{ cadenceMin ? `${cadenceMin} min` : '—' }}</span>
|
||||||
|
</span>
|
||||||
|
<span class="hidden text-[#64748B] lg:inline" aria-hidden="true">•</span>
|
||||||
|
<span class="hidden text-xs text-[#94A3B8] lg:inline md:text-sm">
|
||||||
|
Scenario:
|
||||||
|
<span class="font-mono text-[#00C3CD]">{{ scenarioLabel(scenarioId) }}</span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex w-full items-center justify-between gap-4 pl-2 md:w-auto md:justify-end md:pl-0">
|
||||||
|
<div class="flex w-36 flex-col gap-1">
|
||||||
|
<div class="flex items-center justify-between text-[11px] text-[#94A3B8]">
|
||||||
|
<span>Sensor coverage</span>
|
||||||
|
<span class="font-mono font-semibold text-white">{{ sensorCount }}/8</span>
|
||||||
|
</div>
|
||||||
|
<MiniBar :value="coveragePct" label="Sensor coverage" />
|
||||||
|
</div>
|
||||||
|
<span class="shrink-0 text-[11px] font-medium text-[#94A3B8]">Updated {{ age }}</span>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
withDefaults(
|
||||||
|
defineProps<{
|
||||||
|
value: number
|
||||||
|
tone?: 'accent' | 'muted' | 'subtle'
|
||||||
|
label?: string
|
||||||
|
height?: 'sm' | 'md'
|
||||||
|
}>(),
|
||||||
|
{
|
||||||
|
tone: 'accent',
|
||||||
|
label: '',
|
||||||
|
height: 'sm',
|
||||||
|
},
|
||||||
|
)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div
|
||||||
|
class="w-full overflow-hidden rounded-full border border-white/10 bg-[#081723]"
|
||||||
|
:class="height === 'md' ? 'h-2' : 'h-1.5'"
|
||||||
|
role="img"
|
||||||
|
:aria-label="label || `${Math.round(value)} percent`"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="h-full rounded-full transition-all duration-500"
|
||||||
|
:class="{
|
||||||
|
'bg-[#00C3CD] shadow-[0_0_8px_rgba(0,195,205,0.55)]': tone === 'accent',
|
||||||
|
'bg-[#94A3B8]': tone === 'muted',
|
||||||
|
'bg-[#475569]': tone === 'subtle',
|
||||||
|
}"
|
||||||
|
:style="{ width: `${Math.max(0, Math.min(100, value))}%` }"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,397 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import type { PrezeroBundle, PrezeroContainer } from '#shared/use-cases'
|
||||||
|
import {
|
||||||
|
PRIORITY_ORDER,
|
||||||
|
prezeroReason,
|
||||||
|
prezeroTotal,
|
||||||
|
priorityShare,
|
||||||
|
shortContainerId,
|
||||||
|
} from '#shared/use-cases'
|
||||||
|
import DecisionMetric from '~/components/use-cases/DecisionMetric.vue'
|
||||||
|
import MiniBar from '~/components/use-cases/MiniBar.vue'
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
bundle: PrezeroBundle | null
|
||||||
|
error: string
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const ruleOpen = ref(false)
|
||||||
|
const exportNote = ref('')
|
||||||
|
|
||||||
|
const PRIORITY_LABELS: Record<PrezeroContainer['priority'], string> = {
|
||||||
|
high: 'High',
|
||||||
|
medium: 'Medium',
|
||||||
|
low: 'Low',
|
||||||
|
}
|
||||||
|
|
||||||
|
const PRIORITY_TONE: Record<PrezeroContainer['priority'], 'accent' | 'muted' | 'subtle'> = {
|
||||||
|
high: 'accent',
|
||||||
|
medium: 'muted',
|
||||||
|
low: 'subtle',
|
||||||
|
}
|
||||||
|
|
||||||
|
const PRIORITY_DOT: Record<PrezeroContainer['priority'], string> = { high: 'bg-[#00C3CD]', medium: 'bg-[#94A3B8]', low: 'bg-[#64748B]' }
|
||||||
|
|
||||||
|
const PRIORITY_BADGE: Record<PrezeroContainer['priority'], string> = {
|
||||||
|
high: 'border-[#00C3CD]/40 bg-[#00C3CD]/15 text-[#00C3CD]',
|
||||||
|
medium: 'border-[#1e3a52] bg-white/10 text-[#94A3B8]',
|
||||||
|
low: 'border-[#1e3a52] bg-[#081723] text-[#64748B]',
|
||||||
|
}
|
||||||
|
|
||||||
|
const MATERIAL_ORDER = ['white', 'green', 'brown'] as const
|
||||||
|
const MATERIAL_META = {
|
||||||
|
white: { label: 'White glass', icon: 'material-symbols:local-drink', iconClass: 'text-[#94A3B8]' },
|
||||||
|
green: { label: 'Green glass', icon: 'material-symbols:eco', iconClass: 'text-[#00C3CD]' },
|
||||||
|
brown: { label: 'Brown glass', icon: 'material-symbols:inventory-2', iconClass: 'text-[#64748B]' },
|
||||||
|
} as const
|
||||||
|
|
||||||
|
const total = computed(() => prezeroTotal(props.bundle))
|
||||||
|
const highCount = computed(() => props.bundle?.summary.priority_counts.high ?? 0)
|
||||||
|
const highShare = computed(() => priorityShare(props.bundle, 'high'))
|
||||||
|
const top = computed(() => props.bundle?.top ?? [])
|
||||||
|
const limitations = computed(() => props.bundle?.meta.limitations ?? [])
|
||||||
|
|
||||||
|
const distribution = computed(() =>
|
||||||
|
PRIORITY_ORDER.map((priority) => ({
|
||||||
|
priority,
|
||||||
|
label: PRIORITY_LABELS[priority],
|
||||||
|
count: props.bundle?.summary.priority_counts[priority] ?? 0,
|
||||||
|
share: priorityShare(props.bundle, priority),
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
|
||||||
|
const materialRows = computed(() => {
|
||||||
|
const materials = props.bundle?.summary.by_material
|
||||||
|
if (!materials) return []
|
||||||
|
return MATERIAL_ORDER.flatMap((key) => {
|
||||||
|
const stats = materials[key]
|
||||||
|
if (!stats) return []
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
key,
|
||||||
|
...MATERIAL_META[key],
|
||||||
|
readings: stats.readings,
|
||||||
|
overfull: stats.overfull,
|
||||||
|
share: stats.readings > 0 ? (stats.overfull / stats.readings) * 100 : 0,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
function fmt(value: number): string {
|
||||||
|
return String(Math.round(value)).replace(/\B(?=(\d{3})+(?!\d))/g, ',')
|
||||||
|
}
|
||||||
|
|
||||||
|
function csvCell(value: unknown): string {
|
||||||
|
const text = value == null ? '' : String(value)
|
||||||
|
return /[",\n]/.test(text) ? `"${text.replaceAll('"', '""')}"` : text
|
||||||
|
}
|
||||||
|
|
||||||
|
function exportCsv() {
|
||||||
|
if (!props.bundle || props.bundle.top.length === 0) return
|
||||||
|
try {
|
||||||
|
const header = ['rank', 'location_id', 'priority', 'priority_score', 'readings', 'overfull_count', 'overfull_rate', 'p95_fill', 'max_fill', 'mean_fill', 'last_fill', 'last_is_overfull', 'last_date', 'days_since_last', 'trend']
|
||||||
|
const rows = props.bundle.top.map((row, index) => [index + 1, row.location_id, row.priority, row.priority_score, row.readings, row.overfull_count, row.overfull_rate, row.p95_fill, row.max_fill, row.mean_fill, row.last_fill, row.last_is_overfull, row.last_date, row.days_since_last, row.trend])
|
||||||
|
const csv = [header, ...rows].map((line) => line.map(csvCell).join(',')).join('\r\n')
|
||||||
|
const blob = new Blob([`\uFEFF${csv}`], { type: 'text/csv;charset=utf-8' })
|
||||||
|
const url = URL.createObjectURL(blob)
|
||||||
|
const anchor = document.createElement('a')
|
||||||
|
anchor.href = url
|
||||||
|
anchor.download = `sensing-engine-prezero-priority-${props.bundle.meta.reference_date}.csv`
|
||||||
|
anchor.click()
|
||||||
|
anchor.remove()
|
||||||
|
URL.revokeObjectURL(url)
|
||||||
|
exportNote.value = `Exported ${props.bundle.top.length} ranked locations; ${total.value} locations in the snapshot.`
|
||||||
|
} catch {
|
||||||
|
exportNote.value = 'The browser blocked the download; no file was created.'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="grid grid-cols-1 items-start gap-6 lg:grid-cols-12">
|
||||||
|
<div
|
||||||
|
v-if="error"
|
||||||
|
class="rounded-xl border border-[#1e3a52] bg-[#132b40] p-4 text-sm text-[#94A3B8] lg:col-span-12"
|
||||||
|
role="alert"
|
||||||
|
>
|
||||||
|
<div class="flex items-start gap-3">
|
||||||
|
<Icon name="material-symbols:info" class="mt-0.5 text-[20px] text-[#00C3CD]" />
|
||||||
|
<div class="flex flex-col gap-0.5">
|
||||||
|
<span class="font-semibold text-white">Priority snapshot unavailable</span>
|
||||||
|
<span>{{ error }} No ranking is estimated or filled in.</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<template v-if="bundle">
|
||||||
|
<!-- LEFT: decision story -->
|
||||||
|
<div class="flex min-w-0 flex-col gap-6 lg:col-span-5">
|
||||||
|
<section class="relative flex flex-col gap-5 overflow-hidden rounded-xl border border-[#1e3a52] bg-[#0e2233] p-6 shadow-sm">
|
||||||
|
<div class="flex flex-col gap-1">
|
||||||
|
<span class="text-[11px] font-semibold uppercase tracking-widest text-[#00C3CD]">Optimization query</span>
|
||||||
|
<h2 class="text-lg font-bold leading-snug tracking-tight text-white md:text-xl">
|
||||||
|
Which containers need collection first?
|
||||||
|
</h2>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="relative flex flex-col gap-3 rounded-xl border border-[#00C3CD]/30 bg-[#132b40] p-5 shadow-inner">
|
||||||
|
<div class="flex flex-wrap items-center justify-between gap-2">
|
||||||
|
<span class="text-[11px] font-bold uppercase tracking-wider text-[#00C3CD]">Priority answer</span>
|
||||||
|
<span class="rounded border border-[#00C3CD]/40 bg-[#00C3CD]/15 px-2 py-0.5 font-mono text-[10px] font-bold text-[#00C3CD]">
|
||||||
|
RULE OUTPUT · {{ bundle.meta.reference_date }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="flex flex-col">
|
||||||
|
<span class="text-2xl font-extrabold tracking-tight text-white md:text-3xl">
|
||||||
|
{{ fmt(highCount) }} high-priority {{ highCount === 1 ? 'location' : 'locations' }}
|
||||||
|
</span>
|
||||||
|
<span class="mt-1 text-[12px] font-semibold leading-snug text-[#00C3CD]">
|
||||||
|
High if 5+ overfull readings, or 2+ with at least 25% of visits overfull.
|
||||||
|
</span>
|
||||||
|
<span class="mt-1 text-[11px] leading-snug text-[#94A3B8]">
|
||||||
|
Priority proof, not a route. {{ highShare.toFixed(1) }}% of all {{ fmt(total) }} locations clear the
|
||||||
|
high threshold.
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="grid grid-cols-2 gap-2.5">
|
||||||
|
<DecisionMetric
|
||||||
|
label="Container locations"
|
||||||
|
:value="fmt(total)"
|
||||||
|
hint="rule-scored IDs"
|
||||||
|
tone="accent"
|
||||||
|
/>
|
||||||
|
<DecisionMetric
|
||||||
|
label="Overfull readings"
|
||||||
|
:value="fmt(bundle.meta.overfull_readings)"
|
||||||
|
hint="reported states"
|
||||||
|
/>
|
||||||
|
<DecisionMetric
|
||||||
|
label="High-priority share"
|
||||||
|
:value="`${highShare.toFixed(1)}%`"
|
||||||
|
:hint="`${fmt(highCount)} of ${fmt(total)}`"
|
||||||
|
tone="accent"
|
||||||
|
/>
|
||||||
|
<DecisionMetric
|
||||||
|
label="Review window"
|
||||||
|
:value="bundle.meta.date_from"
|
||||||
|
:hint="`to ${bundle.meta.date_to}`"
|
||||||
|
:mono="false"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-col gap-1.5">
|
||||||
|
<span class="text-[11px] font-bold uppercase tracking-wider text-[#94A3B8]">Fused rationale</span>
|
||||||
|
<div class="rounded-lg border border-[#1e3a52] bg-[#081723] p-3">
|
||||||
|
<span class="mb-1 block text-[10px] font-semibold uppercase tracking-wider text-[#64748B]">Priority rule</span>
|
||||||
|
<p class="break-words font-mono text-[10px] leading-relaxed text-[#94A3B8]">
|
||||||
|
{{ bundle.meta.priority_rule }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<p class="text-sm leading-relaxed text-[#94A3B8]">
|
||||||
|
The snapshot applies that rule once to every container's full reading history. The classification uses
|
||||||
|
observed overfull counts and the overfull rate only. Overfull is a reported state in the fill-level
|
||||||
|
series, not a measured volume, and the artifact has no coordinates. It therefore proves priority; it does
|
||||||
|
not produce a route.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-col gap-2.5 pt-1">
|
||||||
|
<span class="text-[11px] font-bold uppercase tracking-wider text-[#94A3B8]">Material summary</span>
|
||||||
|
<div
|
||||||
|
v-for="material in materialRows"
|
||||||
|
:key="material.key"
|
||||||
|
class="flex items-center justify-between gap-3 rounded-lg border border-white/10 bg-[#132b40] p-3"
|
||||||
|
>
|
||||||
|
<div class="flex min-w-0 items-center gap-3">
|
||||||
|
<Icon :name="material.icon" class="shrink-0 text-[20px]" :class="material.iconClass" />
|
||||||
|
<div class="flex min-w-0 flex-col">
|
||||||
|
<span class="text-[13px] font-semibold text-white">{{ material.label }}</span>
|
||||||
|
<span class="text-[11px] text-[#94A3B8]">
|
||||||
|
{{ fmt(material.readings) }} readings · {{ fmt(material.overfull) }} overfull
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<span
|
||||||
|
class="shrink-0 rounded border border-[#00C3CD]/30 bg-[#00C3CD]/15 px-2 py-0.5 font-mono text-[11px] font-semibold text-[#00C3CD]"
|
||||||
|
:aria-label="`${material.share.toFixed(1)} percent of ${material.label} readings overfull`"
|
||||||
|
>
|
||||||
|
{{ material.share.toFixed(1) }}% overfull
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex items-start gap-2 rounded-lg border border-[#1e3a52] bg-[#081723] p-3">
|
||||||
|
<Icon name="material-symbols:info" class="mt-0.5 shrink-0 text-[16px] text-[#64748B]" />
|
||||||
|
<p class="text-[10px] leading-relaxed text-[#64748B]">
|
||||||
|
No coordinates in the dataset; no container capacity or depot data. This is a priority proof, not a
|
||||||
|
route.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-col gap-2 pt-1">
|
||||||
|
<div class="flex flex-col gap-2.5 sm:flex-row sm:items-center">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="flex h-10 w-full items-center justify-center gap-2 rounded-lg bg-[#00C3CD] px-4 text-[13px] font-semibold text-[#081723] shadow-[0_0_16px_rgba(0,195,205,0.3)] transition-all hover:bg-[#00d8e4] disabled:cursor-not-allowed disabled:opacity-60 sm:w-auto sm:flex-1"
|
||||||
|
:disabled="top.length === 0"
|
||||||
|
@click="exportCsv"
|
||||||
|
>
|
||||||
|
<Icon name="material-symbols:download" class="text-[18px]" />
|
||||||
|
Export priority CSV
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="flex h-10 w-full items-center justify-center gap-1.5 rounded-lg border border-[#1e3a52] bg-[#132b40] px-4 text-[13px] font-semibold text-[#94A3B8] transition-all hover:bg-[#1e3a52] hover:text-white sm:w-auto"
|
||||||
|
:aria-expanded="ruleOpen"
|
||||||
|
@click="ruleOpen = !ruleOpen"
|
||||||
|
>
|
||||||
|
<Icon name="material-symbols:query-stats" class="text-[18px]" />
|
||||||
|
Inspect rule
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<p v-if="exportNote" class="text-[10px] text-[#94A3B8]" role="status">{{ exportNote }}</p>
|
||||||
|
<div
|
||||||
|
v-if="ruleOpen"
|
||||||
|
class="flex flex-col gap-2 rounded-lg border border-[#1e3a52] bg-[#081723] p-3 text-[11px] leading-relaxed text-[#94A3B8]"
|
||||||
|
>
|
||||||
|
<p>
|
||||||
|
<strong class="text-white">Rule.</strong>
|
||||||
|
<span class="break-words font-mono text-[10px]">{{ bundle.meta.priority_rule }}</span>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<strong class="text-white">Counts.</strong>
|
||||||
|
{{ fmt(bundle.meta.rows) }} readings across {{ fmt(bundle.meta.containers) }} containers;
|
||||||
|
{{ fmt(bundle.meta.overfull_readings) }} overfull readings. Classes:
|
||||||
|
{{ fmt(bundle.summary.priority_counts.high) }} high /
|
||||||
|
{{ fmt(bundle.summary.priority_counts.medium) }} medium /
|
||||||
|
{{ fmt(bundle.summary.priority_counts.low) }} low.
|
||||||
|
</p>
|
||||||
|
<ul class="list-disc space-y-1 pl-4">
|
||||||
|
<li v-for="limitation in limitations" :key="limitation">{{ limitation }}</li>
|
||||||
|
</ul>
|
||||||
|
<p class="break-words text-[#64748B]">
|
||||||
|
Source: {{ bundle.meta.source }} · generated {{ bundle.meta.generated_at }} · reviewed
|
||||||
|
{{ bundle.meta.date_from }} → {{ bundle.meta.date_to }}.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- RIGHT: visual data story -->
|
||||||
|
<div class="flex min-w-0 flex-col gap-6 lg:col-span-7">
|
||||||
|
<section class="flex flex-col gap-4 rounded-xl border border-[#1e3a52] bg-[#0e2233] p-5 shadow-sm md:p-6">
|
||||||
|
<div class="flex flex-wrap items-center justify-between gap-2">
|
||||||
|
<div class="flex flex-col">
|
||||||
|
<span class="text-[11px] font-semibold uppercase tracking-widest text-[#00C3CD]">Frozen priority rule</span>
|
||||||
|
<h3 class="mt-0.5 text-base font-bold text-white">Priority distribution</h3>
|
||||||
|
</div>
|
||||||
|
<span class="rounded border border-[#1e3a52] bg-[#132b40] px-2.5 py-1 font-mono text-[11px] text-[#94A3B8]">
|
||||||
|
{{ fmt(total) }} locations
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-col gap-4 pt-1">
|
||||||
|
<div v-for="row in distribution" :key="row.priority" class="flex flex-col gap-1.5">
|
||||||
|
<div class="flex flex-wrap items-baseline justify-between gap-x-3 gap-y-0.5">
|
||||||
|
<span class="flex items-center gap-2 text-[12px] font-semibold text-white">
|
||||||
|
<span class="h-1.5 w-1.5 rounded-full" :class="PRIORITY_DOT[row.priority]" aria-hidden="true" />
|
||||||
|
{{ row.label }}
|
||||||
|
</span>
|
||||||
|
<span class="font-mono text-[12px] font-semibold text-white">
|
||||||
|
{{ fmt(row.count) }}
|
||||||
|
<span class="font-normal text-[#94A3B8]">· {{ row.share.toFixed(1) }}%</span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<MiniBar
|
||||||
|
:value="row.share"
|
||||||
|
:tone="PRIORITY_TONE[row.priority]"
|
||||||
|
height="md"
|
||||||
|
:label="`${row.label} priority: ${fmt(row.count)} of ${fmt(total)} locations, ${row.share.toFixed(1)} percent`"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p class="text-[10px] leading-relaxed text-[#64748B]">
|
||||||
|
Counts are container locations, not readings. Priority is a deterministic rule output, not a modeled
|
||||||
|
confidence score.
|
||||||
|
</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="flex flex-col gap-4 rounded-xl border border-[#1e3a52] bg-[#0e2233] p-5 shadow-sm md:p-6">
|
||||||
|
<div class="flex flex-wrap items-center justify-between gap-2">
|
||||||
|
<div class="flex flex-col">
|
||||||
|
<span class="text-[11px] font-semibold uppercase tracking-widest text-[#00C3CD]">Top of the frozen ranking</span>
|
||||||
|
<h3 class="mt-0.5 text-base font-bold text-white">Container priority matrix</h3>
|
||||||
|
</div>
|
||||||
|
<span class="rounded border border-[#1e3a52] bg-[#132b40] px-2.5 py-1 font-mono text-[11px] text-[#94A3B8]">
|
||||||
|
{{ top.length }} rows
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-col gap-2">
|
||||||
|
<article
|
||||||
|
v-for="(row, index) in top"
|
||||||
|
:key="row.location_id"
|
||||||
|
class="flex flex-col gap-1.5 rounded-lg border border-[#1e3a52] bg-[#132b40] px-3 py-2.5 transition-colors hover:border-[#64748B]/60"
|
||||||
|
>
|
||||||
|
<div class="flex flex-wrap items-center gap-x-2 gap-y-1">
|
||||||
|
<span class="w-6 shrink-0 font-mono text-[10px] text-[#64748B]">
|
||||||
|
{{ String(index + 1).padStart(2, '0') }}
|
||||||
|
</span>
|
||||||
|
<span class="font-mono text-[12px] font-semibold text-white">{{ shortContainerId(row.location_id) }}</span>
|
||||||
|
<span class="rounded border px-1.5 py-0.5 text-[9px] font-bold uppercase tracking-wide" :class="PRIORITY_BADGE[row.priority]">
|
||||||
|
{{ row.priority }}
|
||||||
|
</span>
|
||||||
|
<span class="ml-auto flex items-center gap-2 font-mono text-[10px] text-[#94A3B8]">
|
||||||
|
<span><span class="font-semibold text-white">{{ fmt(row.overfull_count) }}</span> overfull</span>
|
||||||
|
<span class="text-[#64748B]" aria-hidden="true">·</span>
|
||||||
|
<span>p95 <span class="font-semibold text-white">{{ Math.round(row.p95_fill) }}%</span></span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<MiniBar
|
||||||
|
:value="row.overfull_rate * 100"
|
||||||
|
:tone="PRIORITY_TONE[row.priority]"
|
||||||
|
:label="`Container ${shortContainerId(row.location_id)} overfull rate ${(row.overfull_rate * 100).toFixed(1)} percent`"
|
||||||
|
/>
|
||||||
|
<span class="shrink-0 font-mono text-[10px] text-[#64748B]">
|
||||||
|
{{ (row.overfull_rate * 100).toFixed(1) }}%
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<p class="text-[11px] leading-snug text-[#64748B]">{{ prezeroReason(row) }}</p>
|
||||||
|
</article>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex items-start gap-2 rounded-lg border border-[#1e3a52] bg-[#081723] p-3">
|
||||||
|
<Icon name="material-symbols:info" class="mt-0.5 shrink-0 text-[16px] text-[#64748B]" />
|
||||||
|
<p class="text-[10px] leading-relaxed text-[#64748B]">
|
||||||
|
No map: the dataset has no coordinates. This is a priority proof, not a route.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<section
|
||||||
|
v-else
|
||||||
|
class="flex flex-col items-center justify-center gap-3 rounded-xl border border-[#1e3a52] bg-[#0e2233] p-8 text-center shadow-sm lg:col-span-12"
|
||||||
|
role="status"
|
||||||
|
>
|
||||||
|
<div class="flex h-11 w-11 items-center justify-center rounded-lg border border-[#1e3a52] bg-[#132b40] text-[#00C3CD]">
|
||||||
|
<Icon name="material-symbols:recycling" class="text-[24px]" />
|
||||||
|
</div>
|
||||||
|
<div class="flex max-w-md flex-col gap-1">
|
||||||
|
<span class="text-base font-bold text-white">Priority snapshot not loaded</span>
|
||||||
|
<p class="text-sm leading-relaxed text-[#94A3B8]">
|
||||||
|
The frozen PreZero artifact is unavailable. The location ranking and summary stay hidden rather than being
|
||||||
|
filled with estimates.
|
||||||
|
</p>
|
||||||
|
<p class="text-[11px] text-[#64748B]">Expected artifact: /prezero/priority.json</p>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,362 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import type { CoolRouteBundle, CoolRouteId } from '#shared/cool'
|
||||||
|
import { ROUTE_ORDER, routeValuesFor } from '#shared/use-cases'
|
||||||
|
|
||||||
|
interface BuildingPolygon {
|
||||||
|
name: string | null
|
||||||
|
kind: string
|
||||||
|
points: Array<[number, number]>
|
||||||
|
}
|
||||||
|
|
||||||
|
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 props = defineProps<{
|
||||||
|
bundle: CoolRouteBundle
|
||||||
|
buildings: BuildingPolygon[] | null
|
||||||
|
places: PlacesBundle | null
|
||||||
|
selectedRouteId: CoolRouteId
|
||||||
|
time: string
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const WIDTH = 760
|
||||||
|
const HEIGHT = 380
|
||||||
|
const PAD = 34
|
||||||
|
|
||||||
|
const zoom = ref(1)
|
||||||
|
const map = ref<SVGSVGElement | null>(null)
|
||||||
|
const viewBox = computed(() => {
|
||||||
|
if (zoom.value === 1) return `0 0 ${WIDTH} ${HEIGHT}`
|
||||||
|
const w = WIDTH / zoom.value
|
||||||
|
const h = HEIGHT / zoom.value
|
||||||
|
return `${(WIDTH - w) / 2} ${(HEIGHT - h) / 2} ${w} ${h}`
|
||||||
|
})
|
||||||
|
|
||||||
|
const bounds = computed(() => {
|
||||||
|
const points = props.bundle.routes.flatMap((route) => route.geometry)
|
||||||
|
if (!points.length) return { minLon: 9.2175, maxLon: 9.2204, minLat: 49.1402, maxLat: 49.1426 }
|
||||||
|
const lons = points.map(([lon]) => lon)
|
||||||
|
const lats = points.map(([, lat]) => lat)
|
||||||
|
return {
|
||||||
|
minLon: Math.min(...lons),
|
||||||
|
maxLon: Math.max(...lons),
|
||||||
|
minLat: Math.min(...lats),
|
||||||
|
maxLat: Math.max(...lats),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
function project([lon, lat]: [number, number]): [number, number] {
|
||||||
|
const b = bounds.value
|
||||||
|
const nx = (lon - b.minLon) / Math.max(b.maxLon - b.minLon, 0.000001)
|
||||||
|
const ny = (b.maxLat - lat) / Math.max(b.maxLat - b.minLat, 0.000001)
|
||||||
|
return [PAD + nx * (WIDTH - PAD * 2), PAD + ny * (HEIGHT - PAD * 2)]
|
||||||
|
}
|
||||||
|
|
||||||
|
function pathFor(routeId: CoolRouteId): string {
|
||||||
|
const route = props.bundle.routes.find((entry) => entry.id === routeId)
|
||||||
|
if (!route || route.geometry.length < 2) return ''
|
||||||
|
const points = route.geometry.map(project)
|
||||||
|
return points.map(([x, y], index) => `${index === 0 ? 'M' : 'L'} ${x.toFixed(2)} ${y.toFixed(2)}`).join(' ')
|
||||||
|
}
|
||||||
|
|
||||||
|
const polygons = computed(() =>
|
||||||
|
(props.buildings ?? []).map((building) => ({
|
||||||
|
...building,
|
||||||
|
d: `${building.points
|
||||||
|
.map(([lon, lat], index) => {
|
||||||
|
const [x, y] = project([lon, lat])
|
||||||
|
return `${index === 0 ? 'M' : 'L'} ${x.toFixed(2)} ${y.toFixed(2)}`
|
||||||
|
})
|
||||||
|
.join(' ')} Z`,
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
|
||||||
|
const routePaths = computed(() =>
|
||||||
|
ROUTE_ORDER.map((id) => ({
|
||||||
|
id,
|
||||||
|
d: pathFor(id),
|
||||||
|
active: id === props.selectedRouteId,
|
||||||
|
recommended: props.bundle.recommendationByTime[props.time] === id,
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
|
||||||
|
const selectedRoute = computed(() =>
|
||||||
|
props.bundle.routes.find((route) => route.id === props.selectedRouteId),
|
||||||
|
)
|
||||||
|
const values = computed(() => routeValuesFor(props.bundle, props.selectedRouteId, props.time))
|
||||||
|
|
||||||
|
const origin = computed(() => {
|
||||||
|
const [x, y] = project([
|
||||||
|
props.bundle.origin.lon ?? 9.218444,
|
||||||
|
props.bundle.origin.lat ?? 49.140269,
|
||||||
|
])
|
||||||
|
return { x, y }
|
||||||
|
})
|
||||||
|
const destination = computed(() => {
|
||||||
|
const [x, y] = project([
|
||||||
|
props.bundle.destination.lon ?? 9.218659,
|
||||||
|
props.bundle.destination.lat ?? 49.142318,
|
||||||
|
])
|
||||||
|
return { x, y }
|
||||||
|
})
|
||||||
|
|
||||||
|
// The shaded route's middle is the real Deutschhof / Kiliansplatz corridor.
|
||||||
|
const corridor = computed(() => {
|
||||||
|
const route = props.bundle.routes.find((entry) => entry.id === 'shaded')
|
||||||
|
if (!route || route.geometry.length < 4) return ''
|
||||||
|
const slice = route.geometry.slice(
|
||||||
|
Math.floor(route.geometry.length * 0.28),
|
||||||
|
Math.ceil(route.geometry.length * 0.78),
|
||||||
|
)
|
||||||
|
return slice
|
||||||
|
.map(([lon, lat], index) => {
|
||||||
|
const [x, y] = project([lon, lat])
|
||||||
|
return `${index === 0 ? 'M' : 'L'} ${x.toFixed(2)} ${y.toFixed(2)}`
|
||||||
|
})
|
||||||
|
.join(' ')
|
||||||
|
})
|
||||||
|
|
||||||
|
const waterPoints = computed(() =>
|
||||||
|
(props.places?.water ?? []).map((place) => {
|
||||||
|
const [x, y] = project([place.lon, place.lat])
|
||||||
|
return { ...place, x, y }
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
|
const benchPoints = computed(() =>
|
||||||
|
(props.places?.benches ?? [])
|
||||||
|
.filter((place) => {
|
||||||
|
const near = place.near_routes_m?.[props.selectedRouteId]
|
||||||
|
return typeof near === 'number' && near <= 30
|
||||||
|
})
|
||||||
|
.slice(0, 7)
|
||||||
|
.map((place) => {
|
||||||
|
const [x, y] = project([place.lon, place.lat])
|
||||||
|
return { ...place, x, y }
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
|
const keyPlaces = computed(() => {
|
||||||
|
const names = ['Kiliansplatz', 'Marktplatz', 'Deutschhof']
|
||||||
|
return (props.places?.cool_places ?? [])
|
||||||
|
.filter((place) => place.name && names.some((name) => place.name!.includes(name)))
|
||||||
|
.slice(0, 3)
|
||||||
|
.map((place) => {
|
||||||
|
const [x, y] = project([place.lon, place.lat])
|
||||||
|
return { ...place, x, y }
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
function zoomBy(delta: number) {
|
||||||
|
zoom.value = Math.max(1, Math.min(2.2, Math.round((zoom.value + delta) * 10) / 10))
|
||||||
|
}
|
||||||
|
function resetZoom() {
|
||||||
|
zoom.value = 1
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<figure class="m-0 flex w-full flex-col gap-2">
|
||||||
|
<div
|
||||||
|
class="relative h-[370px] w-full overflow-hidden rounded-xl border border-[#1e3a52] bg-[#050f17] shadow-inner"
|
||||||
|
>
|
||||||
|
<svg
|
||||||
|
ref="map"
|
||||||
|
class="absolute inset-0 h-full w-full"
|
||||||
|
:viewBox="viewBox"
|
||||||
|
role="img"
|
||||||
|
:aria-label="`Schematic of the ${selectedRoute?.longName ?? selectedRouteId} between ${bundle.origin.name} and ${bundle.destination.name}. Buildings are real OSM footprints; the projection is a schematic and not for navigation.`"
|
||||||
|
preserveAspectRatio="xMidYMid meet"
|
||||||
|
>
|
||||||
|
<defs>
|
||||||
|
<pattern id="uc-grid" width="38" height="38" patternUnits="userSpaceOnUse">
|
||||||
|
<path d="M 38 0 L 0 0 0 38" fill="none" stroke="#102536" stroke-width="0.8" stroke-dasharray="2 3" />
|
||||||
|
</pattern>
|
||||||
|
<marker id="uc-arrow" markerWidth="7" markerHeight="7" refX="5" refY="5" viewBox="0 0 10 10" orient="auto-start-reverse">
|
||||||
|
<path d="M 0 1.5 L 8 5 L 0 8.5 z" fill="#00C3CD" />
|
||||||
|
</marker>
|
||||||
|
<filter id="uc-glow" x="-30%" y="-30%" width="160%" height="160%">
|
||||||
|
<feGaussianBlur stdDeviation="4" result="blur" />
|
||||||
|
<feMerge>
|
||||||
|
<feMergeNode in="blur" />
|
||||||
|
<feMergeNode in="SourceGraphic" />
|
||||||
|
</feMerge>
|
||||||
|
</filter>
|
||||||
|
</defs>
|
||||||
|
|
||||||
|
<rect width="100%" height="100%" fill="url(#uc-grid)" />
|
||||||
|
|
||||||
|
<!-- Real OSM building footprints around the route. -->
|
||||||
|
<path
|
||||||
|
v-for="(building, index) in polygons"
|
||||||
|
:key="`${building.name ?? 'building'}-${index}`"
|
||||||
|
:d="building.d"
|
||||||
|
fill="#0e2233"
|
||||||
|
:stroke="building.name ? '#23445f' : '#1a354c'"
|
||||||
|
stroke-width="0.8"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<!-- Translucent corridor behind the real shaded route. -->
|
||||||
|
<path
|
||||||
|
v-if="corridor"
|
||||||
|
:d="corridor"
|
||||||
|
fill="none"
|
||||||
|
stroke="#00C3CD"
|
||||||
|
stroke-width="26"
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
opacity="0.07"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<!-- Alternatives first. -->
|
||||||
|
<path
|
||||||
|
v-for="path in routePaths.filter((entry) => !entry.active)"
|
||||||
|
:key="path.id"
|
||||||
|
:d="path.d"
|
||||||
|
fill="none"
|
||||||
|
stroke="#64748B"
|
||||||
|
stroke-width="2.4"
|
||||||
|
stroke-dasharray="5 4"
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
opacity="0.55"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<!-- Selected route: glow + line + direction arrow. -->
|
||||||
|
<template v-for="path in routePaths.filter((entry) => entry.active)" :key="`active-${path.id}`">
|
||||||
|
<path
|
||||||
|
:d="path.d"
|
||||||
|
fill="none"
|
||||||
|
stroke="#00C3CD"
|
||||||
|
stroke-width="10"
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
opacity="0.18"
|
||||||
|
filter="url(#uc-glow)"
|
||||||
|
/>
|
||||||
|
<path
|
||||||
|
:d="path.d"
|
||||||
|
fill="none"
|
||||||
|
stroke="#00C3CD"
|
||||||
|
stroke-width="4"
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
marker-end="url(#uc-arrow)"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<!-- Real drinking water points. -->
|
||||||
|
<g v-for="(place, index) in waterPoints" :key="`water-${index}`" :transform="`translate(${place.x} ${place.y})`">
|
||||||
|
<circle r="7" fill="#081723" stroke="#00C3CD" stroke-width="1" opacity="0.9" />
|
||||||
|
<path d="M0 -4 C3 0 4 1.2 4 2.8 A4 4 0 1 1 -4 2.8 C-4 1.2 -3 0 0 -4 Z" fill="#00C3CD" />
|
||||||
|
<title>{{ place.name ?? 'Drinking water' }}</title>
|
||||||
|
</g>
|
||||||
|
|
||||||
|
<!-- Benches within 30 m of the selected route. -->
|
||||||
|
<g v-for="(place, index) in benchPoints" :key="`bench-${index}`" :transform="`translate(${place.x} ${place.y})`">
|
||||||
|
<rect x="-3" y="-2" width="6" height="4" rx="1" fill="#94A3B8" opacity="0.8" />
|
||||||
|
<title>{{ place.name ?? 'Mapped bench' }}</title>
|
||||||
|
</g>
|
||||||
|
|
||||||
|
<!-- Key place labels from the real bundle. -->
|
||||||
|
<g v-for="place in keyPlaces" :key="place.name ?? 'place'" :transform="`translate(${place.x} ${place.y})`">
|
||||||
|
<circle r="2.2" fill="#00C3CD" />
|
||||||
|
<text x="6" y="3" fill="#94A3B8" font-size="8.5" font-family="Inter, sans-serif">{{ place.name }}</text>
|
||||||
|
</g>
|
||||||
|
|
||||||
|
<!-- Origin / destination cards, like a wayfinding board. -->
|
||||||
|
<g :transform="`translate(${origin.x} ${origin.y})`">
|
||||||
|
<circle r="10" fill="#00C3CD" stroke="#081723" stroke-width="2" />
|
||||||
|
<text x="0" y="3.5" text-anchor="middle" fill="#081723" font-size="10" font-weight="700" font-family="Inter, sans-serif">A</text>
|
||||||
|
<g transform="translate(16 -26)">
|
||||||
|
<rect width="132" height="32" rx="6" fill="#132b40" stroke="#00C3CD" stroke-opacity="0.5" />
|
||||||
|
<text x="8" y="12" fill="#94A3B8" font-size="6.5" font-family="Inter, sans-serif" letter-spacing="0.8">START POINT</text>
|
||||||
|
<text x="8" y="24" fill="#FFFFFF" font-size="9" font-weight="600" font-family="Inter, sans-serif">{{ bundle.origin.name }}</text>
|
||||||
|
</g>
|
||||||
|
</g>
|
||||||
|
|
||||||
|
<g :transform="`translate(${destination.x} ${destination.y})`">
|
||||||
|
<circle r="10" fill="#FFFFFF" stroke="#081723" stroke-width="2" />
|
||||||
|
<text x="0" y="3.5" text-anchor="middle" fill="#081723" font-size="10" font-weight="700" font-family="Inter, sans-serif">B</text>
|
||||||
|
<g transform="translate(-148 12)">
|
||||||
|
<rect width="132" height="32" rx="6" fill="#132b40" stroke="#00C3CD" stroke-opacity="0.5" />
|
||||||
|
<text x="8" y="12" fill="#94A3B8" font-size="6.5" font-family="Inter, sans-serif" letter-spacing="0.8">DESTINATION</text>
|
||||||
|
<text x="8" y="24" fill="#FFFFFF" font-size="9" font-weight="600" font-family="Inter, sans-serif">{{ bundle.destination.name }}</text>
|
||||||
|
</g>
|
||||||
|
</g>
|
||||||
|
|
||||||
|
<!-- Compass + solar cue. -->
|
||||||
|
<g transform="translate(38 40)">
|
||||||
|
<circle r="17" fill="#081723" fill-opacity="0.7" stroke="#1e3a52" />
|
||||||
|
<text x="0" y="-21" text-anchor="middle" fill="#94A3B8" font-size="7" font-family="Inter, sans-serif">N</text>
|
||||||
|
<path d="M0 -12 L4 4 L0 1 L-4 4 Z" fill="#00C3CD" />
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
|
||||||
|
<!-- Canvas controls. -->
|
||||||
|
<div class="absolute right-3 top-3 z-10 flex flex-col gap-1 rounded-lg border border-[#1e3a52] bg-[#0e2233]/90 p-1 backdrop-blur">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="flex h-7 w-7 items-center justify-center rounded text-[#94A3B8] transition-colors hover:bg-[#132b40] hover:text-white"
|
||||||
|
aria-label="Zoom in"
|
||||||
|
@click="zoomBy(0.3)"
|
||||||
|
>
|
||||||
|
<Icon name="material-symbols:add" class="text-[17px]" />
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="flex h-7 w-7 items-center justify-center rounded text-[#94A3B8] transition-colors hover:bg-[#132b40] hover:text-white"
|
||||||
|
aria-label="Zoom out"
|
||||||
|
@click="zoomBy(-0.3)"
|
||||||
|
>
|
||||||
|
<Icon name="material-symbols:remove" class="text-[17px]" />
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="flex h-7 w-7 items-center justify-center rounded text-[#00C3CD] transition-colors hover:bg-[#132b40]"
|
||||||
|
aria-label="Reset map view"
|
||||||
|
title="Recenter view"
|
||||||
|
@click="resetZoom"
|
||||||
|
>
|
||||||
|
<Icon name="material-symbols:my-location" class="text-[17px]" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="pointer-events-none absolute bottom-3 left-3 z-10 rounded-md border border-[#1e3a52] bg-[#0e2233]/90 px-2 py-1 text-[9px] font-medium text-[#94A3B8] backdrop-blur">
|
||||||
|
Schematic projection · real OSM footprints · not for navigation
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<figcaption class="flex flex-wrap items-center justify-between gap-3 pt-1 text-[11px] text-[#94A3B8]">
|
||||||
|
<div class="flex flex-wrap items-center gap-4">
|
||||||
|
<span class="flex items-center gap-1.5">
|
||||||
|
<span class="h-1.5 w-3.5 rounded-full bg-[#00C3CD]" />
|
||||||
|
<span class="font-medium text-white">Active recommendation</span>
|
||||||
|
</span>
|
||||||
|
<span class="flex items-center gap-1.5">
|
||||||
|
<span class="h-2.5 w-2.5 rounded-sm border border-[#64748B] bg-[#475569]/40" />
|
||||||
|
<span>Alternative route</span>
|
||||||
|
</span>
|
||||||
|
<span class="flex items-center gap-1.5">
|
||||||
|
<span class="h-2.5 w-2.5 rounded-full border border-[#00C3CD] bg-[#00C3CD]/20" />
|
||||||
|
<span>Drinking water</span>
|
||||||
|
</span>
|
||||||
|
<span class="flex items-center gap-1.5">
|
||||||
|
<span class="h-2.5 w-2.5 rounded-sm bg-[#94A3B8]" />
|
||||||
|
<span>Mapped bench</span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<span class="font-mono text-[#64748B]">EPSG:4326 · modeled, not measured</span>
|
||||||
|
</figcaption>
|
||||||
|
</figure>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,387 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { COOL_TIMES } from '#shared/cool'
|
||||||
|
import type { CoolRouteBundle, CoolRouteId, CoolTime } from '#shared/cool'
|
||||||
|
import type { Sensor } from '#shared/types'
|
||||||
|
import DecisionMetric from '~/components/use-cases/DecisionMetric.vue'
|
||||||
|
import MiniBar from '~/components/use-cases/MiniBar.vue'
|
||||||
|
import RouteMatrixMap from '~/components/use-cases/RouteMatrixMap.vue'
|
||||||
|
import {
|
||||||
|
buildGpx,
|
||||||
|
compassDirection,
|
||||||
|
formatMinutes,
|
||||||
|
formatPercent,
|
||||||
|
recommendedRoute,
|
||||||
|
recommendedValues,
|
||||||
|
routeComparison,
|
||||||
|
routeRationale,
|
||||||
|
solarPosition,
|
||||||
|
} from '#shared/use-cases'
|
||||||
|
|
||||||
|
interface BuildingPolygon {
|
||||||
|
name: string | null
|
||||||
|
kind: string
|
||||||
|
points: Array<[number, number]>
|
||||||
|
}
|
||||||
|
|
||||||
|
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 props = defineProps<{
|
||||||
|
bundle: CoolRouteBundle
|
||||||
|
buildings: BuildingPolygon[] | null
|
||||||
|
places: PlacesBundle | null
|
||||||
|
sensors: Sensor[] | null
|
||||||
|
time: CoolTime
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{ 'update:time': [value: CoolTime] }>()
|
||||||
|
|
||||||
|
const methodOpen = ref(false)
|
||||||
|
const exportNote = ref('')
|
||||||
|
const routeId = computed<CoolRouteId>(() => recommendedRoute(props.bundle, props.time)?.id ?? 'shortest')
|
||||||
|
const route = computed(() => recommendedRoute(props.bundle, props.time))
|
||||||
|
const values = computed(() => recommendedValues(props.bundle, props.time))
|
||||||
|
const comparison = computed(() => routeComparison(props.bundle, props.time))
|
||||||
|
const fastest = computed(() =>
|
||||||
|
comparison.value.slice().sort((a, b) => a.values.durationMin - b.values.durationMin)[0],
|
||||||
|
)
|
||||||
|
const deltaVsFastest = computed(() => {
|
||||||
|
if (!values.value || !fastest.value) return 0
|
||||||
|
return Math.round((values.value.durationMin - fastest.value.values.durationMin) * 10) / 10
|
||||||
|
})
|
||||||
|
const solar = computed(() => solarPosition(props.bundle, props.time))
|
||||||
|
const sensor = computed(
|
||||||
|
() => props.sensors?.find((entry) => entry.name === 'Marktplatz') ?? props.sensors?.[0] ?? null,
|
||||||
|
)
|
||||||
|
const rationale = computed(() => routeRationale(props.bundle, props.time))
|
||||||
|
const hotDay = computed(() => props.bundle.hotDay)
|
||||||
|
const shadeLabel = computed(() => props.bundle.shadeLabel || 'modeled shade, not measured')
|
||||||
|
const activeRouteName = computed(() => route.value?.longName ?? route.value?.label ?? 'Route')
|
||||||
|
const routeDescription = computed(() => route.value?.description ?? '')
|
||||||
|
|
||||||
|
function selectTime(value: CoolTime) {
|
||||||
|
emit('update:time', value)
|
||||||
|
}
|
||||||
|
|
||||||
|
function exportGpx() {
|
||||||
|
try {
|
||||||
|
const xml = buildGpx(props.bundle, routeId.value, props.time)
|
||||||
|
const blob = new Blob([xml], { type: 'application/gpx+xml' })
|
||||||
|
const url = URL.createObjectURL(blob)
|
||||||
|
const anchor = document.createElement('a')
|
||||||
|
anchor.href = url
|
||||||
|
anchor.download = `sensing-engine-${routeId.value}-${props.time.replace(':', '')}.gpx`
|
||||||
|
anchor.click()
|
||||||
|
URL.revokeObjectURL(url)
|
||||||
|
exportNote.value = 'GPX exported with the real OSM geometry.'
|
||||||
|
} catch {
|
||||||
|
exportNote.value = 'The route geometry is unavailable; no file was created.'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="grid grid-cols-1 items-start gap-6 lg:grid-cols-12">
|
||||||
|
<!-- LEFT: decision story -->
|
||||||
|
<div class="flex flex-col gap-6 lg:col-span-5">
|
||||||
|
<section class="relative flex flex-col gap-5 overflow-hidden rounded-xl border border-[#1e3a52] bg-[#0e2233] p-6 shadow-sm">
|
||||||
|
<div class="flex flex-col gap-1">
|
||||||
|
<span class="text-[11px] font-semibold uppercase tracking-widest text-[#00C3CD]">Optimization query</span>
|
||||||
|
<h2 class="text-lg font-bold leading-snug tracking-tight text-white md:text-xl">
|
||||||
|
Fastest way from A to B on a hot day, with modeled shade and step-free access.
|
||||||
|
</h2>
|
||||||
|
<div class="mt-2 flex flex-wrap items-center gap-1.5" role="group" aria-label="Modeled hour">
|
||||||
|
<span class="mr-1 text-[11px] text-[#94A3B8]">Modeled at</span>
|
||||||
|
<button
|
||||||
|
v-for="slot in COOL_TIMES"
|
||||||
|
:key="slot"
|
||||||
|
type="button"
|
||||||
|
class="rounded-md border px-2.5 py-1 text-[11px] font-semibold transition-colors"
|
||||||
|
:class="
|
||||||
|
time === slot
|
||||||
|
? 'border-[#00C3CD]/50 bg-[#00C3CD]/15 text-[#00C3CD]'
|
||||||
|
: 'border-[#1e3a52] bg-[#081723] text-[#94A3B8] hover:text-white'
|
||||||
|
"
|
||||||
|
:aria-pressed="time === slot"
|
||||||
|
@click="selectTime(slot)"
|
||||||
|
>
|
||||||
|
{{ slot }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="relative flex flex-col gap-3 rounded-xl border border-[#00C3CD]/30 bg-[#132b40] p-5 shadow-inner">
|
||||||
|
<div class="flex items-center justify-between gap-2">
|
||||||
|
<span class="text-[11px] font-bold uppercase tracking-wider text-[#00C3CD]">Optimal vector</span>
|
||||||
|
<span class="rounded border border-[#00C3CD]/40 bg-[#00C3CD]/15 px-2 py-0.5 font-mono text-[11px] font-bold text-[#00C3CD]">
|
||||||
|
MODEL ROUTE · {{ time }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="flex flex-col">
|
||||||
|
<span class="text-2xl font-extrabold tracking-tight text-white md:text-3xl">{{ activeRouteName }}</span>
|
||||||
|
<span class="mt-0.5 text-base font-semibold text-[#00C3CD]">
|
||||||
|
{{ values ? `${formatMinutes(values.durationMin)} total duration` : 'Waiting for route values' }}
|
||||||
|
</span>
|
||||||
|
<span v-if="routeDescription" class="mt-1 text-[11px] leading-snug text-[#94A3B8]">{{ routeDescription }}</span>
|
||||||
|
</div>
|
||||||
|
<div class="grid grid-cols-3 gap-2.5 pt-2">
|
||||||
|
<DecisionMetric
|
||||||
|
label="Delta"
|
||||||
|
:value="deltaVsFastest > 0 ? `+${deltaVsFastest} min` : 'Fastest'"
|
||||||
|
:hint="deltaVsFastest > 0 ? 'vs fastest' : 'no penalty'"
|
||||||
|
:tone="deltaVsFastest > 0 ? 'default' : 'accent'"
|
||||||
|
/>
|
||||||
|
<DecisionMetric
|
||||||
|
label="Shade"
|
||||||
|
:value="values ? formatPercent(values.shadePct) : '—'"
|
||||||
|
hint="modeled cover"
|
||||||
|
tone="accent"
|
||||||
|
/>
|
||||||
|
<DecisionMetric
|
||||||
|
label="Direct sun"
|
||||||
|
:value="values ? formatMinutes(values.directSunMin) : '—'"
|
||||||
|
hint="modeled"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div class="grid grid-cols-3 gap-2.5">
|
||||||
|
<div class="flex flex-col">
|
||||||
|
<span class="text-[10px] text-[#64748B]">Step-free</span>
|
||||||
|
<span class="text-[12px] font-semibold text-white">{{ values?.stepFree ? 'Yes' : 'No' }}</span>
|
||||||
|
</div>
|
||||||
|
<div class="flex flex-col">
|
||||||
|
<span class="text-[10px] text-[#64748B]">Water</span>
|
||||||
|
<span class="text-[12px] font-semibold text-white">{{ values?.waterStops ?? '—' }} stops</span>
|
||||||
|
</div>
|
||||||
|
<div class="flex flex-col">
|
||||||
|
<span class="text-[10px] text-[#64748B]">Benches</span>
|
||||||
|
<span class="text-[12px] font-semibold text-white">{{ values?.benchStops ?? '—' }} stops</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-col gap-1.5">
|
||||||
|
<span class="text-[11px] font-bold uppercase tracking-wider text-[#94A3B8]">Fused rationale</span>
|
||||||
|
<p class="text-sm leading-relaxed text-[#94A3B8]">
|
||||||
|
{{ rationale }}
|
||||||
|
</p>
|
||||||
|
<p class="text-[10px] leading-relaxed text-[#64748B]">
|
||||||
|
{{ shadeLabel }}. Estimated devices, not people. The recommendation is deterministic, not a confidence score.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-col gap-2.5 pt-1">
|
||||||
|
<span class="text-[11px] font-bold uppercase tracking-wider text-[#94A3B8]">Sensor context · historical baseline</span>
|
||||||
|
<div class="flex items-center justify-between gap-3 rounded-lg border border-white/10 bg-[#132b40] p-3">
|
||||||
|
<div class="flex items-center gap-3">
|
||||||
|
<Icon name="material-symbols:wb-sunny" class="text-[20px] text-[#94A3B8]" />
|
||||||
|
<div class="flex flex-col">
|
||||||
|
<span class="text-[13px] font-semibold text-white">Solar exposure index</span>
|
||||||
|
<span class="text-[11px] text-[#94A3B8]">
|
||||||
|
{{ solar ? `Azimuth ${Math.round(solar.azimuth_deg)}° ${compassDirection(solar.azimuth_deg)}` : 'solar position unavailable' }}
|
||||||
|
<template v-if="hotDay"> · ambient {{ hotDay.temperature_max_c }}°C</template>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<span class="rounded border border-white/20 bg-white/10 px-2 py-0.5 text-[11px] font-semibold text-white">
|
||||||
|
{{ hotDay && hotDay.temperature_max_c >= 30 ? 'High load' : 'Modeled' }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="flex items-center justify-between gap-3 rounded-lg border border-white/10 bg-[#132b40] p-3">
|
||||||
|
<div class="flex items-center gap-3">
|
||||||
|
<Icon name="material-symbols:groups" class="text-[20px] text-[#00C3CD]" />
|
||||||
|
<div class="flex flex-col">
|
||||||
|
<span class="text-[13px] font-semibold text-white">Pedestrian flux density</span>
|
||||||
|
<span class="text-[11px] text-[#94A3B8]">
|
||||||
|
<template v-if="sensor">{{ sensor.name }} · p95 {{ sensor.p95 }} est. devices/h</template>
|
||||||
|
<template v-else>Waiting for sensor data</template>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<span class="rounded border border-[#00C3CD]/30 bg-[#00C3CD]/15 px-2 py-0.5 text-[11px] font-semibold text-[#00C3CD]">
|
||||||
|
{{ sensor ? `mean ${sensor.mean}` : '—' }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="flex items-center justify-between gap-3 rounded-lg border border-white/10 bg-[#132b40] p-3">
|
||||||
|
<div class="flex items-center gap-3">
|
||||||
|
<Icon name="material-symbols:sensors" class="text-[20px] text-[#00C3CD]" />
|
||||||
|
<div class="flex flex-col">
|
||||||
|
<span class="text-[13px] font-semibold text-white">Microclimate sensor node</span>
|
||||||
|
<span class="text-[11px] text-[#94A3B8]">
|
||||||
|
<template v-if="sensor">{{ sensor.id }}</template>
|
||||||
|
<template v-else>Sensor cluster offline</template>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<span class="font-mono text-[11px] font-semibold text-[#00C3CD]">
|
||||||
|
{{ sensor?.battery != null ? `${sensor.battery}% battery` : 'no battery data' }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-col gap-2 pt-1">
|
||||||
|
<div class="flex items-center gap-3">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="flex h-10 flex-1 items-center justify-center gap-2 rounded-lg bg-[#00C3CD] px-4 text-[13px] font-semibold text-[#081723] shadow-[0_0_16px_rgba(0,195,205,0.3)] transition-all hover:bg-[#00d8e4]"
|
||||||
|
@click="exportGpx"
|
||||||
|
>
|
||||||
|
<Icon name="material-symbols:download" class="text-[18px]" />
|
||||||
|
Export route GPX
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="flex h-10 items-center justify-center gap-1.5 rounded-lg border border-[#1e3a52] bg-[#132b40] px-4 text-[13px] font-semibold text-[#94A3B8] transition-all hover:bg-[#18364e] hover:text-white"
|
||||||
|
:aria-expanded="methodOpen"
|
||||||
|
@click="methodOpen = !methodOpen"
|
||||||
|
>
|
||||||
|
<Icon name="material-symbols:query-stats" class="text-[18px]" />
|
||||||
|
Inspect method
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<p v-if="exportNote" class="text-[10px] text-[#94A3B8]" role="status">{{ exportNote }}</p>
|
||||||
|
<div v-if="methodOpen" class="flex flex-col gap-2 rounded-lg border border-[#1e3a52] bg-[#081723] p-3 text-[11px] leading-relaxed text-[#94A3B8]">
|
||||||
|
<p><strong class="text-white">Method.</strong> {{ bundle.meta?.method ?? 'Route/shade method unavailable.' }}</p>
|
||||||
|
<p><strong class="text-white">Walking speed.</strong> {{ bundle.meta?.walkingSpeedMps ?? '—' }} m/s. {{ shadeLabel }}.</p>
|
||||||
|
<ul class="list-disc space-y-1 pl-4">
|
||||||
|
<li v-for="gap in bundle.meta?.dataGaps ?? []" :key="gap">{{ gap }}</li>
|
||||||
|
</ul>
|
||||||
|
<p class="text-[#64748B]">
|
||||||
|
Source bundle: {{ bundle.generatedAt || 'generated date unavailable' }} · 3 routes × 4 modeled hours · 35 OSM segments.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- RIGHT: visual data story -->
|
||||||
|
<div class="flex flex-col gap-6 lg:col-span-7">
|
||||||
|
<section class="flex flex-col gap-4 rounded-xl border border-[#1e3a52] bg-[#0e2233] p-5 shadow-sm md:p-6">
|
||||||
|
<div class="flex flex-wrap items-center justify-between gap-2">
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<Icon name="material-symbols:layers" class="text-[20px] text-[#00C3CD]" />
|
||||||
|
<span class="text-base font-bold text-white">Micro-spatial routing matrix</span>
|
||||||
|
</div>
|
||||||
|
<div class="flex flex-wrap items-center gap-2">
|
||||||
|
<span v-if="solar" class="text-[12px] text-[#94A3B8]">
|
||||||
|
Solar vector: {{ Math.round(solar.azimuth_deg) }}° {{ compassDirection(solar.azimuth_deg) }}
|
||||||
|
</span>
|
||||||
|
<span class="h-1.5 w-1.5 rounded-full bg-[#00C3CD]" aria-hidden="true" />
|
||||||
|
<span class="text-[12px] font-semibold text-[#00C3CD]">Modeled canvas · {{ time }}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<RouteMatrixMap
|
||||||
|
:bundle="bundle"
|
||||||
|
:buildings="buildings"
|
||||||
|
:places="places"
|
||||||
|
:selected-route-id="routeId"
|
||||||
|
:time="time"
|
||||||
|
/>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="flex flex-col gap-4 rounded-xl border border-[#1e3a52] bg-[#0e2233] p-5 shadow-sm md:p-6">
|
||||||
|
<div class="flex flex-wrap items-center justify-between gap-2">
|
||||||
|
<div class="flex flex-col">
|
||||||
|
<span class="text-[11px] font-semibold uppercase tracking-widest text-[#00C3CD]">Algorithmic trade-off analysis</span>
|
||||||
|
<h3 class="mt-0.5 text-base font-bold text-white">Candidate paths comparison</h3>
|
||||||
|
</div>
|
||||||
|
<span class="rounded border border-[#1e3a52] bg-[#132b40] px-2.5 py-1 font-mono text-[11px] text-[#94A3B8]">
|
||||||
|
{{ comparison.length }} alternatives evaluated
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-col gap-3">
|
||||||
|
<article
|
||||||
|
v-for="row in comparison"
|
||||||
|
:key="row.id"
|
||||||
|
class="relative flex flex-col gap-2 overflow-hidden rounded-xl border p-4 transition-all"
|
||||||
|
:class="
|
||||||
|
row.recommended
|
||||||
|
? 'border-[#00C3CD]/60 bg-[#132b40] shadow-[0_0_20px_rgba(0,195,205,0.08)]'
|
||||||
|
: 'border-[#1e3a52] bg-[#132b40] hover:border-[#64748B]/60'
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<div v-if="row.recommended" class="absolute inset-y-0 left-0 w-1.5 bg-[#00C3CD]" aria-hidden="true" />
|
||||||
|
<div class="flex flex-col justify-between gap-1 sm:flex-row sm:items-center" :class="row.recommended ? 'pl-1.5' : ''">
|
||||||
|
<div class="flex flex-wrap items-center gap-2">
|
||||||
|
<Icon
|
||||||
|
v-if="row.recommended"
|
||||||
|
name="material-symbols:verified"
|
||||||
|
class="text-[18px] text-[#00C3CD]"
|
||||||
|
/>
|
||||||
|
<span class="text-[13px]" :class="row.recommended ? 'font-bold text-white' : 'font-semibold text-white'">
|
||||||
|
{{ row.title }}
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
v-if="row.recommended"
|
||||||
|
class="rounded bg-[#00C3CD] px-2 py-0.5 text-[10px] font-bold tracking-wide text-[#081723]"
|
||||||
|
>
|
||||||
|
RECOMMENDED
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
class="rounded border px-2 py-0.5 text-[10px] font-semibold"
|
||||||
|
:class="
|
||||||
|
row.recommended
|
||||||
|
? 'border-[#00C3CD]/30 bg-[#00C3CD]/15 text-[#00C3CD]'
|
||||||
|
: 'border-[#1e3a52] bg-white/10 text-[#94A3B8]'
|
||||||
|
"
|
||||||
|
>
|
||||||
|
{{ row.tag }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="flex items-center gap-2" :class="row.recommended ? 'pl-6 sm:pl-0' : ''">
|
||||||
|
<span class="font-mono font-extrabold text-[#00C3CD]" :class="row.recommended ? 'text-xl' : 'text-base text-white'">
|
||||||
|
{{ formatMinutes(row.values.durationMin) }}
|
||||||
|
</span>
|
||||||
|
<span class="text-[11px] font-mono text-[#94A3B8]">
|
||||||
|
{{ row.penaltyMin > 0 ? `(+${row.penaltyMin} min penalty)` : '(fastest)' }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="grid grid-cols-1 gap-3 pt-1 md:grid-cols-2" :class="row.recommended ? 'pl-1.5' : ''">
|
||||||
|
<div class="flex flex-col gap-1">
|
||||||
|
<div class="flex justify-between text-[11px]">
|
||||||
|
<span class="flex items-center gap-1 text-[#94A3B8]">
|
||||||
|
<Icon
|
||||||
|
:name="row.recommended ? 'material-symbols:park' : 'material-symbols:wb-sunny'"
|
||||||
|
class="text-[13px]"
|
||||||
|
:class="row.recommended ? 'text-[#00C3CD]' : 'text-[#64748B]'"
|
||||||
|
/>
|
||||||
|
Shade coverage
|
||||||
|
</span>
|
||||||
|
<span class="font-mono font-bold" :class="row.recommended ? 'text-[#00C3CD]' : 'text-white'">
|
||||||
|
{{ formatPercent(row.values.shadePct) }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<MiniBar :value="row.values.shadePct" :tone="row.recommended ? 'accent' : 'muted'" :label="`${row.title} shade coverage`" />
|
||||||
|
</div>
|
||||||
|
<div class="flex flex-col gap-1">
|
||||||
|
<div class="flex justify-between text-[11px]">
|
||||||
|
<span class="flex items-center gap-1 text-[#94A3B8]">
|
||||||
|
<Icon name="material-symbols:sunny" class="text-[13px] text-[#64748B]" />
|
||||||
|
Direct sun
|
||||||
|
</span>
|
||||||
|
<span class="font-mono font-semibold text-white">{{ formatMinutes(row.values.directSunMin) }}</span>
|
||||||
|
</div>
|
||||||
|
<MiniBar :value="Math.min(100, (row.values.directSunMin / 6) * 100)" :tone="row.recommended ? 'subtle' : 'subtle'" :label="`${row.title} direct sun`" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p class="text-[11px] leading-snug text-[#64748B]" :class="row.recommended ? 'pl-1.5' : ''">
|
||||||
|
{{ row.values.distanceM }} m · {{ row.description }}
|
||||||
|
</p>
|
||||||
|
</article>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,428 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { berlinParts, parseHour } from '#shared/staffing'
|
||||||
|
import type { ContextResponse, Sensor, StaffingHour, StaffingResponse } from '#shared/types'
|
||||||
|
import { sensorForPlan, staffingSnapshot } from '#shared/use-cases'
|
||||||
|
import DecisionMetric from '~/components/use-cases/DecisionMetric.vue'
|
||||||
|
import MiniBar from '~/components/use-cases/MiniBar.vue'
|
||||||
|
import { formatEuro, formatNumber, formatPercent, formatShortDate, formatWeekday } from '~/utils/format'
|
||||||
|
import { planDays } from '~/utils/plan'
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
plan: StaffingResponse | null
|
||||||
|
sensors: Sensor[] | null
|
||||||
|
context: ContextResponse | null
|
||||||
|
sensorId: string
|
||||||
|
pending: boolean
|
||||||
|
error: string
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
'update:sensor-id': [value: string]
|
||||||
|
refresh: []
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const assumptionsOpen = ref(false)
|
||||||
|
const exportNote = ref('')
|
||||||
|
const snapshot = computed(() => staffingSnapshot(props.plan))
|
||||||
|
const days = computed(() => planDays(props.plan))
|
||||||
|
const peakDate = computed(() => snapshot.value.peakShift?.date ?? '')
|
||||||
|
const peakDay = computed(() => days.value.find((day) => day.date === peakDate.value) ?? null)
|
||||||
|
const peakShift = computed(() => snapshot.value.peakShift)
|
||||||
|
const peakShiftLabel = computed(() =>
|
||||||
|
peakShift.value ? `${formatWeekday(peakShift.value.date)} · ${formatShortDate(peakShift.value.date)}` : '',
|
||||||
|
)
|
||||||
|
const selectedSensor = computed(() => props.sensors?.find((sensor) => sensor.id === props.sensorId) ?? null)
|
||||||
|
const planSensor = computed(() => sensorForPlan(props.sensors, props.plan))
|
||||||
|
const weather = computed(() => props.context?.weather.now ?? null)
|
||||||
|
const telemetryRows = computed(() => {
|
||||||
|
const sensor = selectedSensor.value
|
||||||
|
const now = weather.value
|
||||||
|
const plan = props.plan
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
title: 'Pedestrian flux density',
|
||||||
|
detail: sensor
|
||||||
|
? `${sensor.name} · mean ${sensor.mean} · p95 ${sensor.p95} est. devices/h`
|
||||||
|
: 'Selected sensor data unavailable.',
|
||||||
|
badge: sensor?.battery != null ? `${sensor.battery}% battery` : 'no battery data',
|
||||||
|
icon: 'material-symbols:sensors',
|
||||||
|
iconClass: 'text-[#00C3CD]',
|
||||||
|
badgeClass: 'border-[#00C3CD]/30 bg-[#00C3CD]/15 text-[#00C3CD]',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Context weather now',
|
||||||
|
detail: now ? `${now.temp_c} °C · ${now.precip_mm} mm · ${now.cloud_pct}% cloud` : 'Weather now unavailable.',
|
||||||
|
badge: now ? 'Now' : '—',
|
||||||
|
icon: 'material-symbols:cloud',
|
||||||
|
iconClass: 'text-[#94A3B8]',
|
||||||
|
badgeClass: 'border-[#1e3a52] bg-white/10 text-[#94A3B8]',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Plan provenance',
|
||||||
|
detail: plan
|
||||||
|
? `data ${plan.data_version || '—'} · model ${plan.model_version || '—'} · context ${plan.context_version || '—'}`
|
||||||
|
: 'Waiting for a plan response.',
|
||||||
|
badge: plan ? (plan.cached ? 'Cached' : 'Not cached') : '—',
|
||||||
|
icon: 'material-symbols:database',
|
||||||
|
iconClass: 'text-[#94A3B8]',
|
||||||
|
badgeClass: 'border-[#1e3a52] bg-white/10 text-[#94A3B8]',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
|
const hourColumns = computed(() => {
|
||||||
|
const open = parseHour(props.plan?.assumptions.store_hours.open ?? '10:00')
|
||||||
|
const close = parseHour(props.plan?.assumptions.store_hours.close ?? '20:00')
|
||||||
|
return Array.from({ length: Math.max(0, close - open) }, (_, index) => open + index)
|
||||||
|
})
|
||||||
|
const hourRange = computed(() => {
|
||||||
|
const first = hourColumns.value[0]
|
||||||
|
const last = hourColumns.value.at(-1)
|
||||||
|
return first === undefined || last === undefined ? '—' : `${first}:00–${last + 1}:00`
|
||||||
|
})
|
||||||
|
|
||||||
|
const matrixRows = computed(() =>
|
||||||
|
days.value.map((day) => {
|
||||||
|
const byHour = new Map(day.hours.map((hour) => [berlinParts(hour.t).hour, hour] as const))
|
||||||
|
const peak = Math.max(0, ...day.hours.map((hour) => hour.required_staff))
|
||||||
|
return {
|
||||||
|
...day,
|
||||||
|
isPeak: day.date === peakDate.value,
|
||||||
|
cells: hourColumns.value.map((hour) => {
|
||||||
|
const entry = byHour.get(hour)
|
||||||
|
return {
|
||||||
|
hour,
|
||||||
|
required: entry?.required_staff ?? 0,
|
||||||
|
scheduled: entry?.scheduled_staff ?? 0,
|
||||||
|
intensity: entry && peak > 0 ? entry.required_staff / peak : 0,
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
|
const maxStaffHours = computed(() => Math.max(0, ...days.value.map((day) => day.staffHours)))
|
||||||
|
const assumptionRows = computed<Array<{ label: string; value: string; sub?: string }>>(() => {
|
||||||
|
const a = props.plan?.assumptions
|
||||||
|
if (!a) return []
|
||||||
|
return [
|
||||||
|
{ label: 'Visitors / staff-hour', value: String(a.visitors_per_staff_hour) },
|
||||||
|
{ label: 'Safety factor', value: `×${a.safety_factor}` },
|
||||||
|
{ label: 'Minimum staff', value: String(a.min_staff) },
|
||||||
|
{ label: 'Shift block', value: `${a.shift_length_h} h` },
|
||||||
|
{ label: 'Labour cost', value: `${formatEuro(a.labor_cost_eur_h)}/h` },
|
||||||
|
{ label: 'Store hours', value: `${a.store_hours.open}–${a.store_hours.close}`, sub: a.store_hours.tz },
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
|
function cellStyle(intensity: number) {
|
||||||
|
return { backgroundColor: `rgba(0, 195, 205, ${(0.07 + Math.max(0, Math.min(1, intensity)) * 0.33).toFixed(3)})` }
|
||||||
|
}
|
||||||
|
|
||||||
|
function cellLabel(
|
||||||
|
day: { weekdayLong: string; dayNumber: string; month: string },
|
||||||
|
cell: { hour: number; required: number; scheduled: number },
|
||||||
|
) {
|
||||||
|
const prefix = `${day.weekdayLong} ${day.dayNumber} ${day.month} at ${cell.hour}:00`
|
||||||
|
return cell.required ? `${prefix}: ${cell.scheduled} scheduled, ${cell.required} required.` : `${prefix}: no plan hour.`
|
||||||
|
}
|
||||||
|
|
||||||
|
function selectSensor(event: Event) {
|
||||||
|
const value = (event.target as HTMLSelectElement).value
|
||||||
|
if (value) emit('update:sensor-id', value)
|
||||||
|
}
|
||||||
|
|
||||||
|
function csvCell(value: unknown) {
|
||||||
|
const text = value == null ? '' : String(value)
|
||||||
|
return /[",\n]/.test(text) ? `"${text.replaceAll('"', '""')}"` : text
|
||||||
|
}
|
||||||
|
|
||||||
|
function exportCsv() {
|
||||||
|
if (!import.meta.client || !props.plan) return
|
||||||
|
try {
|
||||||
|
const plan = props.plan
|
||||||
|
const rows: Array<Array<string | number>> = [
|
||||||
|
['Sensing Engine staffing plan'],
|
||||||
|
['sensor', plan.sensor, 'scenario', plan.scenario, 'standard', plan.standard],
|
||||||
|
['cached', plan.cached ? 'true' : 'false', 'data_version', plan.data_version, 'model_version', plan.model_version],
|
||||||
|
[],
|
||||||
|
['shift blocks'],
|
||||||
|
['date', 'start', 'end', 'staff'],
|
||||||
|
...plan.shifts.map((shift) => [shift.date, shift.start, shift.end, shift.staff]),
|
||||||
|
[],
|
||||||
|
['hourly plan'],
|
||||||
|
['date', 'hour', 'footfall_est_devices', 'required_staff', 'scheduled_staff', 'coverage'],
|
||||||
|
...plan.hours.map((hour) => {
|
||||||
|
const parts = berlinParts(hour.t)
|
||||||
|
return [parts.date, `${String(parts.hour).padStart(2, '0')}:00`, hour.footfall, hour.required_staff, hour.scheduled_staff, hour.coverage]
|
||||||
|
}),
|
||||||
|
]
|
||||||
|
const csv = rows.map((row) => row.map(csvCell).join(',')).join('\n')
|
||||||
|
const blob = new Blob([`\uFEFF${csv}`], { type: 'text/csv;charset=utf-8' })
|
||||||
|
const url = URL.createObjectURL(blob)
|
||||||
|
const anchor = document.createElement('a')
|
||||||
|
anchor.href = url
|
||||||
|
anchor.download = `sensing-engine-staffing-${plan.sensor || 'plan'}-${plan.scenario}.csv`
|
||||||
|
anchor.click()
|
||||||
|
anchor.remove()
|
||||||
|
URL.revokeObjectURL(url)
|
||||||
|
exportNote.value = `Exported ${plan.shifts.length} shift blocks and ${plan.hours.length} hourly rows.`
|
||||||
|
} catch {
|
||||||
|
exportNote.value = 'The browser blocked the download; no file was created.'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="grid grid-cols-1 items-start gap-6 lg:grid-cols-12">
|
||||||
|
<div v-if="error" class="flex flex-col gap-3 rounded-xl border border-[#00C3CD]/40 bg-[#132b40] p-4 sm:flex-row sm:items-center sm:justify-between lg:col-span-12" role="alert">
|
||||||
|
<div class="flex min-w-0 items-start gap-3">
|
||||||
|
<Icon name="material-symbols:info" class="mt-0.5 shrink-0 text-[20px] text-[#00C3CD]" />
|
||||||
|
<div class="flex min-w-0 flex-col gap-0.5">
|
||||||
|
<span class="font-semibold text-white">{{ plan ? 'Plan refresh failed' : 'Live plan unavailable' }}</span>
|
||||||
|
<span class="text-[12px] leading-relaxed text-[#94A3B8]">{{ error }} {{ plan ? 'The last known response stays visible.' : 'Nothing is estimated or filled in.' }}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<button type="button" class="flex h-10 shrink-0 items-center justify-center gap-2 rounded-lg border border-[#00C3CD]/40 bg-[#00C3CD]/10 px-4 text-[12px] font-semibold text-[#00C3CD] transition-colors hover:bg-[#00C3CD]/20" @click="emit('refresh')">
|
||||||
|
<Icon name="material-symbols:refresh" class="text-[18px]" /> Retry
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex min-w-0 flex-col gap-6 lg:col-span-5">
|
||||||
|
<section class="relative flex flex-col gap-5 overflow-hidden rounded-xl border border-[#1e3a52] bg-[#0e2233] p-6 shadow-sm">
|
||||||
|
<div class="flex flex-col gap-1">
|
||||||
|
<span class="text-[11px] font-semibold uppercase tracking-widest text-[#00C3CD]">Optimization query</span>
|
||||||
|
<h2 class="text-lg font-bold leading-snug tracking-tight text-white md:text-xl">How many staff for the next peak?</h2>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-col gap-1.5">
|
||||||
|
<label for="staffing-sensor" class="text-[10px] font-semibold uppercase tracking-wider text-[#64748B]">Store sensor</label>
|
||||||
|
<div class="relative">
|
||||||
|
<select id="staffing-sensor" :value="sensorId" :disabled="!sensors?.length" class="h-10 w-full appearance-none rounded-lg border border-[#1e3a52] bg-[#081723] px-3 pr-9 text-[12px] font-medium text-white outline-none transition-colors focus:border-[#00C3CD]/60 disabled:cursor-not-allowed disabled:opacity-60 [&>option]:bg-[#0e2233] [&>option]:text-white" @change="selectSensor">
|
||||||
|
<option v-for="sensor in sensors ?? []" :key="sensor.id" :value="sensor.id">{{ sensor.name }}</option>
|
||||||
|
<option v-if="!sensors?.length" value="" disabled>Sensor list unavailable</option>
|
||||||
|
</select>
|
||||||
|
<Icon name="material-symbols:expand-more" class="pointer-events-none absolute right-3 top-1/2 -translate-y-1/2 text-[18px] text-[#94A3B8]" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="pending" class="flex items-center gap-2 rounded-lg border border-[#1e3a52] bg-[#132b40] px-3 py-2 text-[11px] text-[#94A3B8]" role="status">
|
||||||
|
<span class="h-1.5 w-1.5 animate-pulse rounded-full bg-[#00C3CD]" aria-hidden="true" />
|
||||||
|
Refreshing the plan for the selected sensor…
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="relative flex flex-col gap-3 rounded-xl border border-[#00C3CD]/30 bg-[#132b40] p-5 shadow-inner">
|
||||||
|
<div class="flex flex-wrap items-center justify-between gap-2">
|
||||||
|
<span class="text-[11px] font-bold uppercase tracking-wider text-[#00C3CD]">Peak shift</span>
|
||||||
|
<span class="rounded border border-[#00C3CD]/40 bg-[#00C3CD]/15 px-2 py-0.5 font-mono text-[10px] font-bold text-[#00C3CD]">BLOCK OUTPUT · {{ plan?.assumptions.shift_length_h ?? '—' }} H</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<template v-if="plan && peakShift">
|
||||||
|
<div class="flex flex-wrap items-end gap-x-2 gap-y-1">
|
||||||
|
<span class="text-3xl font-extrabold tracking-tight text-white">{{ peakShift.staff }}</span>
|
||||||
|
<span class="pb-1 text-sm font-semibold text-[#00C3CD]">staff on the peak shift</span>
|
||||||
|
</div>
|
||||||
|
<div class="flex flex-col">
|
||||||
|
<span class="text-base font-semibold text-white">{{ peakShiftLabel }}</span>
|
||||||
|
<span class="text-[12px] text-[#94A3B8]">{{ peakShift.start }}–{{ peakShift.end }} local</span>
|
||||||
|
</div>
|
||||||
|
<p class="text-[10px] leading-relaxed text-[#64748B]">Plan input: {{ planSensor?.name ?? plan.sensor }} · {{ plan.standard }} standard. Footfall is estimated devices, not people.</p>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<div v-else-if="!plan && pending" class="flex flex-col gap-2.5" aria-busy="true">
|
||||||
|
<div class="h-8 w-32 animate-pulse rounded bg-white/10" />
|
||||||
|
<div class="h-3 w-48 animate-pulse rounded bg-white/10" />
|
||||||
|
<div class="h-3 w-40 animate-pulse rounded bg-white/10" />
|
||||||
|
<p class="text-[10px] text-[#94A3B8]">Loading the live plan. No values are estimated.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p v-else class="text-sm leading-relaxed text-[#94A3B8]">{{ error ? 'No plan response is available, so no staff count or shift window is shown.' : 'The API returned no shift blocks for this plan. No staff count is estimated.' }}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="plan" class="grid grid-cols-2 gap-2.5">
|
||||||
|
<DecisionMetric label="Peak footfall" :value="formatNumber(snapshot.peakFootfall)" hint="est. devices/h" tone="accent" />
|
||||||
|
<DecisionMetric label="Staff hours" :value="formatNumber(snapshot.staffHours)" hint="scheduled" />
|
||||||
|
<DecisionMetric label="Saved vs flat" :value="formatEuro(snapshot.savedEur)" :hint="`${formatPercent(snapshot.savedPct, 1)} vs flat`" tone="accent" />
|
||||||
|
<DecisionMetric label="Coverage" :value="formatPercent(snapshot.coveragePct, 1)" hint="scheduled ≥ required" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p v-if="plan" class="text-[10px] leading-relaxed text-[#64748B]">
|
||||||
|
Coverage = scheduled ≥ required; the block heuristic keeps this at 100% for complete plans. It is not a
|
||||||
|
service-quality or forecast-accuracy score. Footfall is estimated devices, not people.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div v-if="plan" class="flex flex-col gap-1.5">
|
||||||
|
<span class="text-[11px] font-bold uppercase tracking-wider text-[#94A3B8]">Fused rationale</span>
|
||||||
|
<ul v-if="plan.why.length" class="flex flex-col gap-1.5">
|
||||||
|
<li v-for="reason in plan.why.slice(0, 3)" :key="reason" class="flex gap-2 text-[12px] leading-relaxed text-[#94A3B8]">
|
||||||
|
<span class="mt-1.5 h-1 w-1 shrink-0 rounded-full bg-[#00C3CD]" aria-hidden="true" />
|
||||||
|
<span>{{ reason }}</span>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
<p v-else class="text-[12px] leading-relaxed text-[#94A3B8]">No API rationale lines were returned with this plan. The declared rule below still applies.</p>
|
||||||
|
<p class="text-[11px] leading-relaxed text-[#94A3B8]">
|
||||||
|
<strong class="text-white">Rule.</strong> {{ plan.assumptions.visitors_per_staff_hour }} visitors per staff-hour × {{ plan.assumptions.safety_factor }} safety factor, minimum {{ plan.assumptions.min_staff }} staff, {{ plan.assumptions.shift_length_h }} h shift blocks.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-col gap-2.5 pt-1">
|
||||||
|
<span class="text-[11px] font-bold uppercase tracking-wider text-[#94A3B8]">Sensor context · historical baseline</span>
|
||||||
|
<div v-for="row in telemetryRows" :key="row.title" class="flex items-center justify-between gap-3 rounded-lg border border-white/10 bg-[#132b40] p-3">
|
||||||
|
<div class="flex min-w-0 items-center gap-3">
|
||||||
|
<Icon :name="row.icon" class="shrink-0 text-[20px]" :class="row.iconClass" />
|
||||||
|
<div class="flex min-w-0 flex-col">
|
||||||
|
<span class="text-[13px] font-semibold text-white">{{ row.title }}</span>
|
||||||
|
<span class="break-words text-[11px] text-[#94A3B8]">{{ row.detail }}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<span class="shrink-0 rounded border px-2 py-0.5 text-[11px] font-semibold" :class="row.badgeClass">
|
||||||
|
{{ row.badge }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-col gap-2 pt-1">
|
||||||
|
<button type="button" class="flex h-10 items-center justify-center gap-2 rounded-lg bg-[#00C3CD] px-4 text-[13px] font-semibold text-[#081723] shadow-[0_0_16px_rgba(0,195,205,0.3)] transition-all hover:bg-[#00d8e4] disabled:cursor-not-allowed disabled:opacity-60" :disabled="!plan" @click="exportCsv">
|
||||||
|
<Icon name="material-symbols:download" class="text-[18px]" /> Export shift CSV
|
||||||
|
</button>
|
||||||
|
<div class="grid grid-cols-1 gap-2 sm:grid-cols-2">
|
||||||
|
<NuxtLink to="/plan" class="flex h-10 items-center justify-center gap-1.5 rounded-lg border border-[#1e3a52] bg-[#132b40] px-3 text-[13px] font-semibold text-[#94A3B8] transition-all hover:bg-[#18364e] hover:text-white">
|
||||||
|
<Icon name="material-symbols:open-in-new" class="text-[18px]" /> Open full plan
|
||||||
|
</NuxtLink>
|
||||||
|
<button type="button" class="flex h-10 items-center justify-center gap-1.5 rounded-lg border border-[#1e3a52] bg-[#132b40] px-3 text-[13px] font-semibold text-[#94A3B8] transition-all hover:bg-[#18364e] hover:text-white" :aria-expanded="assumptionsOpen" @click="assumptionsOpen = !assumptionsOpen">
|
||||||
|
<Icon name="material-symbols:query-stats" class="text-[18px]" /> Inspect assumptions
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<p v-if="exportNote" class="text-[10px] text-[#94A3B8]" role="status">{{ exportNote }}</p>
|
||||||
|
|
||||||
|
<div v-if="assumptionsOpen && plan" class="flex flex-col gap-2 rounded-lg border border-[#1e3a52] bg-[#081723] p-3">
|
||||||
|
<div class="grid grid-cols-2 gap-x-3 gap-y-2 text-[11px]">
|
||||||
|
<div v-for="row in assumptionRows" :key="row.label" class="flex flex-col">
|
||||||
|
<span class="text-[#64748B]">{{ row.label }}</span>
|
||||||
|
<span class="break-words font-mono font-semibold text-white">{{ row.value }}</span>
|
||||||
|
<span v-if="row.sub" class="break-words text-[9px] text-[#64748B]">{{ row.sub }}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p class="text-[10px] leading-relaxed text-[#64748B]">Coverage = scheduled ≥ required; the block heuristic keeps this at 100% for complete plans. It is a property of the heuristic, not a service-quality claim. No POS, queue or payroll feed is used.</p>
|
||||||
|
</div>
|
||||||
|
<p v-else-if="assumptionsOpen" class="rounded-lg border border-[#1e3a52] bg-[#081723] p-3 text-[10px] text-[#94A3B8]">Assumptions are unavailable until a plan response arrives.</p>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex min-w-0 flex-col gap-6 lg:col-span-7">
|
||||||
|
<section class="flex flex-col gap-4 rounded-xl border border-[#1e3a52] bg-[#0e2233] p-5 shadow-sm md:p-6">
|
||||||
|
<div class="flex flex-wrap items-center justify-between gap-2">
|
||||||
|
<div class="flex min-w-0 items-center gap-2">
|
||||||
|
<Icon name="material-symbols:table-chart" class="shrink-0 text-[20px] text-[#00C3CD]" />
|
||||||
|
<span class="text-base font-bold text-white">Workforce adequacy matrix</span>
|
||||||
|
</div>
|
||||||
|
<div class="flex flex-wrap items-center gap-2">
|
||||||
|
<span v-if="peakDay" class="text-[12px] text-[#94A3B8]">
|
||||||
|
Peak day {{ peakDay.weekdayLong }} {{ peakDay.dayNumber }} {{ peakDay.month }}
|
||||||
|
</span>
|
||||||
|
<span v-if="peakDay" class="h-1.5 w-1.5 rounded-full bg-[#00C3CD]" aria-hidden="true" />
|
||||||
|
<span class="font-mono text-[11px] text-[#00C3CD]">
|
||||||
|
{{ plan ? `${days.length} days · ${hourColumns.length} open hours` : 'No plan loaded' }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<template v-if="matrixRows.length">
|
||||||
|
<div class="overflow-hidden rounded-lg border border-[#1e3a52] bg-[#081723] p-2">
|
||||||
|
<table class="w-full table-fixed border-separate border-spacing-0.5" :aria-label="`Workforce adequacy matrix: ${days.length} local days by ${hourColumns.length} store hours`">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th scope="col" class="w-[2.35rem] pb-1 text-left text-[9px] font-semibold uppercase tracking-wider text-[#64748B]"><span class="sr-only">Day</span></th>
|
||||||
|
<th v-for="hour in hourColumns" :key="hour" scope="col" class="pb-1 text-center text-[9px] font-semibold text-[#64748B]">{{ String(hour).padStart(2, '0') }}</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr v-for="day in matrixRows" :key="day.date">
|
||||||
|
<th scope="row" class="pr-1 align-middle">
|
||||||
|
<span class="block truncate text-[10px] font-bold" :class="day.isPeak ? 'text-[#00C3CD]' : 'text-white'">{{ day.weekday }}</span>
|
||||||
|
<span class="block text-[9px] font-normal text-[#64748B]">{{ day.dayNumber }}</span>
|
||||||
|
</th>
|
||||||
|
<td v-for="cell in day.cells" :key="cell.hour" class="p-0 align-middle" :aria-label="cellLabel(day, cell)">
|
||||||
|
<div class="flex h-7 w-full items-center justify-center rounded-[3px] border border-white/10 sm:h-8" :class="cell.required ? 'text-white' : 'bg-[#0e2233] text-[#64748B]'" :style="cell.required ? cellStyle(cell.intensity) : undefined" aria-hidden="true">
|
||||||
|
<span class="font-mono text-[9px] font-semibold leading-none">{{ cell.required ? cell.scheduled : '–' }}</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-wrap items-center justify-between gap-2 text-[10px] text-[#64748B]">
|
||||||
|
<div class="flex flex-wrap items-center gap-3">
|
||||||
|
<span class="flex items-center gap-1.5"><span class="h-2.5 w-2.5 rounded-[2px] border border-white/10" :style="cellStyle(0.2)" aria-hidden="true" />Lower requirement</span>
|
||||||
|
<span class="flex items-center gap-1.5"><span class="h-2.5 w-2.5 rounded-[2px] border border-white/10" :style="cellStyle(1)" aria-hidden="true" />Day peak</span>
|
||||||
|
<span class="flex items-center gap-1.5"><span class="h-2.5 w-2.5 rounded-[2px] border border-white/10 bg-[#0e2233]" aria-hidden="true" />No hour</span>
|
||||||
|
</div>
|
||||||
|
<span>Number = scheduled staff · local hours {{ hourRange }}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p class="text-[10px] leading-relaxed text-[#64748B]">
|
||||||
|
Intensity = required staff ÷ that day's peak requirement. Coverage = scheduled ≥ required; the block
|
||||||
|
heuristic keeps this at 100% for complete plans. It is a scheduling property, not a quality score.
|
||||||
|
</p>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<div v-else class="rounded-lg border border-dashed border-[#1e3a52] bg-[#132b40] p-4 text-[11px] leading-relaxed text-[#94A3B8]" role="status">
|
||||||
|
{{ pending ? 'Loading the plan days for this sensor…' : 'No plan days are available. The matrix stays empty rather than being estimated.' }}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="flex flex-col gap-4 rounded-xl border border-[#1e3a52] bg-[#0e2233] p-5 shadow-sm md:p-6">
|
||||||
|
<div class="flex flex-wrap items-center justify-between gap-2">
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<Icon name="material-symbols:calendar-month" class="text-[20px] text-[#00C3CD]" />
|
||||||
|
<span class="text-base font-bold text-white">Shift comparison</span>
|
||||||
|
</div>
|
||||||
|
<span class="rounded border border-[#1e3a52] bg-[#132b40] px-2.5 py-1 font-mono text-[11px] text-[#94A3B8]">
|
||||||
|
{{ plan ? `${days.length} days · ${formatNumber(snapshot.staffHours)} staff-hours` : 'No plan loaded' }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="days.length" class="flex flex-col gap-2">
|
||||||
|
<article v-for="day in days" :key="day.date" class="rounded-lg border p-3 transition-colors" :class="day.date === peakDate ? 'border-[#00C3CD]/40 bg-[#132b40]' : 'border-[#1e3a52] bg-[#132b40] hover:border-[#64748B]/60'">
|
||||||
|
<div class="flex flex-wrap items-center justify-between gap-x-3 gap-y-1">
|
||||||
|
<div class="flex flex-wrap items-center gap-2">
|
||||||
|
<span class="text-[13px] font-bold text-white">{{ day.weekdayLong }}</span>
|
||||||
|
<span class="text-[11px] text-[#64748B]">{{ day.dayNumber }} {{ day.month }}</span>
|
||||||
|
<span v-if="day.date === peakDate" class="rounded bg-[#00C3CD] px-2 py-0.5 text-[10px] font-bold tracking-wide text-[#081723]">PEAK DAY</span>
|
||||||
|
</div>
|
||||||
|
<div class="flex items-baseline gap-1.5">
|
||||||
|
<span class="font-mono text-base font-bold" :class="day.date === peakDate ? 'text-[#00C3CD]' : 'text-white'">{{ day.peakStaff }}</span>
|
||||||
|
<span class="text-[10px] text-[#64748B]">peak staff</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mt-2.5 grid grid-cols-1 gap-2.5 sm:grid-cols-[minmax(0,1fr)_auto] sm:items-center">
|
||||||
|
<div class="flex flex-col gap-1">
|
||||||
|
<div class="flex items-center justify-between text-[10px]">
|
||||||
|
<span class="text-[#94A3B8]">Staff-hours</span>
|
||||||
|
<span class="font-mono font-semibold text-white">{{ day.staffHours }}</span>
|
||||||
|
</div>
|
||||||
|
<MiniBar :value="maxStaffHours ? (day.staffHours / maxStaffHours) * 100 : 0" :tone="day.date === peakDate ? 'accent' : 'muted'" :label="`${day.weekdayLong}: ${day.staffHours} scheduled staff-hours`" />
|
||||||
|
</div>
|
||||||
|
<div class="flex items-center justify-between gap-4 text-[10px] sm:justify-end">
|
||||||
|
<span class="text-[#94A3B8]">Overstaffed</span>
|
||||||
|
<span class="font-mono font-semibold text-white">{{ day.overHours }} h</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mt-2 flex flex-wrap items-center gap-1.5">
|
||||||
|
<span v-for="shift in day.shifts" :key="`${shift.start}-${shift.end}`" class="rounded border border-[#1e3a52] bg-[#0e2233] px-2 py-0.5 font-mono text-[10px] text-[#94A3B8]" :aria-label="`${shift.staff} staff, ${shift.start} to ${shift.end}`">{{ shift.start }}–{{ shift.end }}</span>
|
||||||
|
<span v-if="!day.shifts.length" class="text-[10px] text-[#64748B]">No shift blocks</span>
|
||||||
|
</div>
|
||||||
|
</article>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-else class="rounded-lg border border-dashed border-[#1e3a52] bg-[#132b40] p-4 text-[11px] leading-relaxed text-[#94A3B8]" role="status">
|
||||||
|
{{ pending ? 'Loading the shift plan…' : 'No shift rows are available. Nothing is estimated.' }}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { USE_CASE_TABS } from '#shared/use-cases'
|
||||||
|
import type { UseCaseId } from '#shared/use-cases'
|
||||||
|
|
||||||
|
const props = defineProps<{ active: UseCaseId }>()
|
||||||
|
const route = useRoute()
|
||||||
|
|
||||||
|
function to(id: UseCaseId) {
|
||||||
|
return { path: '/use-cases', query: { ...route.query, uc: id } }
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<nav
|
||||||
|
aria-label="Use case"
|
||||||
|
class="flex w-full flex-col items-stretch gap-1.5 rounded-xl border border-[#1e3a52] bg-[#0e2233] p-1.5 shadow-sm sm:flex-row"
|
||||||
|
>
|
||||||
|
<NuxtLink
|
||||||
|
v-for="tab in USE_CASE_TABS"
|
||||||
|
:key="tab.id"
|
||||||
|
:to="to(tab.id)"
|
||||||
|
class="flex flex-1 items-center justify-between rounded-lg px-4 py-2.5 text-left transition-all"
|
||||||
|
:class="
|
||||||
|
active === tab.id
|
||||||
|
? 'border border-[#00C3CD]/40 bg-[#132b40] text-white shadow-sm'
|
||||||
|
: 'text-[#94A3B8] hover:bg-[#132b40]/60 hover:text-white'
|
||||||
|
"
|
||||||
|
:aria-current="active === tab.id ? 'page' : undefined"
|
||||||
|
>
|
||||||
|
<span class="flex min-w-0 flex-col">
|
||||||
|
<span class="flex items-center gap-2">
|
||||||
|
<span
|
||||||
|
class="text-[11px] font-bold uppercase tracking-wider"
|
||||||
|
:class="active === tab.id ? 'text-[#00C3CD]' : 'text-[#94A3B8]'"
|
||||||
|
>
|
||||||
|
{{ tab.eyebrow }}
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
v-if="active === tab.id"
|
||||||
|
class="h-1.5 w-1.5 rounded-full bg-[#00C3CD] animate-pulse"
|
||||||
|
aria-hidden="true"
|
||||||
|
/>
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
class="mt-0.5 truncate text-[13px]"
|
||||||
|
:class="active === tab.id ? 'text-[#94A3B8]' : 'text-[#64748B]'"
|
||||||
|
>
|
||||||
|
{{ tab.title }}
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
<Icon
|
||||||
|
:name="tab.icon"
|
||||||
|
class="ml-2 shrink-0 text-[19px]"
|
||||||
|
:class="active === tab.id ? 'text-[#00C3CD]' : 'text-[#64748B]'"
|
||||||
|
/>
|
||||||
|
</NuxtLink>
|
||||||
|
</nav>
|
||||||
|
</template>
|
||||||
+51
-10
@@ -5,7 +5,17 @@ const menuButton = ref<HTMLButtonElement | null>(null)
|
|||||||
|
|
||||||
const engineActive = computed(() => route.path === '/')
|
const engineActive = computed(() => route.path === '/')
|
||||||
const sensorsActive = computed(() => route.path.startsWith('/sensors'))
|
const sensorsActive = computed(() => route.path.startsWith('/sensors'))
|
||||||
|
const useCasesActive = computed(() => route.path.startsWith('/use-cases'))
|
||||||
const playgroundActive = computed(() => route.path.startsWith('/playground'))
|
const playgroundActive = computed(() => route.path.startsWith('/playground'))
|
||||||
|
const activeUseCase = computed(() =>
|
||||||
|
route.query.uc === 'staffing' || route.query.uc === 'prezero' ? route.query.uc : 'routing',
|
||||||
|
)
|
||||||
|
|
||||||
|
const useCaseLinks = [
|
||||||
|
{ id: 'staffing', label: 'UC1: Staffing' },
|
||||||
|
{ id: 'routing', label: 'UC2: Smart Routing' },
|
||||||
|
{ id: 'prezero', label: 'UC3: PreZero Depot' },
|
||||||
|
] as const
|
||||||
|
|
||||||
const navLinkClass =
|
const navLinkClass =
|
||||||
'inline-flex h-16 items-center border-b-2 font-label-md transition-colors'
|
'inline-flex h-16 items-center border-b-2 font-label-md transition-colors'
|
||||||
@@ -80,13 +90,13 @@ watch(() => route.fullPath, closeMenu)
|
|||||||
>
|
>
|
||||||
Sensors
|
Sensors
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
<span
|
<NuxtLink
|
||||||
class="inline-flex h-16 items-center border-b-2 border-transparent font-label-md text-[#94A3B8] cursor-not-allowed"
|
to="/use-cases"
|
||||||
aria-disabled="true"
|
:class="desktopLinkClass(useCasesActive)"
|
||||||
title="Coming soon"
|
:aria-current="useCasesActive ? 'page' : undefined"
|
||||||
>
|
>
|
||||||
Use cases
|
Use cases
|
||||||
</span>
|
</NuxtLink>
|
||||||
<NuxtLink
|
<NuxtLink
|
||||||
to="/playground"
|
to="/playground"
|
||||||
:class="desktopLinkClass(playgroundActive)"
|
:class="desktopLinkClass(playgroundActive)"
|
||||||
@@ -96,6 +106,24 @@ watch(() => route.fullPath, closeMenu)
|
|||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
|
<div class="hidden shrink-0 items-center gap-3 xl:flex">
|
||||||
|
<div class="flex items-center rounded-lg border border-[#1e3a52] bg-[#0e2233] p-1">
|
||||||
|
<NuxtLink
|
||||||
|
v-for="item in useCaseLinks"
|
||||||
|
:key="item.id"
|
||||||
|
:to="{ path: '/use-cases', query: { uc: item.id } }"
|
||||||
|
class="rounded px-2.5 py-1 text-[12px] font-medium transition-all"
|
||||||
|
:class="
|
||||||
|
useCasesActive && activeUseCase === item.id
|
||||||
|
? 'border border-[#00C3CD]/20 bg-[#132b40] font-semibold text-[#00C3CD] shadow-sm'
|
||||||
|
: 'text-[#94A3B8] hover:text-white'
|
||||||
|
"
|
||||||
|
>
|
||||||
|
{{ item.label }}
|
||||||
|
</NuxtLink>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
ref="menuButton"
|
ref="menuButton"
|
||||||
type="button"
|
type="button"
|
||||||
@@ -132,13 +160,26 @@ watch(() => route.fullPath, closeMenu)
|
|||||||
>
|
>
|
||||||
Sensors
|
Sensors
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
<span
|
<NuxtLink
|
||||||
class="inline-flex h-12 items-center justify-center font-label-md text-[#94A3B8] cursor-not-allowed"
|
to="/use-cases"
|
||||||
aria-disabled="true"
|
:class="mobileLinkClassFor(useCasesActive)"
|
||||||
title="Coming soon"
|
:aria-current="useCasesActive ? 'page' : undefined"
|
||||||
|
@click="closeMenu"
|
||||||
>
|
>
|
||||||
Use cases
|
Use cases
|
||||||
</span>
|
</NuxtLink>
|
||||||
|
<div class="grid grid-cols-3 gap-1 pb-2" aria-label="Use cases">
|
||||||
|
<NuxtLink
|
||||||
|
v-for="item in useCaseLinks"
|
||||||
|
:key="item.id"
|
||||||
|
:to="{ path: '/use-cases', query: { uc: item.id } }"
|
||||||
|
class="rounded border border-[#1e3a52] bg-[#0e2233] px-1 py-2 text-center text-[10px] font-medium text-[#94A3B8]"
|
||||||
|
:class="useCasesActive && activeUseCase === item.id ? 'border-[#00C3CD]/40 text-[#00C3CD]' : ''"
|
||||||
|
@click="closeMenu"
|
||||||
|
>
|
||||||
|
{{ item.label }}
|
||||||
|
</NuxtLink>
|
||||||
|
</div>
|
||||||
<NuxtLink
|
<NuxtLink
|
||||||
to="/playground"
|
to="/playground"
|
||||||
:class="mobileLinkClassFor(playgroundActive)"
|
:class="mobileLinkClassFor(playgroundActive)"
|
||||||
|
|||||||
+1
-1
@@ -41,7 +41,7 @@ const comparisonRows = [
|
|||||||
<span>Try the engine</span>
|
<span>Try the engine</span>
|
||||||
<Icon name="material-symbols:arrow-forward" class="text-[18px] group-hover:translate-x-0.5 transition-transform text-[#081723]" />
|
<Icon name="material-symbols:arrow-forward" class="text-[18px] group-hover:translate-x-0.5 transition-transform text-[#081723]" />
|
||||||
</a>
|
</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]" />
|
<Icon name="material-symbols:visibility-outline" class="text-[18px] text-[#00C3CD]" />
|
||||||
<span>See live use cases</span>
|
<span>See live use cases</span>
|
||||||
</a>
|
</a>
|
||||||
|
|||||||
@@ -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>
|
||||||
@@ -54,6 +54,26 @@ export default defineNuxtConfig({
|
|||||||
'material-symbols:cloud-off',
|
'material-symbols:cloud-off',
|
||||||
'material-symbols:water-drop',
|
'material-symbols:water-drop',
|
||||||
'material-symbols:info',
|
'material-symbols:info',
|
||||||
|
'material-symbols:add',
|
||||||
|
'material-symbols:cloud',
|
||||||
|
'material-symbols:database',
|
||||||
|
'material-symbols:download',
|
||||||
|
'material-symbols:eco',
|
||||||
|
'material-symbols:expand-more',
|
||||||
|
'material-symbols:groups',
|
||||||
|
'material-symbols:inventory-2',
|
||||||
|
'material-symbols:layers',
|
||||||
|
'material-symbols:local-drink',
|
||||||
|
'material-symbols:my-location',
|
||||||
|
'material-symbols:open-in-new',
|
||||||
|
'material-symbols:query-stats',
|
||||||
|
'material-symbols:recycling',
|
||||||
|
'material-symbols:refresh',
|
||||||
|
'material-symbols:remove',
|
||||||
|
'material-symbols:table-chart',
|
||||||
|
'material-symbols:wb-sunny',
|
||||||
|
'material-symbols:trending-up',
|
||||||
|
'material-symbols:route',
|
||||||
],
|
],
|
||||||
scan: true,
|
scan: true,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
{"source":"OpenStreetMap contributors, ODbL","generated":"2026-11-14","bounds":{"minlat":49.1394,"maxlat":49.1432,"minlon":9.2169,"maxlon":9.2212},"buildings":[{"name":"Galeria Kaufhof","kind":"retail","points":[[9.217234,49.14003],[9.218368,49.140169],[9.218594,49.140196],[9.218709,49.139793],[9.218446,49.139761],[9.218451,49.139745],[9.218229,49.139718],[9.218217,49.139759],[9.217871,49.139717],[9.217342,49.139652],[9.217333,49.139682],[9.217252,49.139967],[9.217234,49.14003]]},{"name":"Klosterhof","kind":"retail","points":[[9.219945,49.141147],[9.220166,49.141526],[9.220209,49.141642],[9.22039,49.141588],[9.220465,49.141571],[9.220498,49.141567],[9.220502,49.141589],[9.220623,49.141572],[9.22076,49.141554],[9.220791,49.141622],[9.220803,49.141665],[9.220851,49.141658],[9.220852,49.141661],[9.221174,49.14138],[9.220895,49.141412],[9.220765,49.140947],[9.219945,49.141147]]},{"name":null,"kind":"apartments","points":[[9.217057,49.142312],[9.217105,49.142493],[9.217134,49.142588],[9.217184,49.142667],[9.217324,49.142883],[9.217967,49.142714],[9.217962,49.142692],[9.218102,49.142682],[9.218081,49.14255],[9.218058,49.142549],[9.21805,49.142484],[9.218098,49.142478],[9.218158,49.142475],[9.218156,49.142461],[9.218157,49.142454],[9.218169,49.142452],[9.218131,49.142282],[9.218008,49.142302],[9.218012,49.142322],[9.217959,49.142339],[9.21796,49.142385],[9.217964,49.142469],[9.217831,49.14248],[9.217853,49.142616],[9.217816,49.142627],[9.217413,49.142737],[9.217295,49.142556],[9.217273,49.142477],[9.217251,49.142392],[9.21728,49.142387],[9.217371,49.142374],[9.217315,49.142264],[9.217188,49.142288],[9.21718,49.14227],[9.217057,49.142312]]},{"name":null,"kind":"commercial","points":[[9.219126,49.139658],[9.219223,49.139686],[9.219263,49.139638],[9.219402,49.139685],[9.219371,49.13973],[9.219519,49.139782],[9.21945,49.139872],[9.219604,49.139921],[9.219663,49.139846],[9.219701,49.139855],[9.219638,49.139936],[9.219812,49.139992],[9.219875,49.139911],[9.220056,49.139984],[9.220231,49.139798],[9.219261,49.139474],[9.219126,49.139658]]},{"name":"Stadtgalerie","kind":"public","points":[[9.216965,49.140699],[9.21707,49.140657],[9.217226,49.14034],[9.217606,49.140368],[9.21827,49.140332],[9.218329,49.140318],[9.218398,49.140296],[9.218447,49.140275],[9.218444,49.140269],[9.218458,49.140258],[9.218459,49.140246],[9.218373,49.140232],[9.217333,49.140098],[9.216965,49.140699]]},{"name":"Kilianskirche","kind":"church","points":[[9.219108,49.141871],[9.219628,49.141799],[9.219632,49.141817],[9.219774,49.141803],[9.219814,49.141798],[9.219856,49.14176],[9.219834,49.141756],[9.219847,49.141717],[9.21987,49.1417],[9.219889,49.141704],[9.219893,49.141692],[9.219871,49.141689],[9.219866,49.141664],[9.219884,49.141656],[9.219875,49.141648],[9.219798,49.141622],[9.219792,49.141608],[9.219814,49.1416],[9.219807,49.141593],[9.219741,49.141589],[9.219733,49.141556],[9.219718,49.141557],[9.21968,49.141561],[9.219677,49.141547],[9.219575,49.141558],[9.219565,49.141605],[9.219503,49.141591],[9.21905,49.141642],[9.2189,49.14169],[9.218924,49.141778],[9.218905,49.141778],[9.218905,49.141797],[9.21891,49.141797],[9.218918,49.141817],[9.218967,49.14183],[9.218979,49.141849],[9.218962,49.141861],[9.219108,49.141871]]},{"name":"Deutschhof","kind":"public","points":[[9.2172,49.141208],[9.217327,49.141209],[9.217409,49.140619],[9.217477,49.140531],[9.2175,49.14054],[9.217928,49.140516],[9.21798,49.140513],[9.217997,49.140415],[9.217369,49.140451],[9.217268,49.140583],[9.217267,49.140588],[9.217257,49.140628],[9.217176,49.141206],[9.2172,49.141208]]},{"name":"Parkhaus Klosterhof - Kiliansplatz","kind":"building","points":[[9.220895,49.141412],[9.221174,49.14138],[9.221107,49.141122],[9.221063,49.140888],[9.22096,49.140907],[9.220765,49.140947],[9.220895,49.141412]]},{"name":"St. Peter und Paul","kind":"church","points":[[9.217219,49.141341],[9.217383,49.141345],[9.217381,49.141365],[9.217375,49.141369],[9.21738,49.141373],[9.217528,49.141364],[9.217539,49.141396],[9.217552,49.141364],[9.217809,49.141377],[9.217815,49.141374],[9.217807,49.141369],[9.217808,49.141326],[9.217876,49.141309],[9.21788,49.141264],[9.217828,49.141229],[9.217602,49.141239],[9.217611,49.141151],[9.217582,49.141131],[9.217537,49.14113],[9.217522,49.14114],[9.217382,49.141138],[9.217381,49.141182],[9.217329,49.141181],[9.217327,49.141209],[9.2172,49.141208],[9.21721,49.141274],[9.217219,49.141341]]},{"name":"Holiday Inn Express","kind":"building","points":[[9.220683,49.140836],[9.220685,49.140841],[9.220612,49.140856],[9.220533,49.1408],[9.220699,49.140522],[9.220862,49.140568],[9.220803,49.140664],[9.220839,49.140675],[9.221055,49.140627],[9.221041,49.140601],[9.221131,49.14058],[9.221138,49.140596],[9.221104,49.14075],[9.221109,49.14076],[9.221061,49.14077],[9.221056,49.14076],[9.220683,49.140836]]},{"name":"REWE City","kind":"commercial","points":[[9.219065,49.140621],[9.219114,49.140709],[9.219154,49.140782],[9.219754,49.140629],[9.219711,49.14052],[9.219302,49.14057],[9.Line truncated
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1 @@
|
|||||||
|
{"meta":{"source":"glass_fill_levels_anonymized_f.csv","generated_at":"2026-11-14T16:53:20Z","rows":11701,"containers":449,"material_series":1338,"date_from":"2025-10-17","date_to":"2026-09-30","reference_date":"2026-09-30","overfull_readings":1192,"priority_rule":"high: overfull_count >= 5 or (overfull_count >= 2 and overfull_rate >= 0.25); medium: overfull_count >= 1 and not high; low: 0","limitations":["No coordinates in the dataset; this is a priority proof, not a route.","No container capacity or depot data.","Overfull is a reported state, not a measured volume."]},"summary":{"priority_counts":{"high":88,"medium":248,"low":113},"by_material":{"white":{"readings":4432,"overfull":731},"green":{"readings":4169,"overfull":357},"brown":{"readings":3100,"overfull":104}}},"top":[{"location_id":"eecbf6fa-decf-46da-b110-bf014e7c181d","priority":"high","priority_score":21.525,"readings":80,"overfull_count":21,"overfull_rate":0.2625,"p95_fill":100,"max_fill":100,"mean_fill":64.24,"last_fill":null,"last_is_overfull":true,"last_date":"2026-09-29","days_since_last":1,"trend":30,"materials":{"white":{"readings":29,"overfull_count":12,"last_fill":null,"last_is_overfull":true,"last_date":"2026-09-29"},"green":{"readings":29,"overfull_count":6,"last_fill":null,"last_is_overfull":true,"last_date":"2026-09-29"},"brown":{"readings":22,"overfull_count":3,"last_fill":null,"last_is_overfull":true,"last_date":"2026-09-29"}}},{"location_id":"fdccb1ff-bce6-4e0f-842d-305a11a8de2e","priority":"high","priority_score":20.4396,"readings":91,"overfull_count":20,"overfull_rate":0.21978021978021978,"p95_fill":100,"max_fill":100,"mean_fill":65.07,"last_fill":80,"last_is_overfull":false,"last_date":"2026-09-09","days_since_last":21,"trend":30,"materials":{"white":{"readings":33,"overfull_count":9,"last_fill":80,"last_is_overfull":false,"last_date":"2026-09-09"},"green":{"readings":32,"overfull_count":7,"last_fill":70,"last_is_overfull":false,"last_date":"2026-09-09"},"brown":{"readings":26,"overfull_count":4,"last_fill":20,"last_is_overfull":false,"last_date":"2026-09-09"}}},{"location_id":"80b7f22a-d2e7-44a8-a6d7-c1948331fa51","priority":"high","priority_score":18.8372,"readings":43,"overfull_count":18,"overfull_rate":0.4186046511627907,"p95_fill":100,"max_fill":100,"mean_fill":70.4,"last_fill":null,"last_is_overfull":true,"last_date":"2026-09-28","days_since_last":2,"trend":0,"materials":{"white":{"readings":17,"overfull_count":6,"last_fill":null,"last_is_overfull":true,"last_date":"2026-09-28"},"green":{"readings":17,"overfull_count":9,"last_fill":null,"last_is_overfull":true,"last_date":"2026-09-28"},"brown":{"readings":9,"overfull_count":3,"last_fill":null,"last_is_overfull":true,"last_date":"2026-09-28"}}},{"location_id":"2a91cfc0-cda2-454b-bfd1-bbf0035a2c06","priority":"high","priority_score":13.4483,"readings":58,"overfull_count":13,"overfull_rate":0.22413793103448276,"p95_fill":100,"max_fill":100,"mean_fill":63.11,"last_fill":40,"last_is_overfull":false,"last_date":"2026-09-17","days_since_last":13,"trend":10,"materials":{"white":{"readings":21,"overfull_count":8,"last_fill":40,"last_is_overfull":false,"last_date":"2026-09-17"},"green":{"readings":20,"overfull_count":3,"last_fill":40,"last_is_overfull":false,"last_date":"2026-09-17"},"brown":{"readings":17,"overfull_count":2,"last_fill":20,"last_is_overfull":false,"last_date":"2026-09-17"}}},{"location_id":"9dc40dd4-2ad6-4d7e-a920-71ff3c5c9356","priority":"high","priority_score":11.4681,"readings":47,"overfull_count":11,"overfull_rate":0.23404255319148937,"p95_fill":100,"max_fill":100,"mean_fill":60.56,"last_fill":60,"last_is_overfull":false,"last_date":"2026-09-17","days_since_last":13,"trend":10,"materials":{"white":{"readings":18,"overfull_count":6,"last_fill":60,"last_is_overfull":false,"last_date":"2026-09-17"},"green":{"readings":18,"overfull_count":4,"last_fill":20,"last_is_overfull":false,"last_date":"2026-09-17"},"brown":{"readings":11,"overfull_count":1,"last_fill":40,"last_is_overfull":false,"last_date":"2026-09-17"}}},{"location_id":"e5466d8a-3c44-4f2b-a624-d944703ff27b","priority":"high","priority_score":11.4074,"readings":54,"overfull_count":11,"overfull_rate":0.2037037037037037,"p95_fill":100,"max_fill":100,"mean_fill":65.81,"last_fill":90,"last_is_overfull":false,"last_date":"2026-09-17","days_since_last":13,"trend":35,"materials":{"white":{"readings":20,"overfull_count":7,"last_fill":90,"last_is_overfull":false,"last_date":"2026-09-17"},"green":{"readings":19,"overfull_count":3,"last_fill":60,"last_is_overfull":false,"last_date":"2026-09-17"},"brown":{"readings":15,"overfull_count":1,"last_fill":20,"last_is_overfull":false,"last_date":"2026-09-17"}}},{"location_id":"cf3c2e1a-6061-471c-8e22-9dded9f30184","priority":"high","priority_score":11.3333,"readings":66,"overfull_count":11,"overfull_rate":0.16666666666666666,"p95_fill":100,"max_fill":100,"mean_fill":59.64,"last_fill":50,"last_is_overfull":false,"last_date":"2026-09-17","days_since_last":13,"trend":15,"mateLine truncated
|
||||||
@@ -0,0 +1,221 @@
|
|||||||
|
// Build the small, committed data artifacts used by /use-cases.
|
||||||
|
//
|
||||||
|
// Sources (outside this repo):
|
||||||
|
// ../../cool-city-data/route/raw/area_osm.xml OSM extract, ODbL
|
||||||
|
// ../../ML-py.git/feat-prezero-api/artifacts/prezero_priority.json
|
||||||
|
//
|
||||||
|
// Outputs:
|
||||||
|
// public/cool-city/buildings.json real building footprints around the routes
|
||||||
|
// public/prezero/priority.json summary + top priority containers
|
||||||
|
//
|
||||||
|
// Run from the web repo root:
|
||||||
|
// node scripts/build-use-case-data.mjs
|
||||||
|
import fs from 'node:fs'
|
||||||
|
import path from 'node:path'
|
||||||
|
|
||||||
|
const root = process.cwd()
|
||||||
|
const dataRoot = path.resolve(root, '../..')
|
||||||
|
|
||||||
|
// Route window with a small margin: the three routes span
|
||||||
|
// lat 49.14023..49.14254, lon 9.21753..9.22039.
|
||||||
|
const BOUNDS = { minlat: 49.1394, maxlat: 49.1432, minlon: 9.2169, maxlon: 9.2212 }
|
||||||
|
const SIMPLIFY_TOLERANCE = 0.000018
|
||||||
|
|
||||||
|
function decodeXml(value) {
|
||||||
|
return value
|
||||||
|
.replaceAll('&', '&')
|
||||||
|
.replaceAll('"', '"')
|
||||||
|
.replaceAll(''', "'")
|
||||||
|
.replaceAll('<', '<')
|
||||||
|
.replaceAll('>', '>')
|
||||||
|
}
|
||||||
|
|
||||||
|
function readOsm(file) {
|
||||||
|
const xml = fs.readFileSync(file, 'utf8')
|
||||||
|
const nodes = new Map()
|
||||||
|
const nodeRe = /<node\b([^>]*?)\/?>/g
|
||||||
|
let match
|
||||||
|
while ((match = nodeRe.exec(xml))) {
|
||||||
|
const attrs = match[1]
|
||||||
|
const id = attrs.match(/\bid="(-?\d+)"/)?.[1]
|
||||||
|
const lat = Number(attrs.match(/\blat="(-?[\d.]+)"/)?.[1])
|
||||||
|
const lon = Number(attrs.match(/\blon="(-?[\d.]+)"/)?.[1])
|
||||||
|
if (!id || !Number.isFinite(lat) || !Number.isFinite(lon)) continue
|
||||||
|
const tags = {}
|
||||||
|
const tagRe = /<tag\b([^>]*?)\/?>/g
|
||||||
|
let tag
|
||||||
|
while ((tag = tagRe.exec(match[0]))) {
|
||||||
|
const k = tag[1].match(/\bk="([^"]*)"/)?.[1]
|
||||||
|
const v = tag[1].match(/\bv="([^"]*)"/)?.[1]
|
||||||
|
if (k) tags[decodeXml(k)] = decodeXml(v ?? '')
|
||||||
|
}
|
||||||
|
nodes.set(id, { lat, lon, tags })
|
||||||
|
}
|
||||||
|
|
||||||
|
const ways = []
|
||||||
|
const wayRe = /<way\b([^>]*)>([\s\S]*?)<\/way>/g
|
||||||
|
while ((match = wayRe.exec(xml))) {
|
||||||
|
const body = match[2]
|
||||||
|
const refs = [...body.matchAll(/<nd\b[^>]*\bref="(-?\d+)"/g)].map((row) => row[1])
|
||||||
|
const tags = {}
|
||||||
|
const tagRe = /<tag\b([^>]*?)\/?>/g
|
||||||
|
let tag
|
||||||
|
while ((tag = tagRe.exec(body))) {
|
||||||
|
const k = tag[1].match(/\bk="([^"]*)"/)?.[1]
|
||||||
|
const v = tag[1].match(/\bv="([^"]*)"/)?.[1]
|
||||||
|
if (k) tags[decodeXml(k)] = decodeXml(v ?? '')
|
||||||
|
}
|
||||||
|
ways.push({ refs, tags })
|
||||||
|
}
|
||||||
|
return { nodes, ways }
|
||||||
|
}
|
||||||
|
|
||||||
|
function inBounds(point, bounds) {
|
||||||
|
return (
|
||||||
|
point.lat >= bounds.minlat &&
|
||||||
|
point.lat <= bounds.maxlat &&
|
||||||
|
point.lon >= bounds.minlon &&
|
||||||
|
point.lon <= bounds.maxlon
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function distanceToSegment(p, a, b) {
|
||||||
|
const dx = b[0] - a[0]
|
||||||
|
const dy = b[1] - a[1]
|
||||||
|
if (dx === 0 && dy === 0) return Math.hypot(p[0] - a[0], p[1] - a[1])
|
||||||
|
const t = Math.max(
|
||||||
|
0,
|
||||||
|
Math.min(1, ((p[0] - a[0]) * dx + (p[1] - a[1]) * dy) / (dx * dx + dy * dy)),
|
||||||
|
)
|
||||||
|
return Math.hypot(p[0] - (a[0] + t * dx), p[1] - (a[1] + t * dy))
|
||||||
|
}
|
||||||
|
|
||||||
|
function simplify(points, tolerance) {
|
||||||
|
if (points.length <= 4) return points
|
||||||
|
let maxDistance = 0
|
||||||
|
let index = 0
|
||||||
|
for (let i = 1; i < points.length - 1; i += 1) {
|
||||||
|
const distance = distanceToSegment(points[i], points[0], points.at(-1))
|
||||||
|
if (distance > maxDistance) {
|
||||||
|
maxDistance = distance
|
||||||
|
index = i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (maxDistance > tolerance) {
|
||||||
|
const left = simplify(points.slice(0, index + 1), tolerance)
|
||||||
|
const right = simplify(points.slice(index), tolerance)
|
||||||
|
return [...left.slice(0, -1), ...right]
|
||||||
|
}
|
||||||
|
return [points[0], points.at(-1)]
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildBuildings(source) {
|
||||||
|
const { nodes, ways } = readOsm(source)
|
||||||
|
const buildings = []
|
||||||
|
for (const way of ways) {
|
||||||
|
if (!way.tags.building && !way.tags['building:part']) continue
|
||||||
|
if (way.tags['building:part'] === 'yes' && !way.tags.building) {
|
||||||
|
// Roof-only parts duplicate the main footprint at this zoom.
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
const points = way.refs
|
||||||
|
.map((ref) => nodes.get(ref))
|
||||||
|
.filter(Boolean)
|
||||||
|
.filter((node) => inBounds(node, BOUNDS))
|
||||||
|
.map((node) => [node.lon, node.lat])
|
||||||
|
if (points.length < 3) continue
|
||||||
|
if (points[0][0] !== points.at(-1)[0] || points[0][1] !== points.at(-1)[1]) {
|
||||||
|
points.push(points[0])
|
||||||
|
}
|
||||||
|
const simplified = simplify(points, SIMPLIFY_TOLERANCE)
|
||||||
|
if (simplified.length < 3) continue
|
||||||
|
buildings.push({
|
||||||
|
name: way.tags.name || null,
|
||||||
|
kind: way.tags.building === 'yes' ? 'building' : way.tags.building || 'building',
|
||||||
|
points: simplified.map(([lon, lat]) => [
|
||||||
|
Math.round(lon * 1e6) / 1e6,
|
||||||
|
Math.round(lat * 1e6) / 1e6,
|
||||||
|
]),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
buildings.sort((a, b) => {
|
||||||
|
const areaA = polygonArea(a.points)
|
||||||
|
const areaB = polygonArea(b.points)
|
||||||
|
return areaB - areaA
|
||||||
|
})
|
||||||
|
return {
|
||||||
|
source: 'OpenStreetMap contributors, ODbL',
|
||||||
|
generated: new Date().toISOString().slice(0, 10),
|
||||||
|
bounds: BOUNDS,
|
||||||
|
buildings,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function polygonArea(points) {
|
||||||
|
let area = 0
|
||||||
|
for (let i = 0; i < points.length - 1; i += 1) {
|
||||||
|
area += points[i][0] * points[i + 1][1] - points[i + 1][0] * points[i][1]
|
||||||
|
}
|
||||||
|
return Math.abs(area / 2)
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildPrezero(source) {
|
||||||
|
const full = JSON.parse(fs.readFileSync(source, 'utf8'))
|
||||||
|
const containers = [...full.containers]
|
||||||
|
.sort((a, b) => {
|
||||||
|
const rank = { high: 0, medium: 1, low: 2 }
|
||||||
|
return (
|
||||||
|
rank[a.priority] - rank[b.priority] ||
|
||||||
|
b.priority_score - a.priority_score ||
|
||||||
|
b.overfull_count - a.overfull_count
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.slice(0, 24)
|
||||||
|
.map((row) => ({
|
||||||
|
location_id: row.location_id,
|
||||||
|
priority: row.priority,
|
||||||
|
priority_score: row.priority_score,
|
||||||
|
readings: row.readings,
|
||||||
|
overfull_count: row.overfull_count,
|
||||||
|
overfull_rate: row.overfull_rate,
|
||||||
|
p95_fill: row.p95_fill,
|
||||||
|
max_fill: row.max_fill,
|
||||||
|
mean_fill: row.mean_fill,
|
||||||
|
last_fill: row.last_fill,
|
||||||
|
last_is_overfull: row.last_is_overfull,
|
||||||
|
last_date: row.last_date,
|
||||||
|
days_since_last: row.days_since_last,
|
||||||
|
trend: row.trend,
|
||||||
|
materials: row.materials,
|
||||||
|
}))
|
||||||
|
return {
|
||||||
|
meta: full.meta,
|
||||||
|
summary: full.summary,
|
||||||
|
top: containers,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const buildings = buildBuildings(
|
||||||
|
path.join(dataRoot, 'cool-city-data/route/raw/area_osm.xml'),
|
||||||
|
)
|
||||||
|
fs.mkdirSync(path.join(root, 'public/cool-city'), { recursive: true })
|
||||||
|
fs.writeFileSync(
|
||||||
|
path.join(root, 'public/cool-city/buildings.json'),
|
||||||
|
`${JSON.stringify(buildings)}\n`,
|
||||||
|
)
|
||||||
|
|
||||||
|
const prezero = buildPrezero(
|
||||||
|
path.join(dataRoot, 'ML-py.git/feat-prezero-api/artifacts/prezero_priority.json'),
|
||||||
|
)
|
||||||
|
fs.mkdirSync(path.join(root, 'public/prezero'), { recursive: true })
|
||||||
|
fs.writeFileSync(
|
||||||
|
path.join(root, 'public/prezero/priority.json'),
|
||||||
|
`${JSON.stringify(prezero)}\n`,
|
||||||
|
)
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`buildings: ${buildings.buildings.length} -> public/cool-city/buildings.json`,
|
||||||
|
)
|
||||||
|
console.log(
|
||||||
|
`prezero: ${prezero.top.length} of ${prezero.meta.containers} containers -> public/prezero/priority.json`,
|
||||||
|
)
|
||||||
@@ -0,0 +1,435 @@
|
|||||||
|
import { COOL_TIMES } from './cool'
|
||||||
|
import type { CoolRouteBundle, CoolRouteId, CoolRouteValues, CoolTime } from './cool'
|
||||||
|
import { berlinParts } from './staffing'
|
||||||
|
import type { Sensor, StaffingHour, StaffingResponse, Shift } from './types'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* UC1 Staffing · UC2 Smart Routing · UC3 PreZero.
|
||||||
|
*
|
||||||
|
* These helpers are shared by the page, the panels and the tests. Every number
|
||||||
|
* comes from a real bundle/API payload; no value is generated in the browser.
|
||||||
|
*/
|
||||||
|
export type UseCaseId = 'staffing' | 'routing' | 'prezero'
|
||||||
|
|
||||||
|
export interface UseCaseTab {
|
||||||
|
id: UseCaseId
|
||||||
|
eyebrow: string
|
||||||
|
title: string
|
||||||
|
subtitle: string
|
||||||
|
icon: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export const USE_CASE_TABS: readonly UseCaseTab[] = [
|
||||||
|
{
|
||||||
|
id: 'staffing',
|
||||||
|
eyebrow: 'UC1: Staffing optimization',
|
||||||
|
title: 'Hourly occupancy vs workforce',
|
||||||
|
subtitle: 'Turn the forecast into a shift plan.',
|
||||||
|
icon: 'material-symbols:trending-up',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'routing',
|
||||||
|
eyebrow: 'UC2: Smart micro-climate routing',
|
||||||
|
title: 'Fastest path with modeled shade and access',
|
||||||
|
subtitle: 'Modeled shade, solar position and street access.',
|
||||||
|
icon: 'material-symbols:route',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'prezero',
|
||||||
|
eyebrow: 'UC3: PreZero depot logistics',
|
||||||
|
title: 'Container collection priority',
|
||||||
|
subtitle: 'Rank 449 anonymized container locations from reported states.',
|
||||||
|
icon: 'material-symbols:recycling',
|
||||||
|
},
|
||||||
|
] as const
|
||||||
|
|
||||||
|
export const DEFAULT_USE_CASE: UseCaseId = 'routing'
|
||||||
|
|
||||||
|
export function isUseCaseId(value: unknown): value is UseCaseId {
|
||||||
|
return value === 'staffing' || value === 'routing' || value === 'prezero'
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useCaseById(id: UseCaseId): UseCaseTab {
|
||||||
|
return USE_CASE_TABS.find((tab) => tab.id === id) ?? USE_CASE_TABS[1]!
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isCoolTimeValue(value: unknown): value is CoolTime {
|
||||||
|
return typeof value === 'string' && (COOL_TIMES as readonly string[]).includes(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
/* Routing */
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
const ROUTE_TITLES: Record<CoolRouteId, string> = {
|
||||||
|
shortest: 'Shortest route',
|
||||||
|
shaded: 'Shaded route',
|
||||||
|
accessible: 'Accessible route',
|
||||||
|
}
|
||||||
|
|
||||||
|
export const ROUTE_ORDER: readonly CoolRouteId[] = ['shortest', 'shaded', 'accessible'] as const
|
||||||
|
|
||||||
|
export interface RouteComparisonRow {
|
||||||
|
id: CoolRouteId
|
||||||
|
title: string
|
||||||
|
description: string
|
||||||
|
values: CoolRouteValues
|
||||||
|
recommended: boolean
|
||||||
|
penaltyMin: number
|
||||||
|
tag: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export function routeTitle(id: CoolRouteId): string {
|
||||||
|
return ROUTE_TITLES[id]
|
||||||
|
}
|
||||||
|
|
||||||
|
export function routeValuesFor(
|
||||||
|
bundle: CoolRouteBundle | null | undefined,
|
||||||
|
id: CoolRouteId,
|
||||||
|
time: CoolTime | string,
|
||||||
|
): CoolRouteValues | null {
|
||||||
|
return bundle?.routes.find((route) => route.id === id)?.values[time] ?? null
|
||||||
|
}
|
||||||
|
|
||||||
|
export function recommendedRouteId(
|
||||||
|
bundle: CoolRouteBundle | null | undefined,
|
||||||
|
time: CoolTime | string,
|
||||||
|
): CoolRouteId {
|
||||||
|
return bundle?.recommendationByTime[time] ?? 'shortest'
|
||||||
|
}
|
||||||
|
|
||||||
|
export function recommendedRoute(
|
||||||
|
bundle: CoolRouteBundle | null | undefined,
|
||||||
|
time: CoolTime | string,
|
||||||
|
) {
|
||||||
|
if (!bundle) return null
|
||||||
|
return bundle.routes.find((route) => route.id === recommendedRouteId(bundle, time)) ?? null
|
||||||
|
}
|
||||||
|
|
||||||
|
export function recommendedValues(
|
||||||
|
bundle: CoolRouteBundle | null | undefined,
|
||||||
|
time: CoolTime | string,
|
||||||
|
): CoolRouteValues | null {
|
||||||
|
return routeValuesFor(bundle, recommendedRouteId(bundle, time), time)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function routeTag(
|
||||||
|
id: CoolRouteId,
|
||||||
|
recommended: boolean,
|
||||||
|
values: CoolRouteValues,
|
||||||
|
): string {
|
||||||
|
if (recommended) return 'Recommended'
|
||||||
|
if (id === 'shortest') return values.stepFree ? 'Fastest · 15% ramp' : 'Fastest'
|
||||||
|
if (id === 'shaded') return 'Shaded · longer walk'
|
||||||
|
return 'Step-free · water & benches'
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Candidate rows for the comparison card. `penaltyMin` is the duration after
|
||||||
|
* the fastest candidate, so the values stay real even when the model picks a
|
||||||
|
* slower, step-free route.
|
||||||
|
*/
|
||||||
|
export function routeComparison(
|
||||||
|
bundle: CoolRouteBundle | null | undefined,
|
||||||
|
time: CoolTime | string,
|
||||||
|
): RouteComparisonRow[] {
|
||||||
|
if (!bundle) return []
|
||||||
|
const recommended = recommendedRouteId(bundle, time)
|
||||||
|
const rows = ROUTE_ORDER.flatMap((id) => {
|
||||||
|
const values = routeValuesFor(bundle, id, time)
|
||||||
|
const route = bundle.routes.find((entry) => entry.id === id)
|
||||||
|
if (!values || !route) return []
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
id,
|
||||||
|
title: routeTitle(id),
|
||||||
|
description: route.description,
|
||||||
|
values,
|
||||||
|
recommended: id === recommended,
|
||||||
|
penaltyMin: 0,
|
||||||
|
tag: '',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
})
|
||||||
|
const fastest = Math.min(...rows.map((row) => row.values.durationMin))
|
||||||
|
return rows.map((row) => ({
|
||||||
|
...row,
|
||||||
|
penaltyMin: Math.round((row.values.durationMin - fastest) * 10) / 10,
|
||||||
|
tag: routeTag(row.id, row.recommended, row.values),
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
export function routeRationale(
|
||||||
|
bundle: CoolRouteBundle | null | undefined,
|
||||||
|
time: CoolTime | string,
|
||||||
|
): string {
|
||||||
|
if (!bundle) return 'The route bundle is unavailable. Nothing is estimated.'
|
||||||
|
const route = recommendedRoute(bundle, time)
|
||||||
|
const values = recommendedValues(bundle, time)
|
||||||
|
if (!route || !values) return 'The route bundle has no values for this hour.'
|
||||||
|
|
||||||
|
const fastest = routeComparison(bundle, time)
|
||||||
|
.slice()
|
||||||
|
.sort((a, b) => a.values.durationMin - b.values.durationMin)[0]
|
||||||
|
const delta =
|
||||||
|
fastest && fastest.id !== route.id
|
||||||
|
? ` It is ${formatMinutes(values.durationMin - fastest.values.durationMin)} longer than the fastest candidate.`
|
||||||
|
: ' It is also the fastest candidate.'
|
||||||
|
const access = values.stepFree
|
||||||
|
? values.rampInclinePct === null || values.rampInclinePct === undefined
|
||||||
|
? ' The route is step-free with no ramp.'
|
||||||
|
: ` The route is step-free but includes a ${values.rampInclinePct}% ramp.`
|
||||||
|
: ' The route is not step-free.'
|
||||||
|
const weather = bundle.hotDay
|
||||||
|
? `${bundle.hotDay.temperature_max_c} °C on the modeled ${bundle.hotDay.date} hot day`
|
||||||
|
: 'the modeled hot day'
|
||||||
|
|
||||||
|
return `Fusing ${weather}, the ${solarAzimuthLabel(bundle, time)}, and modeled shade from OSM buildings and tree crowns: the ${routeTitle(route.id).toLowerCase()} is ${formatPercent(values.shadePct)} shaded with ${formatMinutes(values.directSunMin)} of direct sun and ${values.waterStops} water ${values.waterStops === 1 ? 'stop' : 'stops'}.${access}${delta}`
|
||||||
|
}
|
||||||
|
|
||||||
|
export function solarPosition(
|
||||||
|
bundle: CoolRouteBundle | null | undefined,
|
||||||
|
time: CoolTime | string,
|
||||||
|
): { altitude_deg: number; azimuth_deg: number } | null {
|
||||||
|
return bundle?.meta?.solarPositions?.[time] ?? null
|
||||||
|
}
|
||||||
|
|
||||||
|
export function solarAzimuthLabel(
|
||||||
|
bundle: CoolRouteBundle | null | undefined,
|
||||||
|
time: CoolTime | string,
|
||||||
|
): string {
|
||||||
|
const position = solarPosition(bundle, time)
|
||||||
|
if (!position) return 'solar position unavailable'
|
||||||
|
return `solar azimuth ${Math.round(position.azimuth_deg)}° ${compassDirection(position.azimuth_deg)}`
|
||||||
|
}
|
||||||
|
|
||||||
|
export function compassDirection(degrees: number): string {
|
||||||
|
const points = ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW']
|
||||||
|
const index = Math.round(((degrees % 360) + 360) % 360 / 45) % 8
|
||||||
|
return points[index]!
|
||||||
|
}
|
||||||
|
|
||||||
|
export function formatMinutes(value: number): string {
|
||||||
|
const rounded = Math.round(value * 10) / 10
|
||||||
|
return `${Number.isInteger(rounded) ? rounded : rounded.toFixed(1)} min`
|
||||||
|
}
|
||||||
|
|
||||||
|
export function formatPercent(value: number, digits = 1): string {
|
||||||
|
return `${value.toFixed(digits)}%`
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A GPX 1.1 track from the real OSM route geometry. */
|
||||||
|
export function buildGpx(
|
||||||
|
bundle: CoolRouteBundle,
|
||||||
|
routeId: CoolRouteId,
|
||||||
|
time: CoolTime | string,
|
||||||
|
generatedAt = new Date().toISOString(),
|
||||||
|
): string {
|
||||||
|
const route = bundle.routes.find((entry) => entry.id === routeId)
|
||||||
|
if (!route || route.geometry.length === 0) {
|
||||||
|
throw new Error(`No geometry for route ${routeId}`)
|
||||||
|
}
|
||||||
|
const values = route.values[time]
|
||||||
|
const name = `${routeTitle(routeId)} · ${bundle.origin.name} → ${bundle.destination.name}`
|
||||||
|
const desc = values
|
||||||
|
? `${formatPercent(values.shadePct)} modeled shade, ${formatMinutes(values.directSunMin)} direct sun, ${formatMinutes(values.durationMin)} walk at ${time}. ${bundle.shadeLabel}.`
|
||||||
|
: `${bundle.shadeLabel}.`
|
||||||
|
const points = route.geometry
|
||||||
|
.map(
|
||||||
|
([lon, lat]) =>
|
||||||
|
` <trkpt lat="${lat.toFixed(6)}" lon="${lon.toFixed(6)}" />`,
|
||||||
|
)
|
||||||
|
.join('\n')
|
||||||
|
|
||||||
|
return `<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<gpx version="1.1" creator="Sensing Engine" xmlns="http://www.topografix.com/GPX/1/1">
|
||||||
|
<metadata>
|
||||||
|
<name>${escapeXml(name)}</name>
|
||||||
|
<desc>${escapeXml(desc)}</desc>
|
||||||
|
<time>${generatedAt}</time>
|
||||||
|
</metadata>
|
||||||
|
<trk>
|
||||||
|
<name>${escapeXml(name)}</name>
|
||||||
|
<desc>${escapeXml(desc)}</desc>
|
||||||
|
<trkseg>
|
||||||
|
${points}
|
||||||
|
</trkseg>
|
||||||
|
</trk>
|
||||||
|
</gpx>
|
||||||
|
`
|
||||||
|
}
|
||||||
|
|
||||||
|
function escapeXml(value: string): string {
|
||||||
|
return value
|
||||||
|
.replaceAll('&', '&')
|
||||||
|
.replaceAll('<', '<')
|
||||||
|
.replaceAll('>', '>')
|
||||||
|
.replaceAll('"', '"')
|
||||||
|
.replaceAll("'", ''')
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
/* Staffing */
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
export interface StaffingSnapshot {
|
||||||
|
peakHour: StaffingHour | null
|
||||||
|
peakShift: Shift | null
|
||||||
|
staffHours: number
|
||||||
|
peakFootfall: number
|
||||||
|
savedEur: number
|
||||||
|
savedPct: number
|
||||||
|
coveragePct: number
|
||||||
|
overstaffedHours: number
|
||||||
|
understaffedHours: number
|
||||||
|
days: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export function staffingSnapshot(plan: StaffingResponse | null | undefined): StaffingSnapshot {
|
||||||
|
if (!plan) {
|
||||||
|
return {
|
||||||
|
peakHour: null,
|
||||||
|
peakShift: null,
|
||||||
|
staffHours: 0,
|
||||||
|
peakFootfall: 0,
|
||||||
|
savedEur: 0,
|
||||||
|
savedPct: 0,
|
||||||
|
coveragePct: 0,
|
||||||
|
overstaffedHours: 0,
|
||||||
|
understaffedHours: 0,
|
||||||
|
days: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let peakHour: StaffingHour | null = null
|
||||||
|
for (const hour of plan.hours) {
|
||||||
|
if (!peakHour || hour.footfall > peakHour.footfall) peakHour = hour
|
||||||
|
}
|
||||||
|
|
||||||
|
let peakShift: Shift | null = null
|
||||||
|
for (const shift of plan.shifts) {
|
||||||
|
if (
|
||||||
|
!peakShift ||
|
||||||
|
shift.staff > peakShift.staff ||
|
||||||
|
(shift.staff === peakShift.staff && shift.date < peakShift.date)
|
||||||
|
) {
|
||||||
|
peakShift = shift
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const staffHours = plan.hours.reduce((sum, hour) => sum + hour.scheduled_staff, 0)
|
||||||
|
const savedEur = Math.max(0, plan.summary.flat_schedule_cost_eur - plan.summary.cost_eur)
|
||||||
|
const days = new Set(plan.hours.map((hour) => berlinParts(hour.t).date)).size
|
||||||
|
|
||||||
|
return {
|
||||||
|
peakHour,
|
||||||
|
peakShift,
|
||||||
|
staffHours,
|
||||||
|
peakFootfall: peakHour?.footfall ?? 0,
|
||||||
|
savedEur,
|
||||||
|
savedPct:
|
||||||
|
plan.summary.flat_schedule_cost_eur > 0
|
||||||
|
? (savedEur / plan.summary.flat_schedule_cost_eur) * 100
|
||||||
|
: 0,
|
||||||
|
coveragePct: plan.summary.coverage_pct,
|
||||||
|
overstaffedHours: plan.summary.overstaffed_hours,
|
||||||
|
understaffedHours: plan.summary.understaffed_hours,
|
||||||
|
days,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function sensorForPlan(
|
||||||
|
sensors: Sensor[] | null | undefined,
|
||||||
|
plan: StaffingResponse | null | undefined,
|
||||||
|
): Sensor | null {
|
||||||
|
return sensors?.find((sensor) => sensor.id === plan?.sensor) ?? null
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
/* PreZero */
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
export interface PrezeroMaterialStats {
|
||||||
|
readings: number
|
||||||
|
overfull: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PrezeroMeta {
|
||||||
|
source: string
|
||||||
|
generated_at: string
|
||||||
|
rows: number
|
||||||
|
containers: number
|
||||||
|
material_series: number
|
||||||
|
date_from: string
|
||||||
|
date_to: string
|
||||||
|
reference_date: string
|
||||||
|
overfull_readings: number
|
||||||
|
priority_rule: string
|
||||||
|
limitations: string[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PrezeroContainerMaterial {
|
||||||
|
readings: number
|
||||||
|
overfull_count: number
|
||||||
|
last_fill: number | null
|
||||||
|
last_is_overfull: boolean
|
||||||
|
last_date: string | null
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PrezeroContainer {
|
||||||
|
location_id: string
|
||||||
|
priority: 'high' | 'medium' | 'low'
|
||||||
|
priority_score: number
|
||||||
|
readings: number
|
||||||
|
overfull_count: number
|
||||||
|
overfull_rate: number
|
||||||
|
p95_fill: number
|
||||||
|
max_fill: number
|
||||||
|
mean_fill: number
|
||||||
|
last_fill: number | null
|
||||||
|
last_is_overfull: boolean
|
||||||
|
last_date: string | null
|
||||||
|
days_since_last: number | null
|
||||||
|
trend: number | null
|
||||||
|
materials: Record<string, PrezeroContainerMaterial>
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PrezeroBundle {
|
||||||
|
meta: PrezeroMeta
|
||||||
|
summary: {
|
||||||
|
priority_counts: { high: number; medium: number; low: number }
|
||||||
|
by_material: Record<string, PrezeroMaterialStats>
|
||||||
|
}
|
||||||
|
top: PrezeroContainer[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export const PRIORITY_ORDER: readonly PrezeroContainer['priority'][] = [
|
||||||
|
'high',
|
||||||
|
'medium',
|
||||||
|
'low',
|
||||||
|
] as const
|
||||||
|
|
||||||
|
export function prezeroTotal(bundle: PrezeroBundle | null | undefined): number {
|
||||||
|
if (!bundle) return 0
|
||||||
|
const counts = bundle.summary.priority_counts
|
||||||
|
return counts.high + counts.medium + counts.low
|
||||||
|
}
|
||||||
|
|
||||||
|
export function priorityShare(bundle: PrezeroBundle | null | undefined, priority: string): number {
|
||||||
|
const total = prezeroTotal(bundle)
|
||||||
|
if (!total || !bundle) return 0
|
||||||
|
return (bundle.summary.priority_counts[priority as 'high' | 'medium' | 'low'] / total) * 100
|
||||||
|
}
|
||||||
|
|
||||||
|
export function shortContainerId(id: string): string {
|
||||||
|
return id.slice(0, 8)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** One-line reason, built only from fields present in the artifact. */
|
||||||
|
export function prezeroReason(container: PrezeroContainer): string {
|
||||||
|
const pct = formatPercent(container.overfull_rate * 100, 0)
|
||||||
|
if (container.overfull_count > 0) {
|
||||||
|
return `${container.overfull_count} overfull ${container.overfull_count === 1 ? 'reading' : 'readings'} (${pct} of visits); p95 fill ${Math.round(container.p95_fill)}%.`
|
||||||
|
}
|
||||||
|
return `${container.readings} readings; p95 fill ${Math.round(container.p95_fill)}%; no overfull state reported.`
|
||||||
|
}
|
||||||
@@ -0,0 +1,272 @@
|
|||||||
|
import { describe, expect, it } from 'vitest'
|
||||||
|
import type { CoolRouteBundle, CoolRouteOption } from '../shared/cool'
|
||||||
|
import {
|
||||||
|
buildGpx,
|
||||||
|
compassDirection,
|
||||||
|
isUseCaseId,
|
||||||
|
prezeroReason,
|
||||||
|
prezeroTotal,
|
||||||
|
priorityShare,
|
||||||
|
routeComparison,
|
||||||
|
routeRationale,
|
||||||
|
routeTitle,
|
||||||
|
routeValuesFor,
|
||||||
|
staffingSnapshot,
|
||||||
|
} from '../shared/use-cases'
|
||||||
|
import type { PrezeroBundle, PrezeroContainer } from '../shared/use-cases'
|
||||||
|
import type { StaffingResponse } from '../shared/types'
|
||||||
|
|
||||||
|
function route(
|
||||||
|
id: CoolRouteOption['id'],
|
||||||
|
durationMin: number,
|
||||||
|
shadePct: number,
|
||||||
|
directSunMin: number,
|
||||||
|
rampInclinePct: number | null,
|
||||||
|
): CoolRouteOption {
|
||||||
|
return {
|
||||||
|
id,
|
||||||
|
label: id,
|
||||||
|
longName: id,
|
||||||
|
description: `${id} description`,
|
||||||
|
fullDescription: `${id} full description`,
|
||||||
|
values: {
|
||||||
|
'16:00': {
|
||||||
|
shadePct,
|
||||||
|
directSunMin,
|
||||||
|
distanceM: 400,
|
||||||
|
durationMin,
|
||||||
|
stepFree: true,
|
||||||
|
waterStops: 2,
|
||||||
|
benchStops: 6,
|
||||||
|
rampInclinePct,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
ramp: rampInclinePct
|
||||||
|
? { incline: `${rampInclinePct}%`, location: 'Marktplatz', wheelchair: 'yes' }
|
||||||
|
: null,
|
||||||
|
accessibilityNotes: [],
|
||||||
|
geometry: [
|
||||||
|
[9.2184, 49.1402],
|
||||||
|
[9.2189, 49.141],
|
||||||
|
[9.2193, 49.1423],
|
||||||
|
],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const bundle: CoolRouteBundle = {
|
||||||
|
status: 'ready',
|
||||||
|
generatedAt: '2026-08-14',
|
||||||
|
hotDay: {
|
||||||
|
date: '2026-08-14',
|
||||||
|
temperature_max_c: 35,
|
||||||
|
temperature_min_c: 18.2,
|
||||||
|
precipitation_mm: 0,
|
||||||
|
sunshine_hours: 13.9,
|
||||||
|
source: 'Open-Meteo',
|
||||||
|
},
|
||||||
|
label: 'modeled day',
|
||||||
|
shadeLabel: 'modeled shade, not measured',
|
||||||
|
origin: { name: 'Stadtgalerie', lat: 49.140269, lon: 9.218444 },
|
||||||
|
destination: { name: 'Marktplatz', lat: 49.142318, lon: 9.218659 },
|
||||||
|
times: ['10:00', '12:00', '14:00', '16:00'],
|
||||||
|
routes: [
|
||||||
|
route('shortest', 4.8, 43.8, 2.7, 15),
|
||||||
|
route('shaded', 9.8, 50, 4.9, 15),
|
||||||
|
route('accessible', 5.8, 43.8, 3.3, null),
|
||||||
|
],
|
||||||
|
recommendationByTime: { '10:00': 'shortest', '12:00': 'shortest', '14:00': 'accessible', '16:00': 'accessible' },
|
||||||
|
modelLabel: 'Accessible for Ruth',
|
||||||
|
water: [],
|
||||||
|
meta: {
|
||||||
|
city: 'Heilbronn',
|
||||||
|
shadeLabel: 'modeled shade, not measured',
|
||||||
|
method: 'test method',
|
||||||
|
solarPositions: {
|
||||||
|
'16:00': { altitude_deg: 43.3, azimuth_deg: 235.1 },
|
||||||
|
},
|
||||||
|
dataGaps: ['test gap'],
|
||||||
|
walkingSpeedMps: 1.25,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const container: PrezeroContainer = {
|
||||||
|
location_id: 'eecbf6fa-decf-46da-b110-bf014e7c181d',
|
||||||
|
priority: 'high',
|
||||||
|
priority_score: 21.5,
|
||||||
|
readings: 80,
|
||||||
|
overfull_count: 21,
|
||||||
|
overfull_rate: 0.2625,
|
||||||
|
p95_fill: 100,
|
||||||
|
max_fill: 100,
|
||||||
|
mean_fill: 64.24,
|
||||||
|
last_fill: null,
|
||||||
|
last_is_overfull: true,
|
||||||
|
last_date: '2026-09-29',
|
||||||
|
days_since_last: 1,
|
||||||
|
trend: 30,
|
||||||
|
materials: {},
|
||||||
|
}
|
||||||
|
|
||||||
|
const prezero: PrezeroBundle = {
|
||||||
|
meta: {
|
||||||
|
source: 'test.csv',
|
||||||
|
generated_at: '2026-11-14T16:53:20Z',
|
||||||
|
rows: 11701,
|
||||||
|
containers: 449,
|
||||||
|
material_series: 1338,
|
||||||
|
date_from: '2025-10-17',
|
||||||
|
date_to: '2026-09-30',
|
||||||
|
reference_date: '2026-09-30',
|
||||||
|
overfull_readings: 1192,
|
||||||
|
priority_rule: 'high ...',
|
||||||
|
limitations: ['No coordinates'],
|
||||||
|
},
|
||||||
|
summary: {
|
||||||
|
priority_counts: { high: 88, medium: 248, low: 113 },
|
||||||
|
by_material: {
|
||||||
|
white: { readings: 4432, overfull: 731 },
|
||||||
|
green: { readings: 4169, overfull: 357 },
|
||||||
|
brown: { readings: 3100, overfull: 104 },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
top: [container],
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('use case ids', () => {
|
||||||
|
it('accepts only the three implemented use cases', () => {
|
||||||
|
expect(isUseCaseId('staffing')).toBe(true)
|
||||||
|
expect(isUseCaseId('routing')).toBe(true)
|
||||||
|
expect(isUseCaseId('prezero')).toBe(true)
|
||||||
|
expect(isUseCaseId('uc4')).toBe(false)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('route comparison', () => {
|
||||||
|
it('uses the model recommendation and real duration penalties', () => {
|
||||||
|
const rows = routeComparison(bundle, '16:00')
|
||||||
|
|
||||||
|
expect(rows.map((row) => row.id)).toEqual(['shortest', 'shaded', 'accessible'])
|
||||||
|
expect(rows.find((row) => row.recommended)?.id).toBe('accessible')
|
||||||
|
expect(rows.find((row) => row.id === 'shaded')?.penaltyMin).toBe(5)
|
||||||
|
expect(rows.find((row) => row.id === 'accessible')?.penaltyMin).toBe(1)
|
||||||
|
expect(rows.find((row) => row.recommended)?.tag).toBe('Recommended')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('returns no rows when the bundle is missing', () => {
|
||||||
|
expect(routeComparison(null, '16:00')).toEqual([])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('keeps the real shade and sun values', () => {
|
||||||
|
expect(routeValuesFor(bundle, 'accessible', '16:00')?.shadePct).toBe(43.8)
|
||||||
|
expect(routeValuesFor(bundle, 'accessible', '16:00')?.rampInclinePct).toBe(null)
|
||||||
|
expect(routeTitle('shaded')).toBe('Shaded route')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('route rationale', () => {
|
||||||
|
it('mentions the actual solar position, shade and the step-free trade-off', () => {
|
||||||
|
const text = routeRationale(bundle, '16:00')
|
||||||
|
|
||||||
|
expect(text).toContain('solar azimuth 235° SW')
|
||||||
|
expect(text).toContain('43.8% shaded')
|
||||||
|
expect(text).toContain('3.3 min of direct sun')
|
||||||
|
expect(text).toContain('step-free with no ramp')
|
||||||
|
expect(text).toContain('1 min longer')
|
||||||
|
expect(text).not.toContain('4.8')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('never invents a route when the bundle is unavailable', () => {
|
||||||
|
expect(routeRationale(null, '16:00')).toContain('unavailable')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('compass and GPX', () => {
|
||||||
|
it('maps solar azimuth to a compass label', () => {
|
||||||
|
expect(compassDirection(0)).toBe('N')
|
||||||
|
expect(compassDirection(110.8)).toBe('E')
|
||||||
|
expect(compassDirection(235.1)).toBe('SW')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('exports the real geometry as GPX 1.1', () => {
|
||||||
|
const xml = buildGpx(bundle, 'accessible', '16:00', '2026-11-14T20:00:00Z')
|
||||||
|
|
||||||
|
expect(xml).toContain('<gpx version="1.1"')
|
||||||
|
expect(xml).toContain('<trkpt lat="49.140200" lon="9.218400" />')
|
||||||
|
expect(xml).toContain('modeled shade, not measured')
|
||||||
|
expect(xml).toContain('<time>2026-11-14T20:00:00Z</time>')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('refuses to export a route without geometry', () => {
|
||||||
|
const empty = { ...bundle, routes: [{ ...bundle.routes[0]!, geometry: [] }] }
|
||||||
|
expect(() => buildGpx(empty, 'shortest', '16:00')).toThrow('No geometry')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('staffing snapshot', () => {
|
||||||
|
const plan: StaffingResponse = {
|
||||||
|
sensor: 'hn-stadtgalerie-01',
|
||||||
|
scenario: 'base',
|
||||||
|
standard: 'standard',
|
||||||
|
assumptions: {
|
||||||
|
visitors_per_staff_hour: 25,
|
||||||
|
safety_factor: 1.15,
|
||||||
|
min_staff: 1,
|
||||||
|
shift_length_h: 4,
|
||||||
|
labor_cost_eur_h: 16,
|
||||||
|
store_hours: { open: '10:00', close: '20:00', tz: 'Europe/Berlin' },
|
||||||
|
},
|
||||||
|
hours: [
|
||||||
|
{ t: '2026-11-16T09:00:00Z', footfall: 10, required_staff: 1, scheduled_staff: 2, coverage: 'over' },
|
||||||
|
{ t: '2026-11-16T10:00:00Z', footfall: 90, required_staff: 5, scheduled_staff: 5, coverage: 'ok' },
|
||||||
|
{ t: '2026-11-16T11:00:00Z', footfall: 50, required_staff: 3, scheduled_staff: 5, coverage: 'over' },
|
||||||
|
],
|
||||||
|
shifts: [
|
||||||
|
{ date: '2026-11-16', start: '10:00', end: '14:00', staff: 5 },
|
||||||
|
{ date: '2026-11-16', start: '14:00', end: '18:00', staff: 4 },
|
||||||
|
],
|
||||||
|
summary: {
|
||||||
|
coverage_pct: 100,
|
||||||
|
cost_eur: 192,
|
||||||
|
flat_schedule_cost_eur: 320,
|
||||||
|
overstaffed_hours: 2,
|
||||||
|
understaffed_hours: 0,
|
||||||
|
},
|
||||||
|
why: ['forecast peak'],
|
||||||
|
cached: false,
|
||||||
|
data_version: 'd',
|
||||||
|
model_version: 'm',
|
||||||
|
context_version: 'c',
|
||||||
|
}
|
||||||
|
|
||||||
|
it('finds the peak hour, peak shift, staff hours and savings', () => {
|
||||||
|
const snapshot = staffingSnapshot(plan)
|
||||||
|
|
||||||
|
expect(snapshot.peakHour?.footfall).toBe(90)
|
||||||
|
expect(snapshot.peakShift?.staff).toBe(5)
|
||||||
|
expect(snapshot.staffHours).toBe(12)
|
||||||
|
expect(snapshot.savedEur).toBe(128)
|
||||||
|
expect(snapshot.savedPct).toBe(40)
|
||||||
|
expect(snapshot.days).toBe(1)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('returns a safe empty snapshot without a plan', () => {
|
||||||
|
const snapshot = staffingSnapshot(null)
|
||||||
|
expect(snapshot.peakHour).toBeNull()
|
||||||
|
expect(snapshot.staffHours).toBe(0)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('prezero helpers', () => {
|
||||||
|
it('counts all locations and their shares', () => {
|
||||||
|
expect(prezeroTotal(prezero)).toBe(449)
|
||||||
|
expect(priorityShare(prezero, 'high')).toBeCloseTo(19.6, 1)
|
||||||
|
expect(prezeroTotal(null)).toBe(0)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('builds a reason from the artifact fields only', () => {
|
||||||
|
const reason = prezeroReason(container)
|
||||||
|
expect(reason).toContain('21 overfull readings')
|
||||||
|
expect(reason).toContain('26% of visits')
|
||||||
|
expect(reason).toContain('p95 fill 100%')
|
||||||
|
})
|
||||||
|
})
|
||||||
Reference in new issue
Block a user