design: give PulseCast a shift-board identity
ci / check (push) Successful in 50s

- replace default Onyx surfaces with paper/ink, signal orange and Archivo
- make /plan answer peak, staff-hours, cost vs flat and coverage above the fold
- add the weekly shift board, shared plan helpers and a pulse line
- rebuild /live as a phone-first dark board and /stage as a full-bleed projector
- label the real 14-20 Nov window; remove 'next week' claims
- keep Onyx components, SSR, live scenario updates and accessible states
This commit is contained in:
Noel Sabia committed 2026-11-14 11:03:18 +01:00
1 parent 66b80a62fb
commit 33063afbdf
18 files changed
+4300 -1452

No files matched your search

+108
View File
@@ -0,0 +1,108 @@
import { berlinParts } from '#shared/staffing'
import type { Point, Shift, StaffingHour, StaffingResponse } from '#shared/types'
import { formatShortDate, formatWeekday, formatWeekdayShort } from '~/utils/format'
export interface PlanDay {
date: string
dayNumber: string
month: string
weekday: string
weekdayLong: string
shifts: Shift[]
hours: StaffingHour[]
staffHours: number
peakStaff: number
peakFootfall: number
peakHour: number
cost: number
overHours: number
underHours: number
}
export function maxOf<T>(items: T[], score: (item: T) => number): T | undefined {
let best: T | undefined
for (const item of items) {
if (!best || score(item) > score(best)) best = item
}
return best
}
export function peakShiftOf(plan: StaffingResponse | null | undefined): Shift | undefined {
return plan ? maxOf(plan.shifts, (shift) => shift.staff) : undefined
}
export function peakHourOf(plan: StaffingResponse | null | undefined): StaffingHour | undefined {
return plan ? maxOf(plan.hours, (hour) => hour.footfall) : undefined
}
export function totalStaffHoursOf(plan: StaffingResponse | null | undefined): number {
return plan ? plan.hours.reduce((sum, hour) => sum + hour.scheduled_staff, 0) : 0
}
export function savingOf(plan: StaffingResponse | null | undefined): number {
if (!plan) return 0
return Math.max(0, plan.summary.flat_schedule_cost_eur - plan.summary.cost_eur)
}
export function savingPctOf(plan: StaffingResponse | null | undefined): number {
if (!plan || plan.summary.flat_schedule_cost_eur <= 0) return 0
return (savingOf(plan) / plan.summary.flat_schedule_cost_eur) * 100
}
export function planDays(plan: StaffingResponse | null | undefined): PlanDay[] {
if (!plan) return []
const shiftsByDate: Record<string, Shift[]> = {}
for (const shift of plan.shifts) (shiftsByDate[shift.date] ??= []).push(shift)
const hoursByDate: Record<string, StaffingHour[]> = {}
for (const hour of plan.hours) {
const date = berlinParts(hour.t).date
;(hoursByDate[date] ??= []).push(hour)
}
const dates = [...new Set([...Object.keys(shiftsByDate), ...Object.keys(hoursByDate)])].sort()
const costPerHour = plan.assumptions.labor_cost_eur_h
return dates.map((date) => {
const shifts = (shiftsByDate[date] ?? []).slice().sort((a, b) => a.start.localeCompare(b.start))
const hours = (hoursByDate[date] ?? []).slice().sort((a, b) => a.t.localeCompare(b.t))
const peakHour = maxOf(hours, (hour) => hour.footfall)
const staffHours = hours.reduce((sum, hour) => sum + hour.scheduled_staff, 0)
const [dayNumber = '', month = ''] = formatShortDate(date).split(' ')
return {
date,
dayNumber,
month,
weekday: formatWeekdayShort(date),
weekdayLong: formatWeekday(date),
shifts,
hours,
staffHours,
peakStaff: Math.max(0, ...hours.map((hour) => hour.scheduled_staff), ...shifts.map((shift) => shift.staff)),
peakFootfall: peakHour?.footfall ?? 0,
peakHour: peakHour ? berlinParts(peakHour.t).hour : 0,
cost: staffHours * costPerHour,
overHours: hours.filter((hour) => hour.coverage === 'over').length,
underHours: hours.filter((hour) => hour.coverage === 'under').length,
}
})
}
export function planPulsePoints(plan: StaffingResponse | null | undefined): Point[] {
return (plan?.hours ?? []).map((hour) => ({ t: hour.t, v: hour.footfall }))
}
export function numberWord(value: number): string {
const words = ['Zero', 'One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten']
return words[value] ?? String(value)
}
export function shiftLabel(shift: Shift): string {
return `${shift.start}–${shift.end}`
}
export function coverWord(value: number, singular: string, plural = `${singular}s`): string {
return `${value} ${value === 1 ? singular : plural}`
}