Skip to main content
Version: Next

ts_shape.events.development.recipe_phase_adherence

Recipe-phase adherence: check each batch phase against a spec.

Batch processes execute a sequence of named phases (heat-up, hold, cool-down, ...). Each phase has a development-defined spec: an expected duration window, a hold-value window, a maximum ramp rate, sometimes a peak ceiling. This detector iterates the phase intervals in a batch and emits one event per phase carrying pass/fail plus which criterion failed.

The spec format is intentionally a plain dict so it can be authored by a process engineer (or loaded from YAML/JSON) without inventing a new schema class -- see :meth:evaluate for the recognized keys.

Classes
NameDescription
RecipePhaseAdherenceEventsEvaluate batch recipe phases against a declarative spec.

RecipePhaseAdherenceEvents​

classsource
RecipePhaseAdherenceEvents(
dataframe: pd.DataFrame,
phase_uuid: str,
value_uuid: str,
spec: dict[str, dict[str, Any]],
*,
event_uuid: str = "dev:recipe_phase_adherence",
value_column: str = "value_double",
time_column: str = "systime"
) -> None

Bases: Base

Evaluate batch recipe phases against a declarative spec.

The spec is a mapping {phase_name: criteria_dict}. Recognized criteria keys (all optional) per phase:

  • duration_seconds -- (min, max) seconds. duration_s is the deprecated spelling of the same criterion: it still works, with a DeprecationWarning, until the next major release (giving both for one phase raises ValueError); criteria_failed names the key the spec used.
  • hold_value -- (min, max) for the mean value during the phase.
  • ramp_rate_max -- maximum absolute slope (value-units per second) computed from the first to the last sample.
  • peak_value -- (min, max) for the phase max.
  • trough_value -- (min, max) for the phase min.

Missing criteria are not checked. A phase whose name is absent from the spec is reported with pass=True and an empty criteria_failed list (the phase was observed but not constrained).

Functions
NameDescription
evaluateEvaluate every observed phase interval against the spec.
Parameters
NameTypeDescriptionDefault
dataframeDataFrameLong-format timeseries frame (one row per sample, uuid identifies the signal).required
phase_uuidstrUUID of the signal holding the active phase name.required
value_uuidstrUUID of the process value evaluated per phase.required
specdict[str, dict[str, Any]]Mapping of phase name to criteria dict (see the class docstring for the recognized keys).required
event_uuidstrUUID stamped on emitted events.'dev:recipe_phase_adherence'
value_columnstrColumn holding the signal values.'value_double'
time_columnstrTimestamp column.'systime'

evaluate​

methodsource
evaluate(
*, interval_end: str = "next_change", data_end: pd.Timestamp | None = None
) -> pd.DataFrame

Evaluate every observed phase interval against the spec.

Parameters
NameTypeDescriptionDefault
interval_endstrHow each phase interval is closed. "next_change" (default) closes a phase at the next phase change; value samples are taken from start, end) (the sample at the transition belongs to the next phase), and the final phase is closed at data_end when given, otherwise at its own last sample. "last_sample" spans the first to the last phase-signal sample carrying the phase; on a change-encoded (is_delta) phase signal, which logs one row per transition, every phase is then zero-length.'next_change'
data_end[Timestamp | NoneOptional bound for the final phase when interval_end="next_change" (e.g. the batch end).None
Returns
NameTypeDescription
DataFrameInterval-shape DataFrame, one row per phase occurrence,
columnsDataFramestart, end, duration_seconds, uuid,
DataFramephase, mean_value, min_value, max_value,
DataFrameobserved_ramp_per_s, criteria_failed (list[str]),
DataFramepass.