---
id: 019cb9fd-1497-75ff-a497-3515bc4c5895
name: Prep Time Monitor
kind: Anomaly
cron: 0 0 * * * *
analysis_window: 1h
comparison_periods: [1d, 7d]
---

Analyze order preparation time anomalies using the `curated.kitchen_orders` table.

## Known Table Columns

- `preparation_time` (int, seconds, nullable) - how long the order took to prepare
- `create_time` (int, unix timestamp) - when the order was created
- `store_guid` (varchar) - which store/restaurant
- `items_count` (int) - number of items in the order
- `order_type` (varchar) - type of order (dine-in, takeout, delivery)
- `destination` (varchar) - kitchen station
- `done` (tinyint) - whether the order is complete
- `is_deleted` (tinyint) - soft delete flag

## Analysis Approach

1. Query the last {AnalysisWindow} of completed orders (`done=1`, `is_deleted=0`, `preparation_time IS NOT NULL`).
2. Verify that the analysis window contains at least **20 completed orders**. If not, call `emit_no_anomaly` — the sample is too small for reliable analysis.
3. Aggregate by hour to get hourly average prep times.
4. Compare against the historical baseline (same hour of day {ComparisonPeriods}).
5. Flag hours where the average prep time deviates significantly (>3 standard deviations) AND the absolute deviation is at least **60 seconds** above the baseline average.
6. Optionally break down by `order_type` or `destination` to find more specific patterns.

## Severity Guidance

- **Low**: 3-4 sigma deviation AND at least 60s absolute increase
- **Medium**: 4-5 sigma deviation AND at least 120s absolute increase, sustained across 2+ consecutive hours
- **High**: >5 sigma deviation AND at least 180s absolute increase
