Skip to main content
Version: Next

ts_shape.events.production.operating_state

Classes
NameDescription
OperatingStateEventsProduction: Operating State Inference

OperatingStateEvents​

classsource
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
NameDescription
infer_statesCluster the signal into N operating states.
state_duration_statisticsHow long does each inferred state typically last?
unusual_state_sequenceDetect state transitions that violate an expected order.
dwell_time_violationFind intervals where the machine stayed in a state too long.
Parameters
NameTypeDescriptionDefault
dataframeDataFrameLong-format timeseries frame (one row per sample, uuid identifies the signal).required
signal_uuidstrUUID of the continuous signal (vibration, current, power, ...) the states are inferred from.required
event_uuidstrUUID stamped on emitted events.'prod:operating_state'
value_columnstrColumn holding the signal values.'value_double'
time_columnstrTimestamp column.'systime'

infer_states​

methodsource
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
NameTypeDescriptionDefault
n_statesintNumber of states to infer (2 = low/high, 3 = low/mid/high, etc.).2
min_durationstrDiscard intervals shorter than this.'0s'
interval_endstr"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
TypeDescription
DataFrameDataFrame with columns: start, end, state, state_label,
DataFramemean_value, duration_seconds, uuid (event uuid), source_uuid
DataFrame(signal uuid). Samples without a value are ignored; with fewer
DataFramevalued samples than n_states the result is empty.
Raises
TypeDescription
ValueErrorIf interval_end is not "next_change" or "last_sample".

state_duration_statistics​

methodsource
state_duration_statistics(
n_states: int = 2, interval_end: str = "next_change"
) -> pd.DataFrame

How long does each inferred state typically last?

Parameters
NameTypeDescriptionDefault
n_statesintNumber of states to infer.2
interval_endstrHow intervals end, see :meth:infer_states.'next_change'
Returns
TypeDescription
DataFrameDataFrame with columns: state, state_label, count,
DataFramemean_duration, std_duration, min_duration, max_duration,
DataFrametotal_duration (float seconds). count is the number of
DataFrameintervals in the state.
DataFrameCanonical twin columns: interval_count (after count),
DataFramemean_duration_seconds,
DataFramestd_duration_seconds, min_duration_seconds,
DataFramemax_duration_seconds and total_duration_seconds, each
DataFrameright after the deprecated column of the same values, which is
DataFrameremoved in the next major release.

unusual_state_sequence​

methodsource
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
NameTypeDescriptionDefault
n_statesintNumber of states to infer.2
expected_orderlist[int] | NoneList of state IDs defining the expected cycle. If None, the most frequent bigram transitions are treated as "normal".None
interval_endstrHow intervals end, see :meth:infer_states (transition times do not depend on it).'next_change'
Returns
TypeDescription
DataFrameDataFrame with columns: transition_time, from_state,
DataFrameto_state, from_label, to_label, is_unusual.

dwell_time_violation​

methodsource
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
NameTypeDescriptionDefault
stateintState ID to check (0-based).required
max_durationstrMaximum allowed duration (e.g. '5min').required
n_statesintNumber of states to infer.2
interval_endstrHow intervals end, see :meth:infer_states.'next_change'
Returns
TypeDescription
DataFrameDataFrame with columns: start, end, state_label,
DataFrameduration_seconds, excess_seconds, uuid (event uuid), source_uuid
DataFrame(signal uuid).