lead_time_analysis
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.
LeadTimeAnalysisEvents ¤
LeadTimeAnalysisEvents(
dataframe: DataFrame,
*,
event_uuid: str = "sc:lead_time",
time_column: str = "systime"
)
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, each order is matched to the first delivery of the same identifier at or after it; otherwise each order, in time order, is paired with the first not yet used delivery at or after it.
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')
Initialize lead time analyzer.
Parameters:
| 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).
When deliveries carry identifiers that occur among the orders, each
order is matched to the first delivery with the same identifier at or
after the order time (unmatched orders are left out). Otherwise each
order, in time order, is paired with the first delivery at or after
it that is not paired yet; orders and deliveries left without a
partner are dropped with a
:class:~ts_shape.errors.DataQualityWarning. A lead time is never
negative.
Parameters:
| 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'
|
Returns:
| 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. |
DataFrame
|
delivery times; |
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.
Parameters:
| 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'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Single-row DataFrame with columns: mean_hours, std_hours, |
DataFrame
|
min_hours, max_hours, p95_hours, count. |
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.
Parameters:
| 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'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with columns: systime, order_time, delivery_time, uuid, |
DataFrame
|
source_uuid, is_delta, lead_time_hours, z_score. |
DataFrame
|
the delivery time (when the anomaly becomes known). |