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

+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>