ts_shape.events.engineering.startup_events
Classes
StartupDetectionEvents(
dataframe: pd.DataFrame,
target_uuid: str,
*,
event_uuid: str = "eng:startup",
value_column: str = "value_double",
time_column: str = "systime"
) -> None
Bases: Base
Detect equipment startup intervals based on threshold crossings or
sustained positive slope in a numeric metric (speed, temperature, etc.).
Schema assumptions (columns):
- uuid, sequence_number, systime, plctime, is_delta
- value_integer, value_string, value_double, value_bool, value_bytes
Functions
Parameters
| Name | Type | Description | Default |
|---|
dataframe | DataFrame | Long-format timeseries frame (one row per sample, uuid identifies the signal). | required |
target_uuid | str | UUID of the metric (speed, temperature, ...) startups are detected on; must be present in dataframe. | required |
event_uuid | str | UUID stamped on emitted events. | 'eng:startup' |
value_column | str | Column holding the signal values. | 'value_double' |
time_column | str | Timestamp column. | 'systime' |
detect_startup_by_threshold(
*,
threshold: float,
hysteresis: tuple[float, float] | None = None,
min_above: str = "0s"
) -> pd.DataFrame
Startup begins at first crossing above threshold (or hysteresis enter)
and is valid only if the metric stays above the (exit) threshold for at
least min_above.
Parameters
| Name | Type | Description | Default |
|---|
threshold | float | Level in signal units; a startup starts where the signal rises to or above it. Reported in the threshold column. | required |
hysteresis | tuple[float, float] | None | Optional (enter, exit) pair that replaces threshold: the rising edge is detected against enter and the dwell is checked against exit. None uses threshold for both. | None |
min_above | str | Minimum time the signal must stay at or above the exit level after the crossing (pandas offset string). It also sets end (start + min_above). Default "0s". | '0s' |
Returns
| Type | Description |
|---|
DataFrame | DataFrame with columns: start, end, duration_seconds, uuid, |
DataFrame | source_uuid, is_delta, method, threshold. |
detect_startup_by_slope(
*, min_slope: float, slope_window: str = "0s", min_duration: str = "0s"
) -> pd.DataFrame
Startup intervals where per-second slope >= min_slope for at least
min_duration.
With the default slope_window="0s" the slope is the instantaneous
slope between consecutive samples. With a positive slope_window
the slope at each sample is taken over a trailing window: the change
from the latest sample at or before t - slope_window to the
current sample, divided by the actual elapsed seconds. Samples with
no sample that far back get no slope. A longer window smooths noise.
The slope at a sample describes the step from its reference sample
(the previous sample, or the one slope_window back) to it, so an
interval starts at the reference sample of its first ramping sample
-- the sample before the first fast step with the default
slope_window -- and ends at its last ramping sample. A single
fast step from t[i-1] to t[i] lasts t[i] - t[i-1].
Parameters
| Name | Type | Description | Default |
|---|
min_slope | float | Minimum slope in signal units per second. | required |
slope_window | str | Trailing window for the slope as a pandas offset string (default '0s': between consecutive samples). | '0s' |
min_duration | str | Minimum duration (pandas offset string) of a contiguous run of samples at or above min_slope, measured from the run's start to its end. | '0s' |
Returns
| Type | Description |
|---|
DataFrame | DataFrame with columns: start, end, duration_seconds, uuid, |
DataFrame | source_uuid, is_delta, method, min_slope, avg_slope. |
detect_startup_multi_signal(
signals: dict[str, dict[str, Any]],
logic: str = "all",
*,
time_tolerance: str = "30s"
) -> pd.DataFrame
Detect startups based on multiple signals with configurable AND/OR logic.
Parameters
| Name | Type | Description | Default |
|---|
signals | dict[str, dict[str, Any]] | Dict mapping uuid to detection config. Each config should contain: - 'method': 'threshold' or 'slope' - For threshold: 'threshold', optional 'hysteresis', 'min_above' - For slope: 'min_slope', optional 'slope_window', 'min_duration' | required |
logic | str | 'all' (AND - all signals must detect) or 'any' (OR - at least one) | 'all' |
time_tolerance | str | Maximum time difference between signals for 'all' logic | '30s' |
Returns
| Type | Description |
|---|
DataFrame | DataFrame with columns: start, end, uuid, is_delta, method, signals_triggered, signal_details |
detect_startup_adaptive(
*,
baseline_window: str | None = None,
sensitivity: float = 2.0,
min_above: str = "10s",
lookback_periods: int = 5
) -> pd.DataFrame
Detect startups using adaptive thresholds calculated from historical baseline data.
The baseline (mean and std) is computed from samples before each
point, so a rising value does not raise its own threshold.
Parameters
| Name | Type | Description | Default |
|---|
baseline_window | str | None | Time span of preceding samples for the baseline (e.g. '1h'). Default None uses the last lookback_periods samples instead. (This parameter used to default to '1h' but was ignored.) | None |
sensitivity | float | Multiplier for standard deviation (threshold = mean + sensitivity * std) | 2.0 |
min_above | str | Minimum time the value must stay above threshold | '10s' |
lookback_periods | int | Number of preceding samples for the baseline when baseline_window is None | 5 |
Returns
| Type | Description |
|---|
DataFrame | DataFrame with columns: start, end, duration_seconds, uuid, |
DataFrame | source_uuid, is_delta, method, adaptive_threshold, baseline_mean, |
DataFrame | baseline_std |
assess_startup_quality(
startup_events: pd.DataFrame,
*,
smoothness_window: int = 5,
anomaly_threshold: float = 3.0
) -> pd.DataFrame
Assess the quality of detected startup events.
Parameters
| Name | Type | Description | Default |
|---|
startup_events | DataFrame | DataFrame of detected startup events (must have 'start' and 'end' columns) | required |
smoothness_window | int | Window size for calculating smoothness metrics | 5 |
anomaly_threshold | float | Z-score threshold for detecting anomalies | 3.0 |
Returns
| Type | Description |
|---|
DataFrame | DataFrame with quality metrics for each startup: - duration: Total duration of startup - smoothness_score: Inverse of derivative variance (higher = smoother) - anomaly_flags: Number of anomalous points detected - value_change: Total change in value during startup - avg_rate: Average rate of change - max_value: Maximum value reached - stability_score: 1 / (1 + CV) of the values in the final 20% of the startup (at least its last two samples); 1.0 is perfectly flat. NaN when the startup holds fewer than two samples; 0.0 when the final mean is 0 (CV undefined). |
track_startup_phases(
phases: list[dict[str, Any]], *, min_phase_duration: str = "5s"
) -> pd.DataFrame
Track progression through defined startup phases.
Parameters
| Name | Type | Description | Default |
|---|
phases | list[dict[str, Any]] | List of phase definitions, each containing: - 'name': Phase name - 'condition': 'threshold', 'range', or 'slope' - For 'threshold': 'min_value' (value must be >= min_value) - For 'range': 'min_value' and 'max_value' (value in range) - For 'slope': 'min_slope' (slope must be >= min_slope) | required |
min_phase_duration | str | Minimum time to stay in phase to be considered valid | '5s' |
Returns
| Type | Description |
|---|
DataFrame | DataFrame with phase transitions: - phase_name: Name of the phase - phase_number: Sequential phase number (0-indexed) - start: Phase start time - end: Phase end time - duration: Time spent in phase - next_phase: Name of the next phase (None for last phase) - completed: Whether full startup sequence completed |
detect_failed_startups(
*,
threshold: float,
min_rise_duration: str = "5s",
max_completion_time: str = "5min",
completion_threshold: float | None = None,
required_stability: str = "10s"
) -> pd.DataFrame
Detect failed or aborted startup attempts.
A failed startup is identified when:
- Value rises above threshold for at least min_rise_duration
- But fails to reach completion_threshold within max_completion_time
- Or drops back below threshold before achieving required_stability
Parameters
| Name | Type | Description | Default |
|---|
threshold | float | Initial threshold that must be crossed to begin startup | required |
min_rise_duration | str | Minimum time above threshold to consider it a startup attempt | '5s' |
max_completion_time | str | Maximum time allowed to complete startup | '5min' |
completion_threshold | float | None | Target threshold for successful completion (default: 2x threshold) | None |
required_stability | str | Time that must be maintained at completion level | '10s' |
Returns
| Type | Description |
|---|
DataFrame | DataFrame with columns: systime (= start, the startup attempt), |
DataFrame | uuid, source_uuid, start, end, is_delta, method, failure_reason, |
DataFrame | max_value_reached, time_to_failure |