- Replace mock Nitro routes with server-side proxies to the Go API - /plan reads Go /api/staffing; local assumption edits are a labeled preview - /simulate reads base and scenario staffing from Go instead of local multipliers - Route train upload and scenario POST through Nitro with server-only credentials - Keep NUXT_PUBLIC_USE_MOCK=1 as an explicit dev fallback only - Match Go's global-peak flat schedule and add a captured Go parity fixture - Run the web runtime as numeric UID/GID 10001:10001 - Add make check, Gitea CI workflow and a proxy smoke script
169 lines
4.7 KiB
Vue
169 lines
4.7 KiB
Vue
<script setup lang="ts">
|
|
import { iconUpload } from '@sit-onyx/icons'
|
|
|
|
interface TrainResponse {
|
|
job_id: string
|
|
status: string
|
|
model: 'small' | 'forecast'
|
|
submitted_at: string
|
|
}
|
|
|
|
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
|
|
}
|
|
})
|
|
|
|
function apiErrorMessage(error: unknown, fallback: string): string {
|
|
const data = (
|
|
error as {
|
|
data?: { error?: { message?: string }; message?: string; statusMessage?: string }
|
|
}
|
|
)?.data
|
|
return data?.error?.message ?? data?.message ?? data?.statusMessage ?? fallback
|
|
}
|
|
|
|
function stopPolling() {
|
|
if (pollTimer) clearInterval(pollTimer)
|
|
pollTimer = undefined
|
|
polling.value = false
|
|
}
|
|
|
|
async function poll(jobId: string) {
|
|
stopPolling()
|
|
polling.value = true
|
|
let attempts = 0
|
|
pollTimer = setInterval(async () => {
|
|
attempts += 1
|
|
try {
|
|
const result = await $fetch<TrainJob>(`/api/train/${encodeURIComponent(jobId)}`)
|
|
job.value = result
|
|
if (result.status === 'succeeded' || result.status === 'failed') stopPolling()
|
|
} catch (error) {
|
|
if (attempts >= 30) {
|
|
stopPolling()
|
|
errorMessage.value = apiErrorMessage(error, 'Could not read the training job status.')
|
|
}
|
|
}
|
|
}, 1000)
|
|
}
|
|
|
|
async function submit() {
|
|
errorMessage.value = ''
|
|
job.value = null
|
|
if (!file.value) {
|
|
errorMessage.value = 'Choose a CSV file first.'
|
|
return
|
|
}
|
|
|
|
submitting.value = true
|
|
try {
|
|
const formData = new FormData()
|
|
formData.append('model', model.value)
|
|
formData.append('file', file.value)
|
|
const response = await $fetch<TrainResponse>('/api/train', { method: 'POST', body: formData })
|
|
await poll(response.job_id)
|
|
} catch (error) {
|
|
errorMessage.value = apiErrorMessage(
|
|
error,
|
|
'Training submission failed. Check the Go API and its FastAPI training upstream.',
|
|
)
|
|
} finally {
|
|
submitting.value = false
|
|
}
|
|
}
|
|
|
|
onBeforeUnmount(stopPolling)
|
|
</script>
|
|
|
|
<template>
|
|
<OnyxCard>
|
|
<div class="card-header">
|
|
<OnyxHeadline is="h3">Train new data</OnyxHeadline>
|
|
<OnyxBadge color="info" density="compact">Server proxy</OnyxBadge>
|
|
</div>
|
|
<p class="small muted" style="margin-top: 0">
|
|
Uploads through Nitro to Go <code>/api/train</code>. The control credentials stay in the Node process and are
|
|
never sent to the browser.
|
|
</p>
|
|
|
|
<form class="form-grid" @submit.prevent="submit">
|
|
<OnyxFileUpload
|
|
v-model="file"
|
|
label="Training CSV"
|
|
message="Challenge CSV schema. Required."
|
|
:accept="['text/csv']"
|
|
max-size="50MiB"
|
|
/>
|
|
<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>
|
|
<span v-else-if="polling" class="small muted">Training job running…</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>
|