ts_shape.events.production.long_downtime_events
Classes
| Name | Description |
|---|---|
LongDowntimeEvents | Production: Long Downtime Detection |
LongDowntimeEvents
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
| Name | Description |
|---|---|
detect_long_downtime | Return idle/stopped intervals whose duration is >= min_gap. |
count_events_between_gaps | Count production events in each window between consecutive long downtimes. |
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
dataframe | DataFrame | Long-format timeseries frame (one row per sample, uuid identifies the signal). | required |
run_state_uuid | str | UUID of the run-state signal; must be present in a non-empty dataframe. | required |
event_uuid | str | UUID stamped on emitted events. | 'prod:long_downtime' |
value_column | str | Column holding the run state. | 'value_bool' |
time_column | str | Timestamp column. | 'systime' |
value_range | tuple[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_states | Collection[Any] | None | Values 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
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
| 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: 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
| 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 |