ts_shape.events.supplychain.demand_pattern
Demand pattern events for supply chain timeseries.
Aggregates demand by time window, detects demand spikes, and summarizes seasonal demand patterns.
| Name | Description |
|---|---|
DemandPatternEvents | Analyze demand patterns from a timeseries demand signal. |
DemandPatternEvents
DemandPatternEvents(
dataframe: pd.DataFrame,
demand_uuid: str,
*,
event_uuid: str = "sc:demand",
value_column: str = "value_double",
time_column: str = "systime"
) -> None
Bases: Base
Analyze demand patterns from a timeseries demand signal.
Each demand event is a numeric value representing demand quantity at a point in time.
Example usage
analyzer = DemandPatternEvents(df, demand_uuid='order_demand') daily = analyzer.demand_by_period(window='1D') spikes = analyzer.detect_demand_spikes(threshold_factor=2.0) seasonal = analyzer.seasonality_summary(window='1D')
| Name | Description |
|---|---|
demand_by_period | Aggregate demand per time period. |
detect_demand_spikes | Flag periods where demand exceeds mean + threshold_factor * std. |
seasonality_summary | Compute demand patterns by day-of-week (for daily) or hour-of-day (for hourly). |
| Name | Type | Description | Default |
|---|---|---|---|
dataframe | DataFrame | Input DataFrame with timeseries data. | required |
demand_uuid | str | UUID of the demand signal. | required |
event_uuid | str | UUID assigned to generated events. | 'sc:demand' |
value_column | str | Column containing numeric demand values. | 'value_double' |
time_column | str | Name of timestamp column. | 'systime' |
demand_by_period
demand_by_period(
window: str = "1D", empty_periods: Literal["zero", "drop"] = "zero"
) -> pd.DataFrame
Aggregate demand per time period.
Each row of the demand signal is one order (or demand event), so a
period without rows is a period without demand. With
empty_periods="zero" (the default) every period between the
first and the last period with data appears, the empty ones with
total_demand = 0, peak_demand = 0, order_count = 0 and
avg_demand missing (it is the mean order size, undefined
without orders). A cumulative counter is not event-encoded demand:
difference it into per-event quantities first.
| Name | Type | Description | Default |
|---|---|---|---|
window | str | Pandas offset alias for grouping (e.g. '1D', '1h'). | '1D' |
empty_periods | Literal['zero', 'drop'] | "zero" keeps periods without orders as zero demand; "drop" leaves them out (only periods with at least one order). | 'zero' |
| Type | Description |
|---|---|
DataFrame | DataFrame with columns: start, end, duration_seconds, uuid, |
DataFrame | source_uuid, is_delta, total_demand, avg_demand, peak_demand, |
DataFrame | order_count. order_count is the number of orders (non-missing |
DataFrame | values) in the period. |
| Type | Description |
|---|---|
ValueError | If empty_periods is not "zero" or "drop". |
detect_demand_spikes
detect_demand_spikes(
threshold_factor: float = 2.0,
window: str = "1D",
empty_periods: Literal["zero", "drop"] = "zero",
) -> pd.DataFrame
Flag periods where demand exceeds mean + threshold_factor * std.
The mean and std are taken over the period totals of
:meth:demand_by_period, by default including the periods without
orders as zero demand: a spike is measured against the demand over
the whole span, not only against the periods that had orders.
| Name | Type | Description | Default |
|---|---|---|---|
threshold_factor | float | Number of standard deviations above the mean to flag as a spike. | 2.0 |
window | str | Pandas offset alias for aggregation period. | '1D' |
empty_periods | Literal['zero', 'drop'] | Passed to :meth:demand_by_period; "drop" gives the baseline over periods with orders only. | 'zero' |
| Type | Description |
|---|---|
DataFrame | DataFrame with columns: start, end, duration_seconds, uuid, |
DataFrame | source_uuid, is_delta, demand, baseline_mean, spike_magnitude. |
DataFrame | end is start plus window. |
seasonality_summary
seasonality_summary(
window: str = "1D", empty_periods: Literal["zero", "drop"] = "zero"
) -> pd.DataFrame
Compute demand patterns by day-of-week (for daily) or hour-of-day (for hourly).
When window='1D', groups by day of week (Monday=0 .. Sunday=6).
When window is sub-daily (e.g. '1h'), groups by hour of day (0..23).
The statistics are over the period totals of :meth:demand_by_period,
by default including periods without orders as zero demand (a
weekday that usually has no orders shows a low average).
| Name | Type | Description | Default |
|---|---|---|---|
window | str | Pandas offset alias. '1D' for day-of-week analysis, any sub-daily frequency for hour-of-day analysis. | '1D' |
empty_periods | Literal['zero', 'drop'] | Passed to :meth:demand_by_period; "drop" uses periods with orders only. | 'zero' |
| Type | Description |
|---|---|
DataFrame | DataFrame with columns: period_label, avg_demand, std_demand, |
DataFrame | min_demand, max_demand. |