feat: build Onyx SSR shell and plan hero with mock data
This commit is contained in:
1 parent
84c20992f9
commit
2db494fb10
34 files changed
+3197
-2
No files matched your search
@@ -0,0 +1,79 @@
|
||||
// Server-side mock dataset. Shapes follow /home/noel/Documents/Hackathon_2026/CONTRACT.md.
|
||||
// The files are imported (not read from disk at runtime) so the Nitro build bundles them
|
||||
// into the SSR output and the app renders before the Go API exists.
|
||||
import context from '../../mock/context.json'
|
||||
import demo from '../../mock/demo.json'
|
||||
import meta from '../../mock/meta.json'
|
||||
import scenario from '../../mock/scenario.json'
|
||||
import scenarios from '../../mock/scenarios.json'
|
||||
import sensors from '../../mock/sensors.json'
|
||||
|
||||
import forecast01 from '../../mock/forecast/hn-stadtgalerie-01.json'
|
||||
import forecast02 from '../../mock/forecast/hn-kaiserstrasse-02.json'
|
||||
import forecast03 from '../../mock/forecast/hn-marktplatz-03.json'
|
||||
import forecast04 from '../../mock/forecast/hn-kilianskirche-04.json'
|
||||
import forecast05 from '../../mock/forecast/hn-rathaus-05.json'
|
||||
import forecast06 from '../../mock/forecast/hn-neckartor-06.json'
|
||||
import forecast07 from '../../mock/forecast/hn-suelmerstrasse-07.json'
|
||||
import forecast08 from '../../mock/forecast/hn-harmonie-08.json'
|
||||
|
||||
import series01 from '../../mock/series/hn-stadtgalerie-01.json'
|
||||
import series02 from '../../mock/series/hn-kaiserstrasse-02.json'
|
||||
import series03 from '../../mock/series/hn-marktplatz-03.json'
|
||||
import series04 from '../../mock/series/hn-kilianskirche-04.json'
|
||||
import series05 from '../../mock/series/hn-rathaus-05.json'
|
||||
import series06 from '../../mock/series/hn-neckartor-06.json'
|
||||
import series07 from '../../mock/series/hn-suelmerstrasse-07.json'
|
||||
import series08 from '../../mock/series/hn-harmonie-08.json'
|
||||
|
||||
import type {
|
||||
ContextResponse,
|
||||
ForecastResponse,
|
||||
MetaResponse,
|
||||
ScenarioPreset,
|
||||
ScenarioState,
|
||||
Sensor,
|
||||
SeriesResponse,
|
||||
} from '../../shared/types'
|
||||
|
||||
export const mockMeta = meta as MetaResponse
|
||||
export const mockContext = context as ContextResponse
|
||||
export const mockSensors = sensors as Sensor[]
|
||||
export const mockScenarios = scenarios as ScenarioPreset[]
|
||||
export const mockScenario = scenario as ScenarioState
|
||||
export const mockDemo = demo as {
|
||||
now: string
|
||||
plan_start: string
|
||||
plan_end: string
|
||||
timezone: string
|
||||
}
|
||||
|
||||
const forecasts: Record<string, ForecastResponse> = {
|
||||
'hn-stadtgalerie-01': forecast01,
|
||||
'hn-kaiserstrasse-02': forecast02,
|
||||
'hn-marktplatz-03': forecast03,
|
||||
'hn-kilianskirche-04': forecast04,
|
||||
'hn-rathaus-05': forecast05,
|
||||
'hn-neckartor-06': forecast06,
|
||||
'hn-suelmerstrasse-07': forecast07,
|
||||
'hn-harmonie-08': forecast08,
|
||||
} as Record<string, ForecastResponse>
|
||||
|
||||
const series: Record<string, SeriesResponse> = {
|
||||
'hn-stadtgalerie-01': series01,
|
||||
'hn-kaiserstrasse-02': series02,
|
||||
'hn-marktplatz-03': series03,
|
||||
'hn-kilianskirche-04': series04,
|
||||
'hn-rathaus-05': series05,
|
||||
'hn-neckartor-06': series06,
|
||||
'hn-suelmerstrasse-07': series07,
|
||||
'hn-harmonie-08': series08,
|
||||
} as Record<string, SeriesResponse>
|
||||
|
||||
export function getMockForecast(sensorId: string): ForecastResponse | undefined {
|
||||
return forecasts[sensorId]
|
||||
}
|
||||
|
||||
export function getMockSeries(sensorId: string): SeriesResponse | undefined {
|
||||
return series[sensorId]
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
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)
|
||||
}
|
||||
Reference in new issue
Block a user