Optimization Data API
Labor optimization metrics and goals for schedule planning
Returns weekly optimization data including sales, labor costs, and goal progress. Used for labor variance checking and schedule optimization.
GET /api/analytics/optimization
GET /api/analytics/goals
| Parameter | Type | Required | Description |
|---|
teamId | string | ✅ | Team/organization identifier |
weekOf | string | ✅ | ISO date of Saturday starting the week |
locationId | string | ❌ | Optional location filter |
{
weekLabel: string;
summary: {
totalSales: number; // finite, nonnegative
totalLaborCost: number; // finite, nonnegative
laborPct: number; // finite
targetLaborPct?: number; // finite
splh: number; // finite
targetSplh?: number; // finite
};
salesByCategory?: Array<{ // defaults to [] if not provided
day: string;
block: string;
food: number;
{
goals: Array<{
dayOfWeek: number; // integer 0-6 (0 = Saturday)
salesGoal: number; // finite, nonnegative
laborPctTarget: number; // finite, nonnegative
splhTarget: number
curl -X GET "https://analytics.example.com/api/analytics/optimization?teamId=team123&weekOf=2026-05-16&locationId=loc456" \
-H "Authorization: Bearer YOUR_API_KEY"
{
"weekLabel": "May 11-17, 2026",
"summary": {
"totalSales": 45230.00,
"totalLaborCost": 12500.00,
"laborPct": 27.6,
"splh": 142.50
},
"salesByCategory": [
{
"day": "Monday",
"block":
{
"goals": [
{
"dayOfWeek": 0,
"salesGoal": 5000.00,
"laborPctTarget": 28.0,
"splhTarget": 135.00
}
]
}
- Redis cache: 15 minutes
- Reconfiguration: On webhook events or scheduled sync
import { getOptimizationData, getGoalsFromApi } from '@repo/analytics/labor-client';
// Get weekly optimization data
const optimization = await getOptimizationData({
teamId: 'team123',
weekOf: '2026-05-16',
locationId: 'loc456'
});
| Status | Description |
|---|
401 | Missing or invalid API key |
400 | Invalid query parameters |
503 | Circuit breaker open |
| File | Purpose |
|---|
packages/analytics/labor-client.ts | Client implementation with Zod schemas |
packages/analytics/labor-variance.ts | Labor variance checking logic |
// finite, nonnegative
beverage: number; // finite, nonnegative
other: number; // finite, nonnegative
total: number; // finite, nonnegative
}>;
laborByCategory?: Array<{ // defaults to [] if not provided
day: string;
fohHours: number; // finite, nonnegative
bohHours: number; // finite, nonnegative
naHours: number; // finite, nonnegative
totalHours: number; // finite, nonnegative
cost: number; // finite, nonnegative
pctOfSales: number; // finite
}>;
dailySummary?: Array<{ // defaults to [] if not provided
day: string;
sales: number; // finite, nonnegative
laborCost: number; // finite, nonnegative
laborPct: number; // finite
splh: number; // finite
servedGuests?: number; // integer, nonnegative
goalsMet?: boolean;
}>;
weeklySummary?: { // optional
totalSales: number; // finite, nonnegative
totalLaborCost: number; // finite, nonnegative
avgLaborPct: number; // finite
avgSplh: number; // finite
goalsMetPercent?: number;
topDay?: string;
worstDay?: string;
};
}
;
// finite, nonnegative
}>;
}
"Dinner"
,
"food": 2500.00,
"beverage": 1200.00,
"other": 300.00,
"total": 4000.00
}
],
"laborByCategory": [
{
"day": "Monday",
"fohHours": 32.5,
"bohHours": 28.0,
"naHours": 4.0,
"totalHours": 64.5,
"cost": 1800.00,
"pctOfSales": 26.5
}
],
"dailySummary": [
{
"day": "Monday",
"sales": 6500.00,
"laborCost": 1800.00,
"laborPct": 27.7,
"splh": 140.00,
"goalsMet": true
}
],
"weeklySummary": {
"totalSales": 45230.00,
"totalLaborCost": 12500.00,
"avgLaborPct": 27.6,
"avgSplh": 142.50,
"goalsMetPercent": 71.4,
"topDay": "Saturday",
"worstDay": "Tuesday"
}
}
// Get optimization goals
const goals = await getGoalsFromApi({
teamId: 'team123',
locationId: 'loc456'
});