ts_shape.events.production.operating_state
Classes
OperatingStateEvents(
dataframe: pd.DataFrame,
signal_uuid: str,
*,
event_uuid: str = "prod:operating_state",
value_column: str = "value_double",
time_column: str = "systime"
) -> None
Bases: Base
Production: Operating State Inference
Infer discrete operating states from continuous signals (vibration,
current, power, temperature) when no explicit boolean state signal
is available. Answers the question "what state is the machine in?"
Unlike :class:MachineStateEvents which requires a boolean run/idle
signal, this class clusters continuous values to discover states
automatically.
Methods:
- infer_states: Cluster the signal into N operating states.
- state_duration_statistics: How long does each state typically last?
- unusual_state_sequence: Did states occur in an unexpected order?
- dwell_time_violation: Did the machine stay in a state too long?
Functions
Parameters
| Name | Type | Description | Default |
|---|
dataframe | DataFrame | Long-format timeseries frame (one row per sample, uuid identifies the signal). | required |
signal_uuid | str | UUID of the continuous signal (vibration, current, power, ...) the states are inferred from. | required |
event_uuid | str | UUID stamped on emitted events. | 'prod:operating_state' |
value_column | str | Column holding the signal values. | 'value_double' |
time_column | str | Timestamp column. | 'systime' |
infer_states(
n_states: int = 2,
min_duration: str = "0s",
interval_end: str = "next_change",
) -> pd.DataFrame
Cluster the signal into N operating states.
Uses quantile-based binning to assign each sample to a state,
then intervalizes consecutive same-state runs.
Parameters
| Name | Type | Description | Default |
|---|
n_states | int | Number of states to infer (2 = low/high, 3 = low/mid/high, etc.). | 2 |
min_duration | str | Discard intervals shorter than this. | '0s' |
interval_end | str | "next_change" (default) ends an interval at the first sample of the next state, so the intervals tile the signal and no time between two states is lost; the last interval ends at the last sample. "last_sample" ends each interval at its own last sample (the behavior before October 2026), which leaves one sampling period per interval in no state. | 'next_change' |
Returns
| Type | Description |
|---|
DataFrame | DataFrame with columns: start, end, state, state_label, |
DataFrame | mean_value, duration_seconds, uuid (event uuid), source_uuid |
DataFrame | (signal uuid). Samples without a value are ignored; with fewer |
DataFrame | valued samples than n_states the result is empty. |
Raises
| Type | Description |
|---|
ValueError | If interval_end is not "next_change" or "last_sample". |
state_duration_statistics(
n_states: int = 2, interval_end: str = "next_change"
) -> pd.DataFrame
How long does each inferred state typically last?
Parameters
| Name | Type | Description | Default |
|---|
n_states | int | Number of states to infer. | 2 |
interval_end | str | How intervals end, see :meth:infer_states. | 'next_change' |
Returns
| Type | Description |
|---|
DataFrame | DataFrame with columns: state, state_label, count, |
DataFrame | mean_duration, std_duration, min_duration, max_duration, |
DataFrame | total_duration (float seconds). count is the number of |
DataFrame | intervals in the state. |
DataFrame | Canonical twin columns: interval_count (after count), |
DataFrame | mean_duration_seconds, |
DataFrame | std_duration_seconds, min_duration_seconds, |
DataFrame | max_duration_seconds and total_duration_seconds, each |
DataFrame | right after the deprecated column of the same values, which is |
DataFrame | removed in the next major release. |
unusual_state_sequence(
n_states: int = 2,
expected_order: list[int] | None = None,
interval_end: str = "next_change",
) -> pd.DataFrame
Detect state transitions that violate an expected order.
By default, the expected order is the most common transition
sequence observed in the data. Supply expected_order to
override (e.g. [0, 1, 2, 1, 0] for a warm-up/run/cool-down
cycle).
Parameters
| Name | Type | Description | Default |
|---|
n_states | int | Number of states to infer. | 2 |
expected_order | list[int] | None | List of state IDs defining the expected cycle. If None, the most frequent bigram transitions are treated as "normal". | None |
interval_end | str | How intervals end, see :meth:infer_states (transition times do not depend on it). | 'next_change' |
Returns
| Type | Description |
|---|
DataFrame | DataFrame with columns: transition_time, from_state, |
DataFrame | to_state, from_label, to_label, is_unusual. |
dwell_time_violation(
state: int,
max_duration: str,
n_states: int = 2,
interval_end: str = "next_change",
) -> pd.DataFrame
Find intervals where the machine stayed in a state too long.
Parameters
| Name | Type | Description | Default |
|---|
state | int | State ID to check (0-based). | required |
max_duration | str | Maximum allowed duration (e.g. '5min'). | required |
n_states | int | Number of states to infer. | 2 |
interval_end | str | How intervals end, see :meth:infer_states. | 'next_change' |
Returns
| Type | Description |
|---|
DataFrame | DataFrame with columns: start, end, state_label, |
DataFrame | duration_seconds, excess_seconds, uuid (event uuid), source_uuid |
DataFrame | (signal uuid). |