ts_shape.events.profiling.stops
Mapping-free stop profiling: why does the machine stop, what does it cost?
:class:StopProfileEvents takes the raw signals of one PLC -- no run-state
or alarm mapping -- and answers which stop causes cost the most time?
- Units. With a cycle anchor (see
:class:
~ts_shape.events.profiling.cycles.CycleProfileEvents) everypausecycle is a stop and everylongcycle a micro-stop; the lost time is the duration beyond the variant's median cycle and the stop is taken to start where the cycle should have ended. Without an anchor (a continuous line) the stops are the off-periods of a discovered run signal: a bool or state value during which a counter keeps counting. Stops that overlap a hole in which no signal logged anything areunknowntime, not stops. - Signatures. The events in a window before each stop are compared with
the same windows in normal running (:func:
~ts_shape.events.production. _unit_profile.enrichment): an event that is much more frequent before stops (lift >= :data:SIGNATURE_MIN_LIFT, q < 0.05) is a stop signature. Each stop gets the earliest of them in its window (first-out); without one, a state that is enriched during stops (door open, manual mode); otherwiseunexplained. - Register. Per signature: count, lost time and its share, MTTR (median, P10, P90), MTBF and the potential (lost time beyond the signature's P10).
Classes
| Name | Description |
|---|---|
StopProfileEvents | Stops and their causes, learned from the raw signals of one PLC. |
StopProfileEvents
StopProfileEvents(
dataframe: pd.DataFrame,
*,
cycle_profile: CycleProfileEvents | None = None,
signal_uuids: list[str] | None = None,
pre_window: str | float | None = None,
min_stops: int = 10,
include_micro_stops: bool = True,
time_column: str = "systime",
uuid_column: str = "uuid",
event_uuid: str = "prod:stop_profile",
**cycle_options: Any
) -> None
Bases: _UnitProfiler
Stops and their causes, learned from the raw signals of one PLC.
Example
>>> import ts_shape
>>> frame, truth = ts_shape.make_plc_cycles(
... n_cycles=300, seed=3, stop_causes=4, stop_probability=0.08)
>>> stops = ts_shape.StopProfileEvents(frame)
>>> bool(stops.evaluation_window()["evaluable"].iloc[0])
True
Functions
| Name | Description |
|---|---|
stop_records | One record per stop (and micro-stop), with its signature. |
stop_signatures | The stop register: what each signature costs. |
signature_evidence | Why each event counts as a stop signature (or not). |
evaluation_window | Whether the stop profile can be trusted, and why not. |
summary | Headline numbers (JSON-able). |
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
dataframe | DataFrame | Long-format signals of one PLC (systime, uuid, value_*). | required |
cycle_profile | CycleProfileEvents | None | A computed cycle profile of the same signals to reuse; None (default) builds one. | None |
signal_uuids | list[str] | None | Signals to use (default: all). | None |
pre_window | str | float | None | Length of the window before a stop in which its cause is looked for (offset string or seconds); default: one median cycle, at least :data:STOP_PRE_MIN_SECONDS. | None |
min_stops | int | Fewer stops are not evaluable. | 10 |
include_micro_stops | bool | Treat long cycles as micro-stops (their time beyond the median is lost time). | True |
time_column | str | Timestamp column. | 'systime' |
uuid_column | str | Signal column. | 'uuid' |
event_uuid | str | uuid of the stop records. | 'prod:stop_profile' |
**cycle_options | Any | Options of the cycle profile built when cycle_profile is None (n_sigma, pause_factor ...). | {} |
stop_records
stop_records() -> pd.DataFrame
One record per stop (and micro-stop), with its signature.
Returns
| Type | Description |
|---|---|
DataFrame | Point events at the stop end: systime, uuid, |
DataFrame | source_uuid, unit_uuid, start_ns (estimated stop |
DataFrame | start), end_ns, duration_seconds (of the stop), |
DataFrame | stop_class (stop / micro_stop), variant, |
DataFrame | lost_seconds, signature (the first-out event, a held |
DataFrame | state, unexplained or data_hole), signature_kind and |
DataFrame | preceding_events (every signature event in the pre-window). |
stop_signatures
stop_signatures() -> pd.DataFrame
The stop register: what each signature costs.
Returns
| Type | Description |
|---|---|
DataFrame | One row per signature (data_hole stops are left out): |
DataFrame | signature, signature_kind, stop_count, |
DataFrame | lost_seconds, lost_share_ratio (of all lost time), |
DataFrame | mttr_median_seconds / mttr_p10_seconds / |
DataFrame | mttr_p90_seconds (stop durations), mtbf_seconds (median |
DataFrame | time between two stops of the signature), stops_per_hour, |
DataFrame | potential_seconds (lost time beyond the signature's P10 |
DataFrame | stop), lift_factor and q_value (evidence) and |
DataFrame | potential_rank, most potential first. |
signature_evidence
signature_evidence() -> pd.DataFrame
Why each event counts as a stop signature (or not).
Returns
| Type | Description |
|---|---|
DataFrame | func:~ts_shape.events.profiling._base.enrichment of |
DataFrame | the pre-stop windows (window="before") and of the stop |
DataFrame | intervals (window="during") against normal running: |
DataFrame | window, label, unit_count, unit_presence_ratio, |
DataFrame | baseline_presence_ratio, lift_factor, p_value, |
DataFrame | q_value, is_significant. |
evaluation_window
evaluation_window() -> pd.DataFrame
Whether the stop profile can be trusted, and why not.
Returns
| Type | Description |
|---|---|
DataFrame | One row: scope (all), unit_count (stops outside data |
DataFrame | holes), evaluable, reason (ok, too_few_units, |
DataFrame | below_resolution (judged on the stops' own durations, so a |
DataFrame | cycle signal too coarse for cycle times still marks minutes-long |
DataFrame | stops) or no_candidate_signal: run state without an anchor |
DataFrame | and a run signal), |
DataFrame | time_resolution_seconds, source (cycles or the run |
DataFrame | signal), explained_share_ratio (lost time with a signature) |
DataFrame | and unknown_seconds (stops inside data holes). |
summary
summary() -> dict[str, Any]
Headline numbers (JSON-able).
Returns
| Type | Description |
|---|---|
dict[str, Any] | evaluable, reason, stop_count, lost_hours, |
dict[str, Any] | explained_share_ratio, top_signature and |
dict[str, Any] | top_signature_lost_hours. |