ts_shape.events.production.pareto
Pareto ranking of categorical values per time window.
A generic Pareto roll-up: group a long-format frame by a time window and a
category column (typically value_string — downtime reasons, alarm codes,
scrap codes, operator ids), then rank categories by count or by a summed
value column. For each window the output carries rank,
share_of_total_pct and cumulative_pct so the 80/20 cut is a filter,
not a hand calculation.
This is the "which reasons took the most hours this shift?" building block.
It composes with :class:~ts_shape.events.production.DowntimeEvents
(whose top_downtime_reasons is downtime-specific) and with the
loader / filter / event-log chain exactly like the other detectors.
| Name | Description |
|---|---|
ParetoEvents | Rank categorical values per window by count or by a summed amount. |
ParetoEvents
ParetoEvents(dataframe: pd.DataFrame, *, time_column: str = 'systime') -> None
Bases: Base
Rank categorical values per window by count or by a summed amount.
The returned frame is long-format and Grafana-ready: one row per
(start, category) with the category's share of the window and the
cumulative share up to its rank, sorted highest-first within each
window.
Pipeline example::
pareto = ParetoEvents(df).rank_by_count(
category_column="value_string", window="1D", top_n=5
)
# → the five biggest reason codes per day with share_of_total_pct.
Each UUID in the input represents one signal; the categorical values are
read from category_column (default value_string). The constructor
inherits :class:~ts_shape.utils.base.Base, so the frame is sorted,
uuids and timestamps are validated, and the usual signal-check warnings
fire.
| Name | Description |
|---|---|
rank_by_count | Count rows per (window, category) and rank by count. |
rank_by_sum | Sum value_column per (window, category) and rank by sum. |
| Name | Type | Description | Default |
|---|---|---|---|
dataframe | DataFrame | Long-format input (systime, uuid, value_* and the category column — by default value_string). | required |
time_column | str | Timestamp column to window by. Default "systime". | 'systime' |
rank_by_count
rank_by_count(
*,
category_column: str = "value_string",
time_column: str = "systime",
window: str = "1D",
top_n: int | None = None
) -> pd.DataFrame
Count rows per (window, category) and rank by count.
| Name | Type | Description | Default |
|---|---|---|---|
category_column | str | The column holding the category label. Default "value_string". | 'value_string' |
time_column | str | Time column to window by. Default "systime". | 'systime' |
window | str | Pandas offset string ("1h", "1D", "MS"). Default "1D". | '1D' |
top_n | int | None | Keep only the top-N rows per window. None (default) keeps every category. | None |
| Type | Description |
|---|---|
DataFrame | A flat long-format DataFrame with columns start, category, |
DataFrame | total, share_of_total_pct, cumulative_pct, rank. |
DataFrame | Rows are sorted by (start, rank). |
rank_by_sum
rank_by_sum(
*,
category_column: str = "value_string",
value_column: str = "value_double",
time_column: str = "systime",
window: str = "1D",
top_n: int | None = None
) -> pd.DataFrame
Sum value_column per (window, category) and rank by sum.
| Name | Type | Description | Default |
|---|---|---|---|
category_column | str | The column holding the category label. Default "value_string". | 'value_string' |
value_column | str | The numeric column to sum. Default "value_double". | 'value_double' |
time_column | str | Time column to window by. Default "systime". | 'systime' |
window | str | Pandas offset string. Default "1D". | '1D' |
top_n | int | None | Keep only the top-N rows per window. | None |
| Type | Description |
|---|---|
DataFrame | A flat long-format DataFrame with the same columns as |
DataFrame | meth:rank_by_count; total is the summed value. |