Chapter 3 — Demand & Lead Time¶
3.1 — Chapter summary¶
Two analyses of actuals, kept together deliberately. Demand analysis turns raw
order lines into the planning-grade demand signal: demand at two grains (order level → weekly aggregation with
the is_open partition), data shaping (zero-fill, min-observations, horizon limits), route-native
coverage (the Demand-map editor writes real TRANSFER lanes) and the time-phased quota/coverage change points.
Lead-time analysis mines observed history into per-lane statistics: movement history
→ lane LT stats, receipt history → supplier lead times, statistical route materialization, and the
planner's per-lane overrides.
Pipeline steps involved: demand-aggregation (formerly etl — renamed end-to-end Nov 2026)
and lead-time (before lt-distribution). Everything here is
master.*/history-table-level analysis — shared across pipelines; the per-pipeline planning
consumption happens downstream (Points 5–7).
3.2 — Demand at two grains: order level → weekly aggregation, with the is_open partition¶
⚙ Process: the Demand aggregation pipeline step (step id
demand-aggregation— renamed frometlend-to-end in Nov 2026 so that only ONE thing is called ETL: the Stage process) derives the weekly aggregation from the order level. The order level itself is written by the import (Point 2'sdemand_actualsstep). How to run it: the full pipeline run (ProcessRunner ▶ — it is the chain's first step) or the Demand aggregation card's own Run. Its configuration lives on the same card's Configure button (3.3). Changing the zero-fill or min-observations settings requires re-running this step to take effect.
The two processes graphically — input → process → output (Stage is Point 1; the import between them is Point 2; Demand aggregation is this chapter):
flowchart LR
subgraph STAGE["STAGE — the ETL (Point 1)"]
direction LR
A["INPUT<br/>customer source data<br/>(per-customer extract)"] --> B["PROCESS<br/>per-customer extraction into staging<br/>one registered variant per tenant:<br/>csv_directory · flow_history_source<br/>customer_db_source · customer_erp_source"]
B --> C["OUTPUT<br/>import.* staging"]
end
subgraph DA["DEMAND AGGREGATION (3.2)"]
direction LR
E["INPUT<br/>master.demand_orders<br/>order level"] --> F["PROCESS<br/>the single standard weekly derivation<br/>no customer variants — ever"]
F --> G["OUTPUT<br/>master.demand_actuals<br/>weekly — shared across pipelines"]
end
C --> D["IMPORT (Point 2)<br/>staging → core"]
D --> E
classDef io fill:#e7f6f0,stroke:#10b981,color:#1b4332;
classDef proc fill:#eef2ff,stroke:#6366f1,color:#312e81;
class A,C,E,G io;
class B,D,F proc;
Two shapes of the same demand, one derived from the other:
The order level — the order lines exactly as the customer's system produced them
(master.demand_orders, one row per order line, business key (order_id, line_id)).
"a tyre maker ordered 12 units of item A for site Y on 12 January, order SO-456 line 2, still open." The import
(Point 2) writes it verbatim (blank order ids are rejected, never invented). It exists because some questions only
make sense at the order-line grain — how many orders ("hits") did we get, and how big is a typical one? —
which the line-fill-rate service level needs and which any weekly sum destroys.
The weekly aggregation — the planning signal (master.demand_actuals, one row per
item × site × week × fulfilled-or-open): the Demand aggregation step sums the order lines of
each week into it. This is the demand signal every planning tool reads — the forecast learns from it, MEIO
derives its rates, coverage routes it to warehouses, ABC classes it.
The is_open partition, in plain terms: every row carries one flag —
fulfilled or still open. That flag plus the planning Monday sorts all demand into exactly one of
three buckets:
Worked example.
Customer orders 10 crates on 12 January (delivered) and 5 more on 15 January (still open); the planning Monday is 19 January. The order level keeps both lines as they came. The weekly aggregation sums them into the week of 12 January as two separate rows — "10 units, closed" and "5 units, open" — because a completed sale and a pending promise are different planning facts and are never merged (live evidence of the split: the demo tenant holds 11,727 order lines → 27,944 weekly rows). The 10 closed crates are history the forecast learns from; the 5 open ones are a backorder the supply plan must still deliver — but they cannot eat the future forecast.
| Demand slice | Planning meaning |
|---|---|
| Forecast history | Definition: date < planning Monday AND NOT is_open — closed/fulfilled past.Downstream consumers: forecast training, MEIO demand rates/σ and empirical distributions, βline hit statistics, indirect-rollup history, ABC/segmentation windows, alerts, dashboards, and Mirabelle AI. |
| Order book | Definition: date ≥ planning Monday — any status.Downstream consumers: netting firm-demand consumption, supply firm-order loaders, and detail-page order panels; never forecast training. |
| Backorders | Definition: date < planning Monday AND is_open — open past orders.Downstream consumers: supply treats them like open future demand with a week-0 clamp; they are not netted because past demand cannot consume future forecast. |
Where the flag itself is consumed — three reader families, three predicates:
| Reader | Predicate | Why |
|---|---|---|
| Supply + Allocation (the firm-order loaders) | date ≥ horizon OR is_open |
Open customer orders enter the plan: the order book plus backorders (open past rows), which clamp to week 0 and are treated like any open future order. |
| Netting (firm-demand consumption) | date ≥ planning Monday — no is_open filter (any status) |
Deliberate: a future week's demand consumes that week's forecast whether still open or already fulfilled early (future rows default to open at import), and backorders must not eat future forecast — past demand is routed to supply instead. |
| Every history reader (forecast training, MEIO rates/σ, indirect rollup, exceptions, NPI, retirement, dashboards) | date < planning Monday AND NOT is_open |
Closed, fulfilled history only — the slice every training and statistics consumer reads; open past rows are unfulfilled promises, not observed demand. |
The order level's own consumers (the order-line grain is the only place "number of hits" exists):
MEIO's line-fill-rate λ/μ hit statistics (closed-history order-level read), the netting firm-order drill-down
(NettingOrdersModal kind='firm'), and the Master Data demand-orders grid. The forecast chain never
touches the order level — it reads the weekly aggregation.

Fig. 13 — The order level's editing/review surface: Settings → Master Data → Objects →
Demand Orders (master.demand_orders, 82,708 rows on the demo tenant) — every row carries the
editable Open (is_open) column that decides its weekly slice; new rows default to
open. Captured 2026-11-09.
3.3 — Data shaping: zero-fill, min-observations, horizon limits¶
⚙ Process: no separate process — the gates execute inside two existing steps. Zero-fill and min-observations run inside the Demand aggregation step (run it as in 3.2); the demand horizon limits execute at forecast dispatch, inside the
forecaststep (the full chain, or the forecast card's own Run). Settings changes take effect on the next run of the corresponding step.
Three gates shape the weekly training dataframe (all OFF/absent by default — byte-identical baseline). Where each is configured:
| Gate | Configuration surface |
|---|---|
| Zero-fill + min-observations | Processes → the Demand aggregation chain card → Configure (its own modal — the same pattern as the Stage/Import cards; planner directive Nov 2026: NOT in global Settings, NOT on the Stage card): the Min observations field, the Zero-fill missing periods toggle, the Zero-fill max periods safety cap (appears only when the toggle is ON), plus the date range and aggregation. Auto-saves ~800 ms; admin saves. |
| Demand horizon limits | Pipelines → Forecast → Series scenario ("Base") → Edit → the Method Selection fold → expand a settings row: per-demand-group method candidates, confidence levels, and the Demand Horizon Limits group at the bottom — Min Periods / Max Periods (global-only) / Below-Min Policy (skip | zero-fill). Per-method min_periods / below_min_policy live one fold down, in Hyperparameters. |

Fig. 14 — Where zero-fill and min-observations are configured (the demo tenant): the Demand aggregation chain card → Configure modal (its own card — the same pattern as the Stage/Import cards; planner directive Nov 2026): Min observations, the Zero-fill missing periods toggle (ON here — the customer seasonal flows), the Zero-fill max periods cap beneath it, plus the date range and aggregation. Captured 2026-11-10.

Fig. 15 — Where the demand horizon limits are configured (the demo tenant): Pipelines → Forecast → Series scenario "Base" → Edit → Method Selection fold → row expand — the per-demand-group method candidates, the confidence-level checkboxes, and the Demand Horizon Limits group (Min Periods, Max Periods — global only, Below-Min Policy: skip | zero-fill). Captured 2026-11-09.
Why these settings stay tenant-global — the scope record.
Zero-fill and min-observations live in one tenant-global parameter set because their output is global: master.demand_actuals is the shared, across-pipelines weekly table — ONE derivation serves every pipeline (the 1.1 scope rules). Per-pipeline shaping therefore requires first making demand pipeline-scoped (per-pipeline demand stores or derived views — a large architectural change, option c, not undertaken). The horizon limits are already scoped where it matters — they live in the series scenario (per-scenario Method Selection / per-method Hyperparameters), so they can already differ per planning configuration.
What each gate does, and who consumes the shaped result:
| Gate | Planning meaning |
|---|---|
Zero-fill · data_source.query.zero_fill_missing_periods |
What it does: reindexes each forecast-permitted series across its observed span and fills missing weeks with 0, preventing sparse extracts from starving the ACF seasonality test. Consumers: characterization and forecast only; order book/backorders pass through untouched and synthetic rows are is_open=FALSE. |
| min-observations | What it does: drops series below the data-quality floor before filling, so synthetic zeros cannot resurrect a dropped series. Consumers: all downstream steps see the intentionally smaller series universe. |
Demand horizon limits · forecasting.demand_horizon_limits |
What it does: applies per-method min_periods at forecast dispatch; below-minimum series are skipped with min_periods_not_met or zero-filled per policy.Consumers: exception surfaces; only that method's forecast is excluded. |
Worked examples — one per gate.
Zero-fill (the seasonal-crate case). A depot ships ~400 units every week from June to August and nothing the rest of the year — so the customer's extract contains only the ~13 summer weeks. Without the fill, characterization sees 13 clustered points per year: the ACF seasonality test cannot detect a 52-week cycle (it needs the empty weeks present as explicit zeros to "see" the gap), and every seasonal method smears demand across the off-season. With the fill ON, the series is reindexed to every week between its first and last observation: the 39 empty winter weeks become 0 rows, the yearly cycle is detectable, and SeasonalHurdle can predict the on/off-window shape (the demo tenant live reference: Jun ≈ 1,587, Jul ≈ 2,896, winter 0). A series that genuinely starts in 2026 gets nothing padded into 2024 — the fill is span-only.
min-observations (the too-young series). A new item first shipped 3 weeks ago and holds 3 order lines. With the floor at, say, 8 observations, the series is dropped at ingest — 3 points fit nothing but noise, so it never reaches characterization or the forecast chain at all (a smaller series universe, by design). The floor judges the real rows before the fill runs, so synthetic zeros can never rescue a dropped series — and conversely the fill cannot turn 3 observations into more observations, only into a complete calendar.
Horizon limits (the per-method gate). The same 10-observation
intermittent series dispatches against AutoARIMA configured with min_periods = 24: the gate sees
10 < 24 and skips the (series, AutoARIMA) pair — a min_periods_not_met row lands in the
exceptions (Point 8) naming series + method, and AutoARIMA produces no candidate rows for it; other methods
with lower floors still run. With below_min_policy = zero_fill the series is instead reindexed and
forecast anyway. max_periods (global-only — ML/DL methods have fixed input windows) truncates from
the recent end: a 5-year series against max_periods = 156 keeps the last 3 years only.
Live state: zero-fill is ON on the customer family (the demo tenant, the demo tenant, another demo tenant — the seasonal crate flows), OFF/absent
everywhere else. The IQR outlier guard (zero_ratio > 0.5 ⇒ skip IQR) protects sparse
zero-filled series from being "corrected" to zero.
3.4 — Coverage: routes & the Demand-map editor (route-native)¶
⚙ Process: none of its own — coverage is master data on the routes themselves (
master.routeinbound TRANSFER lanes:coverage_pct, lead times) and takes effect when the rollup, MEIO and supply steps next run. How to edit it: the Dashboard's Demand tab (Map/List views, Fig. 11) — the install-base coverage modal writes REAL routes: it retunescoverage_pct(+ lead time) on existing lanes, creates missing lanes per demanded item (a lead time is required for a route-less target — fail-loud 400 otherwise), collapses parallel duplicate lanes, and retires (end-dates, never deletes) lanes to targets left out of the payload. Screen-created lanes carrytag='demand_map'; the reset action end-dates them and clears their change points (ERP lanes keep their last state). Drag an install-base diamond onto a warehouse = the 100% one-link write.
One truth, every consumer reads routes: the indirect-demand rollup (both passes —
per-date coverage shares), MEIO (LT blend + install-base served stream), both supply engines
(route options, the transfer allocator's edges, upstream demand explosion), the Route Network map
and the Routes grid all consume the same lanes — no parallel override table, no virtual links.
Historical demand stays at the client location (the order book nets there; warehouses receive the
flow through the lanes — the retired forecast-history reassignment mechanism and its write-only
PIPE_demand_reassigned table are gone; one-time migration:
files/scripts/migrate_coverage_to_routes.py). Customers on the map are informational context:
each customer's demand lands at its location, and that location's routes define its coverage.
3.5 — Time-phased coverage & quota change points¶
⚙ Process: none of its own — per-week values on the lanes, resolved by the ONE shared scheduler (
utils/route_quota_schedule.py).
A lane's coverage comes from exactly TWO sources — there is no third:
| Source | Time-phased? | Storage | Where you set it (UI) |
|---|---|---|---|
| 1 · The route's standing coverage | No — one value, valid every week the lane is active (only end_date switches it off) |
master.route.coverage_pct |
Settings → Master Data → Routes grid (inline edit); the Demand tab's install-base Coverage routes modal (base save: retunes / creates missing lanes with a lead time / end-dates dropped targets); drag-drop a diamond onto a warehouse = the 100% one-link write; the route create/update form; operator side: the import route feed + the lead-time step's statistical routes (observed share, system-owned) |
| 2 · Weekly coverage changes | Yes — "from this Monday the split is X", holding until expiry or the next change point; a 0 means "no share that week" (a value, never a lane removal) |
master.route_quota_override, kind='coverage' (keyed per lane + Monday; note carries provenance) |
the Demand tab's install-base modal — the "weekly coverage changes" chips (a whole-site revision at a chosen Monday); the per-lane weekly split editors (Route Network map node chip / lane details, the Routes grid's "⇄ splits" action, the Demand-map warehouse click, the Overview tooltip); the CustomerSplitModal Coverages tab (map click on a client location); Settings → Master Data → Route Quota Overrides grid (raw CRUD); operator side: the route_quota_override import step (planner-written demand_map points are guarded) |
Resolution (one ladder): the value at a week = the latest change point effective ≤ that week (not expired) → else the lane's standing coverage → else 1.0 / equal split. The rollup resolves per demand week (true time-phasing where demand forms); MEIO and supply order-choice resolve at the planning anchor (one steady-state value per run). Weeks without a change point simply use the standing value.
Change points are route-keyed, Monday-normalized, kind='push'|'coverage':
| Input | Meaning and consumers |
|---|---|
| Weekly coverage changes (the Demand-map modal's revision chips — a dated revision at a chosen Monday) | What it is: per (item × target) coverage change points on the site's lanes — the effective split from that Monday until the next change point; a target joining at a week gets a static-0 lane + the change point (no share before it). Consumers: demand formation per week — the rollup resolves per demand date; MEIO and MRP sourcing resolve at the planning anchor (the approved OQ8 architecture). |
Time-phased quota / coverage schedules (master.route_quota_override) |
What it is: per-lane, per-week push/coverage values replacing static reverse-engineered percentages — written by every per-lane editor (RouteSplitScheduleEditor / CustomerSplitModal / Routes grid). Consumers: rollup per-date shares and LP USE synthesis at the release week. |
Step by step — setting coverage from the UI¶

A · Standing coverage (the base route set) — Demand tab
- Pick the pipeline in the left toolbar, then Dashboard → Demand tab.
- Click an install-base marker (person glyph) on the map, or in the List view click Edit on an "Install Base → Warehouse(s)" row — the Coverage routes modal opens with the current route-derived split.
- Edit the links: change percentages, add a target (a lead time is required when the target has no route for some demanded item), or remove a target from the set.
- Save. The routes are written for real: primary lanes retuned, parallel duplicates collapsed, missing lanes
created (tagged
demand_map), dropped targets' lanes end-dated — never deleted (reversible in the Routes grid). A toast confirms; the list refreshes from the save response. - Quick variant: drag the diamond onto a warehouse = the 100% one-link write.
- Verify in Settings → Master Data → Routes: the lanes show the new
coverage_pct; screen-created lanes carry the "demand-map" badge.



B · Weekly coverage changes (time-phased) — same modal
- "+ add weekly revision" → pick a Monday → set that week's split → save.
- A coverage change point is written on the site's lanes at that Monday: weeks before it keep the standing routes, from it the new split holds until the next change point. A target joining at that week gets a static-0 lane + the change point (no share before it).
- Delete the revision chip to remove it — pure join-at-week lanes are retired with it.
- Verify in Settings → Master Data → Route Quota Overrides (points with
note='demand_map').


C · One lane, week by week — the per-lane split editors
- Open a weekly split editor from the Route Network map (node chip or lane click), the Routes grid's "⇄ splits" row action, the Demand map's warehouse click, or the Overview tooltip.
- Edit the cells (Excel-like: click/Enter, arrows/Tab, Escape cancels) — each save writes a change point on that lane. Σ ≠ 100% highlights amber: it warns, never blocks (the engines normalize).
D · What happens next
- The rollup applies per-week values at its next indirect-demand run; MEIO and order choice use the anchor-resolved value at their next runs. Re-run the steps from the ProcessRunner — no restart needed.
- Every demand-map save is audited (entity
coverage_routes); the base write records each lane's old and new state, so retunes are reversible from the Audit Log.
Live state (15 Nov 2026): the former install-base override rows (two demo tenants carried 3 each) are
materialized into real routes + coverage change points — the migration ran on every tenant and the retired tables
are dropped (per-tenant reports under reports/); the weekly mechanism is exercised by the
route-quota change-point suites.
3.6 — Lead-time analysis¶
⚙ Process: the lead-time step (
lead_time/runner.py) — mines the movement and receipt history tables into per-lane statistics. Run: the Lead Times view's run-step button, or the lead-time card on the Processes page (the API/CLI equivalents are in 3.D). Dormant until a lead-time scenario is linked; overrides are edited in the same view.
The lead-time step graphically — inputs, the process, its output tables, and who consumes them:
flowchart LR
A["INPUT — observed history<br/>movement ledger MASTER_supply_movement<br/>receipt history MASTER_supply_orders_hist"]
B["INPUT — ERP routes<br/>+ planner overrides"]
A --> C
B --> C
C["PROCESS — the lead-time step<br/>weighted mean / cv per item-lane<br/>deterministic bootstrap percentiles<br/>quota & coverage closure<br/>final_lt_days precedence"]
C --> D["OUTPUT — PIPE_route_lt_stats<br/>one row per item-lane<br/>(+ statistical routes into master.route)"]
D --> E["MEIO lead-time distributions<br/>(Tier 0 when scenario active)"]
D --> F["Supply route options<br/>(lanes with stats swap their LT<br/>for final_lt_days)"]
classDef io fill:#e7f6f0,stroke:#10b981,color:#1b4332;
classDef proc fill:#eef2ff,stroke:#6366f1,color:#312e81;
class A,B,D io;
class C proc;
| Input / mechanism | Meaning and downstream use |
|---|---|
Movement history MASTER_supply_movement |
Produces: raw observed movement history (release → arrival per lane). Consumed by: the lead-time step mines it; zone lane-throughput blends read its 12-month volumes. |
Receipt-history table MASTER_supply_orders_hist |
Produces: closed replenishment orders with observed durations (lead_time_days).Consumed by: MEIO's lead-time distribution Tier 1, volume-weighted by received_qty. |
| The lead-time step | Produces: per-item-lane weighted mean/std/cv, deterministic bootstrap percentiles and sample blobs, quota/coverage closure, and final_lt_days precedence.Consumed by: MEIO Tier 0 and supply route options. |
| Per-lane overrides | Produces: the planner's final word per item-lane (final LT days / horizon). Consumed by: the same MEIO and supply consumers through the precedence chain. |
3.D — For developers — the step & coverage APIs¶
The UI paths above cover the planner's loop; the equivalents for scripts and add-ons:
| Call | Purpose |
|---|---|
POST /api/pipeline/run/demand-aggregation {"pipeline_id": N} |
Run the Demand aggregation step standalone (the weekly derivation). |
POST /api/pipeline/run/forecast {"pipeline_id": N} |
Run the forecast step standalone (the demand horizon limits execute here). |
POST /api/pipeline/run/lead-time {"pipeline_id": N} |
Run the lead-time step standalone. |
GET /api/demand/coverage?pipeline_id=N |
The Demand-map payload (map + list; customers informational, install bases with route-derived links and change-point revisions). |
PUT /api/demand/coverage/routes |
The coverage editor's write — a base set (effective_date NULL) or a dated revision (effective_date Monday-normalized). Admin. |
DELETE /api/demand/coverage/routes/{install_site_id}[?effective_date=] |
Reset an install base's demand-map lanes / delete one dated revision. |
CLI equivalents: python files/run_pipeline.py --only demand-aggregation | forecast | lead-time --pipeline-id N.
3.T — Step-by-step test walkthrough¶
Demand shaping and lead-time verification.
| # | Where to look / what to click | You should see |
|---|---|---|
| 1 | Dashboard → Demand tab | the coverage map: customers (informational circles), install bases (person glyphs), warehouses |
| 2 | Click an install-base diamond → Coverage routes modal → edit shares (a route-less target requires a lead time) → save | REAL routes are written: lanes retuned/created (tag='demand_map')/retired — verify on the Routes grid and the Route Network map; drag-drop = the 100% one-link write |
| 3 | Coverage routes modal → "+ add weekly revision" → pick a Monday → edit the split | coverage change points at that Monday (visible in the modal's revision chips and every per-lane schedule editor); weeks before it keep the base routes |
| 4 | Master Data → Demand Order | one row per order LINE: order_id + line_id unique; is_open flags the order book |
| 5 | Processes → Demand aggregation card → Configure | the data_source parameter set: zero-fill toggle, min-observations, date range |
| 6 | Toggle zero-fill ON → run the step | sparse seasonal series gain their off-season zero weeks (verify on a series chart) |
| 7 | Demand tab → Lead Times view | per-lane stats: n_obs, mean, p50/p90, quota/coverage; filter by planning type |
| 8 | Click a lane → edit final-LT override | the override auto-saves; the next run's stats carry it (routes have the last word) |

The Demand tab map: customers, install bases, warehouses, coverage links.

Per-route lead-time statistics with filters and the expandable history/histogram detail.