Skip to main content
Version: Next

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.

Classes
NameDescription
ParetoEventsRank categorical values per window by count or by a summed amount.

ParetoEvents​

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

Functions
NameDescription
rank_by_countCount rows per (window, category) and rank by count.
rank_by_sumSum value_column per (window, category) and rank by sum.
Parameters
NameTypeDescriptionDefault
dataframeDataFrameLong-format input (systime, uuid, value_* and the category column — by default value_string).required
time_columnstrTimestamp column to window by. Default "systime".'systime'

rank_by_count​

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

Parameters
NameTypeDescriptionDefault
category_columnstrThe column holding the category label. Default "value_string".'value_string'
time_columnstrTime column to window by. Default "systime".'systime'
windowstrPandas offset string ("1h", "1D", "MS"). Default "1D".'1D'
top_nint | NoneKeep only the top-N rows per window. None (default) keeps every category.None
Returns
TypeDescription
DataFrameA flat long-format DataFrame with columns start, category,
DataFrametotal, share_of_total_pct, cumulative_pct, rank.
DataFrameRows are sorted by (start, rank).

rank_by_sum​

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

Parameters
NameTypeDescriptionDefault
category_columnstrThe column holding the category label. Default "value_string".'value_string'
value_columnstrThe numeric column to sum. Default "value_double".'value_double'
time_columnstrTime column to window by. Default "systime".'systime'
windowstrPandas offset string. Default "1D".'1D'
top_nint | NoneKeep only the top-N rows per window.None
Returns
TypeDescription
DataFrameA flat long-format DataFrame with the same columns as
DataFramemeth:rank_by_count; total is the summed value.