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,3 @@
|
||||
import { mockContext } from '../utils/mock-data'
|
||||
|
||||
export default defineEventHandler(() => mockContext)
|
||||
@@ -0,0 +1,34 @@
|
||||
import { applyScenario } from '../../shared/staffing'
|
||||
import { HORIZONS, SCENARIOS } from '../../shared/types'
|
||||
import type { Horizon, Scenario } from '../../shared/types'
|
||||
import { getMockForecast } from '../utils/mock-data'
|
||||
|
||||
export default defineEventHandler((event) => {
|
||||
const query = getQuery(event)
|
||||
const sensor = String(query.sensor ?? 'hn-stadtgalerie-01')
|
||||
const horizon = String(query.horizon ?? '7d') as Horizon
|
||||
const scenario = String(query.scenario ?? 'base') as Scenario
|
||||
const forecast = getMockForecast(sensor)
|
||||
|
||||
if (!forecast) {
|
||||
throw createError({ statusCode: 404, statusMessage: `Unknown sensor: ${sensor}` })
|
||||
}
|
||||
if (!HORIZONS.includes(horizon)) {
|
||||
throw createError({ statusCode: 400, statusMessage: `Invalid horizon: ${horizon}` })
|
||||
}
|
||||
if (!SCENARIOS.includes(scenario)) {
|
||||
throw createError({ statusCode: 400, statusMessage: `Invalid scenario: ${scenario}` })
|
||||
}
|
||||
|
||||
const points = applyScenario(forecast.points, scenario)
|
||||
const limit = horizon === '15m' ? 1 : horizon === '1h' ? 4 : horizon === '48h' ? 48 : points.length
|
||||
|
||||
return {
|
||||
...forecast,
|
||||
horizon,
|
||||
scenario,
|
||||
points: points.slice(0, limit),
|
||||
// The mock is computed locally; it is not a cached fallback from the Go API.
|
||||
cached: false,
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1 @@
|
||||
export default defineEventHandler(() => ({ ok: true }))
|
||||
@@ -0,0 +1,3 @@
|
||||
import { mockMeta } from '../utils/mock-data'
|
||||
|
||||
export default defineEventHandler(() => mockMeta)
|
||||
@@ -0,0 +1 @@
|
||||
export default defineEventHandler(() => ({ ok: true, data: true, model: true }))
|
||||
@@ -0,0 +1,3 @@
|
||||
import { mockScenario } from '../utils/mock-data'
|
||||
|
||||
export default defineEventHandler(() => mockScenario)
|
||||
@@ -0,0 +1,22 @@
|
||||
import { SCENARIOS } from '../../shared/types'
|
||||
import type { Scenario, ScenarioDefinition } from '../../shared/types'
|
||||
import { mockScenario } from '../utils/mock-data'
|
||||
|
||||
let version = mockScenario.version
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const body = await readBody<ScenarioDefinition>(event)
|
||||
const scenario = body?.scenario
|
||||
if (!scenario || !SCENARIOS.includes(scenario as Scenario)) {
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: 'Invalid scenario. Expected base | sunny-saturday-market | rainy-saturday | weekday-event.',
|
||||
})
|
||||
}
|
||||
version += 1
|
||||
return {
|
||||
version,
|
||||
scenario: body,
|
||||
at: new Date().toISOString(),
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,3 @@
|
||||
import { mockScenarios } from '../utils/mock-data'
|
||||
|
||||
export default defineEventHandler(() => mockScenarios)
|
||||
@@ -0,0 +1,3 @@
|
||||
import { mockSensors } from '../utils/mock-data'
|
||||
|
||||
export default defineEventHandler(() => mockSensors)
|
||||
@@ -0,0 +1,12 @@
|
||||
import { getMockSeries } from '../utils/mock-data'
|
||||
|
||||
export default defineEventHandler((event) => {
|
||||
const query = getQuery(event)
|
||||
const sensor = String(query.sensor ?? 'hn-stadtgalerie-01')
|
||||
const series = getMockSeries(sensor)
|
||||
if (!series) {
|
||||
throw createError({ statusCode: 404, statusMessage: `Unknown sensor: ${sensor}` })
|
||||
}
|
||||
const step = query.step === '15m' ? '15m' : '1h'
|
||||
return { ...series, step }
|
||||
})
|
||||
@@ -0,0 +1,37 @@
|
||||
import { applyScenario, buildStaffing, planWeekStart } from '../../shared/staffing'
|
||||
import { planDrivers } from '../../shared/insights'
|
||||
import { SCENARIOS, STANDARDS } from '../../shared/types'
|
||||
import type { Scenario, Standard } from '../../shared/types'
|
||||
import { getMockForecast, mockContext, mockDemo } from '../utils/mock-data'
|
||||
|
||||
export default defineEventHandler((event) => {
|
||||
const query = getQuery(event)
|
||||
const sensor = String(query.sensor ?? 'hn-stadtgalerie-01')
|
||||
const scenario = String(query.scenario ?? 'base') as Scenario
|
||||
const standard = String(query.standard ?? 'standard') as Standard
|
||||
const forecast = getMockForecast(sensor)
|
||||
|
||||
if (!forecast) {
|
||||
throw createError({ statusCode: 404, statusMessage: `Unknown sensor: ${sensor}` })
|
||||
}
|
||||
if (!SCENARIOS.includes(scenario)) {
|
||||
throw createError({ statusCode: 400, statusMessage: `Invalid scenario: ${scenario}` })
|
||||
}
|
||||
if (!STANDARDS.includes(standard)) {
|
||||
throw createError({ statusCode: 400, statusMessage: `Invalid standard: ${standard}` })
|
||||
}
|
||||
|
||||
const weekStart = planWeekStart(mockDemo.now)
|
||||
const build = buildStaffing({
|
||||
sensor,
|
||||
scenario,
|
||||
standard,
|
||||
points: applyScenario(forecast.points, scenario),
|
||||
weekStart,
|
||||
data_version: forecast.data_version,
|
||||
model_version: forecast.model_version,
|
||||
context_version: forecast.context_version,
|
||||
})
|
||||
build.response.why = planDrivers(build.response, mockContext, weekStart, scenario)
|
||||
return build.response
|
||||
})
|
||||
@@ -0,0 +1,34 @@
|
||||
import { createMockTrainJob } from '../utils/train-jobs'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
let model: 'small' | 'forecast' = 'small'
|
||||
let filename: string | null = null
|
||||
|
||||
const contentType = getRequestHeader(event, 'content-type') ?? ''
|
||||
if (contentType.includes('multipart/form-data')) {
|
||||
const parts = await readMultipartFormData(event)
|
||||
for (const part of parts ?? []) {
|
||||
if (part.name === 'model' && part.data) {
|
||||
const value = part.data.toString()
|
||||
if (value === 'small' || value === 'forecast') model = value
|
||||
}
|
||||
if (part.name === 'file' && part.filename) {
|
||||
filename = part.filename
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const body = await readBody<{ model?: 'small' | 'forecast'; path?: string }>(event).catch(() => null)
|
||||
if (body?.model === 'small' || body?.model === 'forecast') model = body.model
|
||||
if (body?.path) filename = body.path
|
||||
}
|
||||
|
||||
const job = createMockTrainJob(model, filename)
|
||||
setResponseStatus(event, 202)
|
||||
return {
|
||||
job_id: job.job_id,
|
||||
status: job.status,
|
||||
model: job.model,
|
||||
submitted_at: job.started_at,
|
||||
mock: true,
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,10 @@
|
||||
import { getMockTrainJob } from '../../utils/train-jobs'
|
||||
|
||||
export default defineEventHandler((event) => {
|
||||
const jobId = getRouterParam(event, 'jobId')
|
||||
const job = jobId ? getMockTrainJob(jobId) : undefined
|
||||
if (!job) {
|
||||
throw createError({ statusCode: 404, statusMessage: `Unknown training job: ${jobId}` })
|
||||
}
|
||||
return job
|
||||
})
|
||||
Reference in new issue
Block a user