398 lines
19 KiB
Vue
398 lines
19 KiB
Vue
<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>
|