Skip to main content
Version: 0.0.98

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.

Classes
NameDescription
LeadTimeAnalysisEventsAnalyze lead times between order placement and delivery in timeseries data.

LeadTimeAnalysisEvents​

classsource
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')

Functions
NameDescription
lead_timesMatch order events to delivery events.
lead_time_statisticsCompute summary statistics of lead times.
detect_lead_time_anomaliesFlag lead times exceeding mean + threshold_factor * std.
Parameters
NameTypeDescriptionDefault
dataframeDataFrameInput DataFrame with timeseries data.required
event_uuidstrUUID assigned to generated events.'sc:lead_time'
time_columnstrName of timestamp column.'systime'

lead_times​

methodsource
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.

Parameters
NameTypeDescriptionDefault
order_uuidstrUUID of the order placement signal.required
delivery_uuidstrUUID of the delivery received signal.required
value_columnstrColumn containing order identifiers.'value_string'
Returns
TypeDescription
DataFrameDataFrame with columns: start, end, duration_seconds, order_time,
DataFramedelivery_time, uuid, source_uuid, is_delta, lead_time_seconds,
DataFramelead_time_hours, order_id. start/end are the order and
DataFramedelivery times; source_uuid is "<order_uuid>,<delivery_uuid>".

lead_time_statistics​

methodsource
lead_time_statistics(
order_uuid: str, delivery_uuid: str, value_column: str = "value_string"
) -> pd.DataFrame

Compute summary statistics of lead times.

Parameters
NameTypeDescriptionDefault
order_uuidstrUUID of the order placement signal.required
delivery_uuidstrUUID of the delivery received signal.required
value_columnstrColumn containing order identifiers.'value_string'
Returns
TypeDescription
DataFrameSingle-row DataFrame with columns: mean_hours, std_hours,
DataFramemin_hours, max_hours, p95_hours, count, order_count (the number
DataFrameof matched orders).
DataFrameCanonical twin columns: order_count (after count); it holds the same
DataFramevalues as the deprecated column right before it, which is removed
DataFramein the next major release.

detect_lead_time_anomalies​

methodsource
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
NameTypeDescriptionDefault
order_uuidstrUUID of the order placement signal.required
delivery_uuidstrUUID of the delivery received signal.required
threshold_factorfloatNumber of standard deviations above mean to flag as anomalous.2.0
value_columnstrColumn containing order identifiers.'value_string'
Returns
TypeDescription
DataFrameDataFrame with columns: systime, order_time, delivery_time, uuid,
DataFramesource_uuid, is_delta, lead_time_hours, z_score. systime is
DataFramethe delivery time (when the anomaly becomes known).