Skip to main content
Version: 0.0.98

ts_shape.events.supplychain.inventory_monitoring

Inventory monitoring events for supply chain timeseries.

Detects low stock intervals, calculates consumption rates, identifies reorder point breaches, and predicts stockouts.

Classes
NameDescription
InventoryMonitoringEventsMonitor inventory levels from a timeseries signal and detect supply chain events.

InventoryMonitoringEvents​

classsource
InventoryMonitoringEvents(
dataframe: pd.DataFrame,
level_uuid: str,
*,
event_uuid: str = "sc:inventory",
value_column: str = "value_double",
time_column: str = "systime"
) -> None

Bases: Base

Monitor inventory levels from a timeseries signal and detect supply chain events.

Each inventory level is tracked via a UUID signal whose numeric value represents the current stock quantity.

Example usage

tracker = InventoryMonitoringEvents(df, level_uuid='warehouse_a_level') low = tracker.detect_low_stock(min_level=100, hold='5min') rate = tracker.consumption_rate(window='1h') breach = tracker.reorder_point_breach(reorder_level=200, safety_stock=50) prediction = tracker.stockout_prediction(consumption_rate_window='4h')

Functions
NameDescription
detect_low_stockFlag intervals where inventory stays below min_level for at least hold.
consumption_rateCalculate rolling consumption rate from inventory level decreases.
reorder_point_breachDetect when inventory falls below reorder point or safety stock level.
stockout_predictionEstimate time until stockout based on recent consumption rate.
Parameters
NameTypeDescriptionDefault
dataframeDataFrameInput DataFrame with timeseries data.required
level_uuidstrUUID of the inventory level signal.required
event_uuidstrUUID assigned to generated events.'sc:inventory'
value_columnstrColumn containing numeric inventory levels.'value_double'
time_columnstrName of timestamp column.'systime'

detect_low_stock​

methodsource
detect_low_stock(
min_level: float, hold: str = "0s", *, interval_end: str = "next_change"
) -> pd.DataFrame

Flag intervals where inventory stays below min_level for at least hold.

Parameters
NameTypeDescriptionDefault
min_levelfloatThreshold below which stock is considered low.required
holdstrMinimum duration the level must stay below threshold (e.g. '0s', '5min', '1h').'0s'
interval_endstr"next_change" (default) ends an interval at the next sample (the transition), so the interval spans the time the condition held and change-encoded signals -- one row per change -- keep their duration. "last_sample" ends it at its last flagged sample. See :func:ts_shape.utils.intervals.interval_end_times.'next_change'
Returns
TypeDescription
DataFrameDataFrame with columns: start, end, uuid, source_uuid, is_delta,
DataFramemin_value, avg_value, duration_seconds.

consumption_rate​

methodsource
consumption_rate(
window: str = "1h", *, handle_refills: bool = True
) -> pd.DataFrame

Calculate rolling consumption rate from inventory level decreases.

The rate is expressed as units consumed per hour within each window.

Parameters
NameTypeDescriptionDefault
windowstrTime-based window for grouping (e.g. '1h', '30min').'1h'
handle_refillsboolWhen True (default) only level decreases are summed (a refill is treated like a counter reset), booked in the window of the reading that reports them. When False consumption is first - last level of the window, so a refill inside the window cancels out the consumption (100 -> 40 -> 100 -> 40 reads as 0).True
Returns
TypeDescription
DataFrameDataFrame with columns: start, end, duration_seconds, uuid,
DataFramesource_uuid, is_delta, consumption_rate, level_start, level_end.
DataFrameend is start plus window (calendar-correct: a daily
DataFramewindow on a DST change lasts 23 h or 25 h, and the rate is per
DataFramehour of that real length).

reorder_point_breach​

methodsource
reorder_point_breach(
reorder_level: float, safety_stock: float = 0.0
) -> pd.DataFrame

Detect when inventory falls below reorder point or safety stock level.

Parameters
NameTypeDescriptionDefault
reorder_levelfloatThe reorder point threshold.required
safety_stockfloatSafety stock threshold (must be <= reorder_level).0.0
Returns
TypeDescription
DataFrameDataFrame with columns: systime, uuid, source_uuid, is_delta,
DataFramecurrent_level,
DataFramebreach_type ('reorder' or 'safety_stock'), deficit.

stockout_prediction​

methodsource
stockout_prediction(
consumption_rate_window: str = "4h", *, handle_refills: bool = True
) -> pd.DataFrame

Estimate time until stockout based on recent consumption rate.

For each data point, uses the consumption rate calculated over the preceding consumption_rate_window to project when inventory will reach zero.

Parameters
NameTypeDescriptionDefault
consumption_rate_windowstrLookback window for calculating consumption rate (e.g. '4h').'4h'
handle_refillsboolWhen True (default) the consumption in the lookback is the sum of the level decreases between consecutive samples (the same refill-aware rule as :meth:consumption_rate), so a refill inside the window does not cancel the consumption around it. When False it is the level at the window's first sample minus the level at its last (a refill then hides consumption, often giving 0).True
Returns
NameTypeDescription
DataFrameDataFrame with columns: systime, uuid, source_uuid, is_delta,
DataFramecurrent_level,
DataFrameconsumption_rate (units per hour), estimated_stockout_time_hours.
DataFrameestimated_stockout_time_hours is NaN where the level is not
fallingno consumption in the windowno stockout is
DataFrameprojected.