Skip to content

long_downtime_events

long_downtime_events ¤

LongDowntimeEvents ¤

LongDowntimeEvents(
    dataframe: 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
)

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.

detect_long_downtime ¤

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

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

Parameters:

Name Type Description Default
min_gap str

Minimum downtime duration to report (pandas offset string). Default "3h".

'3h'
interval_end str

How 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_end Timestamp | None

Optional bound for a downtime still open at the end of the data (e.g. "now").

None

Returns:

Type Description
DataFrame

DataFrame with columns: start, end, duration_seconds,

DataFrame

downtime_index, uuid, source_uuid, is_delta.

count_events_between_gaps ¤

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

Count production events in each window between consecutive long downtimes.

Parameters:

Name Type Description Default
production_df DataFrame

ts-shape DataFrame with the production signal.

required
production_uuid str

UUID of the production signal in production_df.

required
min_gap str

Minimum downtime duration to qualify as a long-downtime boundary.

'3h'
value_column str

Column used for 'sum' and 'transitions' aggregations.

'value_integer'
aggregation str

How 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_end str

How 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_end Timestamp | None

Optional bound for a downtime still open at the end of the data; forwarded to :meth:detect_long_downtime.

None

Returns:

Name Type Description
DataFrame

DataFrame with one row per inter-gap window.

Columns DataFrame

start, end, window_duration_seconds, event_count, downtime_index, uuid, source_uuid, is_delta