Files
web-nuxt/server/utils/train-jobs.ts
T

48 lines
1.4 KiB
TypeScript

import { mockMeta } from './mock-data'
export interface MockTrainJob {
job_id: string
status: 'queued' | 'running' | 'succeeded' | 'failed'
model: 'small' | 'forecast'
started_at: string
finished_at: string | null
metrics: Record<string, number | string> | null
model_version: string | null
error: string | null
filename: string | null
}
const jobs = new Map<string, MockTrainJob>()
export function createMockTrainJob(model: 'small' | 'forecast', filename: string | null): MockTrainJob {
const now = new Date().toISOString()
const job: MockTrainJob = {
job_id: `mock-${Date.now().toString(36)}`,
// The mock completes immediately. Replace this with polling of GET /api/train/{job_id}
// once the Go/FastAPI service exists.
status: 'succeeded',
model,
started_at: now,
finished_at: now,
metrics:
model === 'small'
? { accuracy: 0.84, f1: 0.81, trained_rows: 12480, kind: 'busy classifier' }
: {
mae: mockMeta.metrics.mae,
wape: mockMeta.metrics.wape,
r2: mockMeta.metrics.r2,
baseline_wape: mockMeta.metrics.baseline_wape,
kind: 'global HistGB',
},
model_version: `${mockMeta.model_version}-mock-${Date.now().toString(36)}`,
error: null,
filename,
}
jobs.set(job.job_id, job)
return job
}
export function getMockTrainJob(jobId: string): MockTrainJob | undefined {
return jobs.get(jobId)
}