ts_shape.events.supplychain.lead_time_analysis
Lead time analysis events for supply chain timeseries.
Matches order events to delivery events, computes lead time statistics, and detects anomalous lead times.
| Name | Description |
|---|---|
LeadTimeAnalysisEvents | Analyze lead times between order placement and delivery in timeseries data. |
LeadTimeAnalysisEvents
LeadTimeAnalysisEvents(
dataframe: pd.DataFrame,
*,
event_uuid: str = "sc:lead_time",
time_column: str = "systime"
) -> None
Bases: Base
Analyze lead times between order placement and delivery in timeseries data.
Order and delivery events are identified by separate UUIDs. When the delivery rows carry the order identifier, orders and deliveries are paired one-to-one within each identifier: each order, in time order, with the first not yet used delivery of the same identifier at or after it. Otherwise the same FIFO pairing runs over all orders and deliveries.
Example usage
analyzer = LeadTimeAnalysisEvents(df) lead_times = analyzer.lead_times('order_signal', 'delivery_signal') stats = analyzer.lead_time_statistics('order_signal', 'delivery_signal') anomalies = analyzer.detect_lead_time_anomalies('order_signal', 'delivery_signal')
| Name | Description |
|---|---|
lead_times | Match order events to delivery events. |
lead_time_statistics | Compute summary statistics of lead times. |
detect_lead_time_anomalies | Flag lead times exceeding mean + threshold_factor * std. |
| Name | Type | Description | Default |
|---|---|---|---|
dataframe | DataFrame | Input DataFrame with timeseries data. | required |
event_uuid | str | UUID assigned to generated events. | 'sc:lead_time' |
time_column | str | Name of timestamp column. | 'systime' |
lead_times
lead_times(
order_uuid: str, delivery_uuid: str, value_column: str = "value_string"
) -> pd.DataFrame
Match order events to delivery events.
The value_column is used as an order identifier (e.g. PO number).
Each order, in time order, is paired with the first delivery at or
after it that is not paired yet. When deliveries carry identifiers
that occur among the orders, this FIFO pairing runs within each
identifier (one delivery per order, so two orders with the same
identifier need two deliveries; a multi-line purchase order needs
line-level identifiers such as "PO-1/10"); otherwise it runs over
all orders and deliveries. Orders and deliveries left without a
partner (including rows without an identifier on the identifier
path) are dropped with a
:class:~ts_shape.errors.DataQualityWarning. A lead time is never
negative. Rows come in order-time order.
| Name | Type | Description | Default |
|---|---|---|---|
order_uuid | str | UUID of the order placement signal. | required |
delivery_uuid | str | UUID of the delivery received signal. | required |
value_column | str | Column containing order identifiers. | 'value_string' |
| Type | Description |
|---|---|
DataFrame | DataFrame with columns: start, end, duration_seconds, order_time, |
DataFrame | delivery_time, uuid, source_uuid, is_delta, lead_time_seconds, |
DataFrame | lead_time_hours, order_id. start/end are the order and |
DataFrame | delivery times; source_uuid is "<order_uuid>,<delivery_uuid>". |
lead_time_statistics
lead_time_statistics(
order_uuid: str, delivery_uuid: str, value_column: str = "value_string"
) -> pd.DataFrame
Compute summary statistics of lead times.
| Name | Type | Description | Default |
|---|---|---|---|
order_uuid | str | UUID of the order placement signal. | required |
delivery_uuid | str | UUID of the delivery received signal. | required |
value_column | str | Column containing order identifiers. | 'value_string' |
| Type | Description |
|---|---|
DataFrame | Single-row DataFrame with columns: mean_hours, std_hours, |
DataFrame | min_hours, max_hours, p95_hours, count, order_count (the number |
DataFrame | of matched orders). |
DataFrame | Canonical twin columns: order_count (after count); it holds the same |
DataFrame | values as the deprecated column right before it, which is removed |
DataFrame | in the next major release. |
detect_lead_time_anomalies
detect_lead_time_anomalies(
order_uuid: str,
delivery_uuid: str,
threshold_factor: float = 2.0,
value_column: str = "value_string",
) -> pd.DataFrame
Flag lead times exceeding mean + threshold_factor * std.
| Name | Type | Description | Default |
|---|---|---|---|
order_uuid | str | UUID of the order placement signal. | required |
delivery_uuid | str | UUID of the delivery received signal. | required |
threshold_factor | float | Number of standard deviations above mean to flag as anomalous. | 2.0 |
value_column | str | Column containing order identifiers. | 'value_string' |
| Type | Description |
|---|---|
DataFrame | DataFrame with columns: systime, order_time, delivery_time, uuid, |
DataFrame | source_uuid, is_delta, lead_time_hours, z_score. systime is |
DataFrame | the delivery time (when the anomaly becomes known). |