Skip to main content
Version: Next

ts_shape.events.profiling.control_loops

Mapping-free control-loop profiler: find the loops, rank their health.

:class:ControlLoopProfileEvents needs no machine cycle and no names. It reads the numeric signals of one controller and:

  • finds setpoints: signals that hold their value for minutes between steps (judged on their own readings, so polled and on-change logging both work);
  • pairs each setpoint with the continuous signal that follows its steps (moves in the step's direction by a good part of it) and tracks it the rest of the time; the pairing is one-to-one, best score first;
  • finds the output (optional): the continuous signal that moves at once (within KICK_SAMPLES grid samples) and consistently with the setpoint steps -- the controller's reaction; a signal that reacts at once is never taken for the process value, which reacts only after its dead time;
  • measures every loop with :class:~ts_shape.events.engineering.setpoint_events.SetpointChangeEvents (settling, rise, overshoot, oscillation per step) and :class:~ts_shape.events.engineering.control_loop_health.ControlLoopHealthEvents (IAE, output saturation);
  • diagnoses oscillating (overshoot and repeated crossings, or a settling loop that overshoots by 30 % and more), sluggish (most steps do not settle in time) or ok, and ranks the loops by a health score (mean percentile rank of the badness metrics).

A loop with fewer than min_steps steps gets steady-state metrics only (too_few_units).

Classes
NameDescription
ControlLoopProfileEventsFind the control loops among the signals and rank their health.

ControlLoopProfileEvents​

classsource
ControlLoopProfileEvents(
dataframe: pd.DataFrame,
*,
signal_uuids: list[str] | None = None,
min_steps: int = 5,
settle_pct: float = 0.1,
time_column: str = "systime",
uuid_column: str = "uuid",
value_column: str = "value_double",
event_uuid: str = "eng:control_loop_profile"
) -> None

Bases: _ProfilerBase

Find the control loops among the signals and rank their health.

Example
>>> import ts_shape
>>> frame, truth = ts_shape.make_control_loops(seed=1)
>>> loops = ts_shape.ControlLoopProfileEvents(frame).loop_register()
>>> dict(zip(loops["setpoint_uuid"], loops["diagnosis"]))["plc:tic102_sp"]
'oscillating'
Functions
NameDescription
loop_pairsThe control loops found among the signals.
loop_stepsResponse metrics of every setpoint step of every loop.
loop_registerHealth of every loop, worst first.
evaluation_windowWhether each loop's metrics can be trusted, and why not.
summaryHeadline numbers (JSON-able).
Parameters
NameTypeDescriptionDefault
dataframeDataFrameLong-format signals of one controller or PLC.required
signal_uuidslist[str] | NoneSignals to use (default: all numeric ones).None
min_stepsintSetpoint steps a loop needs for step metrics.5
settle_pctfloatSettling band as a share of each step.0.1
time_columnstrTimestamp column.'systime'
uuid_columnstrSignal column.'uuid'
value_columnstrNumeric value column.'value_double'
event_uuidstruuid of the step records.'eng:control_loop_profile'

loop_pairs​

methodsource
loop_pairs() -> pd.DataFrame

The control loops found among the signals.

Returns
TypeDescription
DataFrameOne row per loop: setpoint_uuid, actual_uuid,
DataFrameoutput_uuid (None when no output reacts), step_count,
DataFramestep_follow_ratio, tracking_ratio, pair_score and
DataFrameoutput_consistency_ratio.

loop_steps​

methodsource
loop_steps() -> pd.DataFrame

Response metrics of every setpoint step of every loop.

Returns
TypeDescription
DataFrameOne row per step (loops with at least min_steps steps):
DataFrameloop plus the columns of
DataFramemeth:`SetpointChangeEvents.control_quality_metrics
DataFrame<ts_shape.events.engineering.setpoint_events.SetpointChangeEvents.control_quality_metrics>`.

loop_register​

methodsource
loop_register() -> pd.DataFrame

Health of every loop, worst first.

Returns
TypeDescription
DataFrameOne row per loop: loop, setpoint_uuid, actual_uuid,
DataFrameoutput_uuid, step_count, settled_share_ratio,
DataFramemedian_settle_seconds, median_overshoot_pct,
DataFramemedian_oscillation_count, iae_per_hour_spans (IAE per
DataFramehour in setpoint spans), tracking_ratio,
DataFramesaturated_share_ratio, mean_abs_error, diagnosis
DataFrame(oscillating / sluggish / ok / unknown),
DataFramehealth_score (0 worst .. 1 best) and health_rank
DataFrame(1 = worst).

evaluation_window​

methodsource
evaluation_window() -> pd.DataFrame

Whether each loop's metrics can be trusted, and why not.

Returns
TypeDescription
DataFrameOne row per loop (or one all row without any): scope,
DataFrameunit_count (setpoint steps), evaluable, reason,
DataFrametime_resolution_seconds (the common grid period) and
DataFramelookahead_seconds (the response window).

summary​

methodsource
summary() -> dict[str, Any]

Headline numbers (JSON-able).

Returns
TypeDescription
dict[str, Any]evaluable (at least one loop is), reason, loop_count,
dict[str, Any]diagnoses (count per diagnosis) and worst_loop.