feat: build Onyx SSR shell and plan hero with mock data

This commit is contained in:
Noel Sabia committed 2026-11-14 05:17:36 +01:00
1 parent 84c20992f9
commit 2db494fb10
34 files changed
+3197 -2

No files matched your search

+33
View File
@@ -0,0 +1,33 @@
<script setup lang="ts">
withDefaults(
defineProps<{
label: string
value: string
hint?: string
badge?: string
badgeColor?: 'neutral' | 'danger' | 'success' | 'primary' | 'warning' | 'info'
icon?: string
}>(),
{ badgeColor: 'neutral' },
)
</script>
<template>
<OnyxCard class="stat-card">
<p class="stat-label">
<OnyxIcon v-if="icon" :icon="icon" size="16px" color="primary" />
{{ label }}
</p>
<p class="stat-value">{{ value }}</p>
<OnyxBadge v-if="badge" :color="badgeColor" density="compact">{{ badge }}</OnyxBadge>
<p v-if="hint" class="stat-hint">{{ hint }}</p>
</OnyxCard>
</template>
<style scoped>
.stat-label {
display: flex;
align-items: center;
gap: 0.35rem;
}
</style>
+57
View File
@@ -0,0 +1,57 @@
<script setup lang="ts">
import type { Sensor } from '#shared/types'
const props = defineProps<{
sensors: Sensor[]
activeId: string
}>()
const emit = defineEmits<{
select: [sensorId: string]
}>()
const bounds = computed(() => {
const lats = props.sensors.map((sensor) => sensor.lat)
const lons = props.sensors.map((sensor) => sensor.lon)
const pad = 0.0009
return {
minLat: Math.min(...lats) - pad,
maxLat: Math.max(...lats) + pad,
minLon: Math.min(...lons) - pad,
maxLon: Math.max(...lons) + pad,
}
})
function position(sensor: Sensor) {
const { minLat, maxLat, minLon, maxLon } = bounds.value
const x = ((sensor.lon - minLon) / (maxLon - minLon)) * 76 + 12
const y = ((maxLat - sensor.lat) / (maxLat - minLat)) * 52 + 30
return { left: `${x}%`, top: `${y}%` }
}
</script>
<template>
<div class="map-frame" role="group" aria-label="Schematic map of the eight Heilbronn sensors">
<div class="map-frame__label">
<OnyxBadge color="info" density="compact">Schematic</OnyxBadge>
<p class="small muted" style="margin: 0.35rem 0 0">
Relative sensor positions in the 580 m cluster. Not a city-wide heatmap.
</p>
</div>
<button
v-for="(sensor, index) in props.sensors"
:key="sensor.id"
type="button"
class="sensor-pin"
:class="{ 'sensor-pin--active': sensor.id === props.activeId }"
:style="position(sensor)"
:aria-label="`${sensor.name}: mean ${sensor.mean}, p95 ${sensor.p95}`"
:aria-pressed="sensor.id === props.activeId"
@click="emit('select', sensor.id)"
>
<span class="sensor-pin__dot">{{ index + 1 }}</span>
<span class="sensor-pin__name">{{ sensor.name }}</span>
</button>
</div>
</template>
+151
View File
@@ -0,0 +1,151 @@
<script setup lang="ts">
import { iconUpload } from '@sit-onyx/icons'
interface TrainResponse {
job_id: string
status: string
model: 'small' | 'forecast'
submitted_at: string
mock?: boolean
}
interface TrainJob {
job_id: string
status: 'queued' | 'running' | 'succeeded' | 'failed'
model: 'small' | 'forecast'
metrics: Record<string, number | string> | null
model_version: string | null
error: string | null
}
const file = ref<File | null>(null)
const model = ref<'small' | 'forecast'>('small')
const submitting = ref(false)
const polling = ref(false)
const job = ref<TrainJob | null>(null)
const errorMessage = ref('')
let pollTimer: ReturnType<typeof setInterval> | undefined
const modelOptions = [
{ label: 'Small busy classifier (fast demo)', value: 'small' },
{ label: 'Global forecast model (slower)', value: 'forecast' },
]
const statusColor = computed(() => {
switch (job.value?.status) {
case 'succeeded':
return 'success' as const
case 'failed':
return 'danger' as const
case 'running':
return 'info' as const
default:
return 'neutral' as const
}
})
async function poll(jobId: string) {
polling.value = true
let attempts = 0
pollTimer = setInterval(async () => {
attempts += 1
try {
const result = await $fetch<TrainJob>(`/api/train/${jobId}`)
job.value = result
if (result.status === 'succeeded' || result.status === 'failed') {
clearInterval(pollTimer)
polling.value = false
}
} catch {
if (attempts >= 12) {
clearInterval(pollTimer)
polling.value = false
errorMessage.value = 'Could not read the mock training job status.'
}
}
}, 700)
}
async function submit() {
errorMessage.value = ''
job.value = null
submitting.value = true
try {
const formData = new FormData()
formData.append('model', model.value)
if (file.value) formData.append('file', file.value)
const response = await $fetch<TrainResponse>('/api/train', { method: 'POST', body: formData })
await poll(response.job_id)
} catch {
errorMessage.value = 'Training submission failed. The mock endpoint expects a CSV or model selection.'
} finally {
submitting.value = false
}
}
onBeforeUnmount(() => {
if (pollTimer) clearInterval(pollTimer)
})
</script>
<template>
<OnyxCard>
<div class="card-header">
<OnyxHeadline is="h3">Train new data</OnyxHeadline>
<OnyxBadge color="warning" density="compact">P1 mock</OnyxBadge>
</div>
<p class="small muted" style="margin-top: 0">
Posts to the mock <code>/api/train</code> contract. Replace the Nitro route with the Go endpoint when it
exists; the form shape stays the same.
</p>
<form class="form-grid" @submit.prevent="submit">
<OnyxFileUpload
v-model="file"
label="Training CSV"
message="Optional in the mock."
:accept="['text/csv']"
max-size="50MiB"
/>
<p class="small muted" style="margin: 0">The real endpoint expects the challenge CSV schema.</p>
<OnyxSelect
v-model="model"
label="Model"
list-label="Available models"
:options="modelOptions"
/>
<div class="form-actions">
<OnyxButton
type="submit"
label="Start training"
:icon="iconUpload"
:loading="submitting || polling"
/>
<span v-if="submitting" class="small muted">Submitting…</span>
</div>
</form>
<p v-if="errorMessage" class="small" style="color: var(--onyx-color-text-icons-danger-intense)">
{{ errorMessage }}
</p>
<div v-if="job" class="train-status">
<OnyxBadge :color="statusColor">{{ job.status }}</OnyxBadge>
<span class="small muted">Job {{ job.job_id }} · {{ job.model }}</span>
<OnyxBadge v-if="job.model_version" color="neutral" density="compact">
{{ job.model_version }}
</OnyxBadge>
</div>
<dl v-if="job?.metrics" class="metric-list" style="margin-top: var(--onyx-density-md)">
<div v-for="(value, key) in job.metrics" :key="key">
<dt>{{ key }}</dt>
<dd>{{ value }}</dd>
</div>
</dl>
<p v-if="job?.error" class="small" style="color: var(--onyx-color-text-icons-danger-intense)">
{{ job.error }}
</p>
</OnyxCard>
</template>
+25
View File
@@ -0,0 +1,25 @@
<script setup lang="ts">
import { iconCloud, iconSunny } from '@sit-onyx/icons'
import type { DailyWeather } from '#shared/insights'
import { formatShortDate, formatWeekdayShort } from '~/utils/format'
const props = defineProps<{
days: DailyWeather[]
}>()
function iconFor(kind: DailyWeather['kind']) {
return kind === 'sunny' || kind === 'partly-cloudy' ? iconSunny : iconCloud
}
</script>
<template>
<div class="weather-strip" role="list" aria-label="Weather forecast for the plan week">
<div v-for="day in props.days" :key="day.date" class="weather-day" role="listitem">
<strong>{{ formatWeekdayShort(day.date) }} {{ formatShortDate(day.date) }}</strong>
<OnyxIcon :icon="iconFor(day.kind)" size="24px" color="primary" />
<span>{{ Math.round(day.tempMin) }}–{{ Math.round(day.tempMax) }} °C</span>
<span class="muted">{{ day.precipMm.toFixed(1) }} mm</span>
<span class="muted">{{ Math.round(day.cloudPct) }}% cloud</span>
</div>
</div>
</template>