Skip to main content
Version: Next

ts_shape.events.production.long_downtime_events

Classes
NameDescription
LongDowntimeEventsProduction: Long Downtime Detection

LongDowntimeEvents​

classsource
LongDowntimeEvents(
dataframe: pd.DataFrame,
run_state_uuid: str,
*,
event_uuid: str = "prod:long_downtime",
value_column: str = "value_bool",
time_column: str = "systime",
value_range: tuple[float | None, float | None] | None = None,
run_states: Collection[Any] | None = None
) -> None

Bases: Base

Production: Long Downtime Detection

Detect downtime intervals exceeding a minimum duration threshold from a boolean or integer state signal, then count production events that occur between consecutive long-downtime boundaries.

  • LongDowntimeEvents: Long idle intervals and inter-gap production counts.
    • detect_long_downtime: Find idle/stopped intervals >= min_gap (default 3 h).
    • count_events_between_gaps: Count production events between consecutive long-downtime boundaries.
Functions
NameDescription
detect_long_downtimeReturn idle/stopped intervals whose duration is >= min_gap.
count_events_between_gapsCount production events in each window between consecutive long downtimes.
Parameters
NameTypeDescriptionDefault
dataframeDataFrameLong-format timeseries frame (one row per sample, uuid identifies the signal).required
run_state_uuidstrUUID of the run-state signal; must be present in a non-empty dataframe.required
event_uuidstrUUID stamped on emitted events.'prod:long_downtime'
value_columnstrColumn holding the run state.'value_bool'
time_columnstrTimestamp column.'systime'
value_rangetuple[float | None, float | None] | None(lower, upper) inclusive bounds; a value inside counts as running (either bound may be None). None (default) casts the value to bool.None
run_statesCollection[Any] | NoneValues of the run signal that mean running (e.g. {2} for a mode signal where 2 is automatic, or {"RUN"}); every other known value is not running. None (default) uses value_range or reads the signal as a bool, with a DataQualityWarning when it is not one.None

detect_long_downtime​

methodsource
detect_long_downtime(
min_gap: str = "3h",
*,
interval_end: str = "next_change",
data_end: pd.Timestamp | None = None
) -> pd.DataFrame

Return idle/stopped intervals whose duration is >= min_gap.

Parameters
NameTypeDescriptionDefault
min_gapstrMinimum downtime duration to report (pandas offset string). Default "3h".'3h'
interval_endstrHow each downtime interval is closed. "next_change" (default) closes the interval at the following transition, so stops on change-encoded (is_delta) state signals are measured. The final, still-open downtime is bounded by data_end when given (otherwise it stays zero-length and is filtered out). "last_sample" ends it at its last sample; on a change-encoded signal (one row per transition) a multi-hour stop is then a single zero-duration row and is missed.'next_change'
data_endTimestamp | NoneOptional bound for a downtime still open at the end of the data (e.g. "now").None
Returns
TypeDescription
DataFrameDataFrame with columns: start, end, duration_seconds,
DataFramedowntime_index, uuid, source_uuid, is_delta.

count_events_between_gaps​

methodsource
count_events_between_gaps(
production_df: pd.DataFrame,
production_uuid: str,
*,
min_gap: str = "3h",
value_column: str = "value_integer",
aggregation: str = "count",
interval_end: str = "next_change",
data_end: pd.Timestamp | None = None
) -> pd.DataFrame

Count production events in each window between consecutive long downtimes.

Parameters
NameTypeDescriptionDefault
production_dfDataFramets-shape DataFrame with the production signal.required
production_uuidstrUUID of the production signal in production_df.required
min_gapstrMinimum downtime duration to qualify as a long-downtime boundary.'3h'
value_columnstrColumn used for 'sum' and 'transitions' aggregations.'value_integer'
aggregationstrHow to count events in each window: - 'count': number of rows in the window - 'sum': sum of value_column in the window - 'transitions': number of value changes (state changes)'count'
interval_endstrHow each downtime interval is closed; forwarded to :meth:detect_long_downtime. "next_change" (default) closes it at the next transition; "last_sample" ends it at its last sample, which makes every stop on a change-encoded (is_delta) state signal zero-length.'next_change'
data_endTimestamp | NoneOptional bound for a downtime still open at the end of the data; forwarded to :meth:detect_long_downtime.None
Returns
NameTypeDescription
DataFrameDataFrame with one row per inter-gap window.
ColumnsDataFramestart, end, window_duration_seconds, event_count, downtime_index, uuid, source_uuid, is_delta