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

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

No files matched your search

@@ -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>
+34
View File
@@ -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>
+397
View File
@@ -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>
+362
View File
@@ -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>
+387
View File
@@ -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>
+428
View File
@@ -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>
+58
View File
@@ -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>