machine_state
machine_state ¤
MachineStateEvents ¤
MachineStateEvents(
dataframe: DataFrame,
run_state_uuid: str,
*,
event_uuid: str = "prod:run_idle",
value_column: str = "value_bool",
time_column: str = "systime",
value_range: (
tuple[float | None, float | None] | None
) = None,
specs: Mapping[str, SignalSpec] | None = None
)
Bases: Base
Production: Machine State
Detect run/idle transitions and intervals from a boolean state signal.
- MachineStateEvents: Run/idle state intervals and transitions.
- detect_run_idle: Intervalize run/idle states with optional min duration filter.
- transition_events: Point events on state changes (idle->run, run->idle).
Example
import pandas as pd, ts_shape t = pd.date_range("2025-01-01 08:00", periods=6, freq="10min") df = pd.DataFrame({"systime": t, "uuid": "run", ... "value_bool": [True, True, False, True, True, False]}) out = ts_shape.MachineStateEvents(df, "run").detect_run_idle() out[["start", "state", "duration_seconds"]] start state duration_seconds 0 2025-01-01 08:00:00 run 1200.0 1 2025-01-01 08:20:00 idle 600.0 2 2025-01-01 08:30:00 run 1200.0 3 2025-01-01 08:50:00 idle 0.0
detect_run_idle ¤
detect_run_idle(
min_duration: str = "0s",
*,
interval_end: str | None = None,
data_end: Timestamp | None = None
) -> pd.DataFrame
Return intervals labeled as 'run' or 'idle'.
- min_duration: discard intervals shorter than this duration.
- interval_end: how to close each interval.
"next_change"closes each interval at the next transition instant, which measures both dense and change-encoded (is_delta) signals."last_sample"ends an interval at its last sample; on a change-encoded signal (one row per transition) every interval then has zero duration. Default (None): follow the signal's spec whenspecs=was given (held states close at the next change, and gaps longer than the spec'smax_gapare "no data"), otherwise"next_change". - data_end: optional bound for the final, still-open interval when intervals close at the next change (e.g. the end of the data window). Columns: start, end, uuid, source_uuid, is_delta, state, duration_seconds
transition_events ¤
transition_events() -> pd.DataFrame
Return point events at state transitions.
Columns: systime, uuid, source_uuid, is_delta, transition ('idle_to_run'|'run_to_idle'), time_since_last_transition_seconds
detect_rapid_transitions ¤
detect_rapid_transitions(
threshold: str = "5s", min_count: int = 3
) -> pd.DataFrame
Identify suspicious rapid state changes.
- threshold: time window to look for rapid transitions
- min_count: minimum number of transitions within threshold to be considered rapid Returns: DataFrame with systime (= start, the first transition of the burst), uuid (event uuid), source_uuid (run-state uuid), start, end, transition_count, duration_seconds
state_quality_metrics ¤
state_quality_metrics(
*,
interval_end: str | None = ...,
data_end: Timestamp | None = ...,
as_frame: Literal[True] = ...
) -> pd.DataFrame
state_quality_metrics(
*,
interval_end: str | None = ...,
data_end: Timestamp | None = ...,
as_frame: Literal[False]
) -> dict[str, Any]
state_quality_metrics(
*,
interval_end: str | None = None,
data_end: Timestamp | None = None,
as_frame: bool = True
) -> pd.DataFrame | dict[str, Any]
Return quality metrics for the state data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interval_end
|
str | None
|
Forwarded to :meth: |
None
|
data_end
|
Timestamp | None
|
Forwarded to :meth: |
None
|
as_frame
|
bool
|
When True (default), return a one-row DataFrame (see
below). |
True
|
Returns:
| Type | Description |
|---|---|
DataFrame | dict[str, Any]
|
With |
DataFrame | dict[str, Any]
|
columns start, end, duration_seconds (the span of the state |
DataFrame | dict[str, Any]
|
signal; NaT / 0 without data), uuid (event uuid), source_uuid |
DataFrame | dict[str, Any]
|
(run-state uuid), followed by the metrics below. |
DataFrame | dict[str, Any]
|
With |
DataFrame | dict[str, Any]
|
|
DataFrame | dict[str, Any]
|
|
DataFrame | dict[str, Any]
|
|
DataFrame | dict[str, Any]
|
|
DataFrame | dict[str, Any]
|
|
DataFrame | dict[str, Any]
|
|