Skip to main content
Version: 0.0.98

ts_shape.events.maintenance.degradation_detection

Classes
NameDescription
DegradationDetectionEventsDetect degradation patterns in time series signals: trend degradation,

DegradationDetectionEvents​

classsource
DegradationDetectionEvents(
dataframe: pd.DataFrame,
signal_uuid: str,
*,
event_uuid: str = "maint:degradation",
value_column: str = "value_double",
time_column: str = "systime"
) -> None

Bases: Base

Detect degradation patterns in time series signals: trend degradation, variance increases, level shifts, and composite health scores.

Designed for predictive maintenance on manufacturing/industrial IoT data.

Functions
NameDescription
detect_trend_degradationDetect intervals where a rolling linear regression slope exceeds min_slope
detect_variance_increaseCompare rolling variance against a baseline (first window) and flag
detect_level_shiftCUSUM-like detection for permanent mean shifts in the signal.
health_scoreComposite 0-100 health score based on mean drift, variance change,
Parameters
NameTypeDescriptionDefault
dataframeDataFrameLong-format timeseries frame (one row per sample, uuid identifies the signal).required
signal_uuidstrUUID of the signal to analyze; must be present in dataframe.required
event_uuidstrUUID stamped on emitted events.'maint:degradation'
value_columnstrColumn holding the signal values.'value_double'
time_columnstrTimestamp column.'systime'

detect_trend_degradation​

methodsource
detect_trend_degradation(
window: str = "1h",
min_slope: float = 0.0,
direction: str = "decreasing",
*,
interval_end: str = "next_change"
) -> pd.DataFrame

Detect intervals where a rolling linear regression slope exceeds min_slope in the given direction, indicating trend-based degradation.

Parameters
NameTypeDescriptionDefault
windowstrRolling window size (e.g. '1h', '30min').'1h'
min_slopefloatMinimum absolute slope to consider degradation.0.0
directionstr'decreasing' (negative slope) or 'increasing' (positive slope).'decreasing'
interval_endstr"next_change" (default) ends an interval at the next sample (the transition), so the interval spans the time the condition held and change-encoded signals -- one row per change -- keep their duration. "last_sample" ends it at its last flagged sample. See :func:ts_shape.utils.intervals.interval_end_times.'next_change'
Returns
TypeDescription
DataFrameDataFrame with columns: start, end, uuid, source_uuid, is_delta,
DataFrameavg_slope, total_change, duration_seconds. source_uuid is the
DataFrameanalyzed signal.

detect_variance_increase​

methodsource
detect_variance_increase(
window: str = "1h",
threshold_factor: float = 2.0,
*,
interval_end: str = "next_change"
) -> pd.DataFrame

Compare rolling variance against a baseline (first window) and flag intervals where the ratio exceeds threshold_factor.

The baseline is [first sample, first sample + window), the same number of samples as each rolling (t - window, t] window of a regular signal, so a stationary signal has ratio 1. Samples inside the baseline window are not flagged (their rolling windows are the partial warm-up of the baseline).

Parameters
NameTypeDescriptionDefault
windowstrRolling window size.'1h'
threshold_factorfloatMinimum variance ratio to flag.2.0
interval_endstr"next_change" (default) ends an interval at the next sample (the transition), so the interval spans the time the condition held and change-encoded signals -- one row per change -- keep their duration. "last_sample" ends it at its last flagged sample. See :func:ts_shape.utils.intervals.interval_end_times.'next_change'
Returns
TypeDescription
DataFrameDataFrame with columns: start, end, uuid, source_uuid, is_delta,
DataFramebaseline_variance, current_variance, ratio, duration_seconds
DataFrame(float seconds from start to end).

detect_level_shift​

methodsource
detect_level_shift(min_shift: float, hold: str = '5min') -> pd.DataFrame

CUSUM-like detection for permanent mean shifts in the signal.

Parameters
NameTypeDescriptionDefault
min_shiftfloatMinimum absolute shift magnitude to detect.required
holdstrMinimum duration the new level must persist.'5min'
Returns
TypeDescription
DataFrameDataFrame with columns: systime, uuid, source_uuid, is_delta,
DataFrameshift_magnitude, prev_mean, new_mean.

health_score​

methodsource
health_score(window: str = '1h', baseline_window: str = '24h') -> pd.DataFrame

Composite 0-100 health score based on mean drift, variance change, and trend slope, computed over rolling windows.

Parameters
NameTypeDescriptionDefault
windowstrRolling window for current metrics.'1h'
baseline_windowstrInitial period used to establish baseline behavior: first sample, first sample + baseline_window), half-open like the rolling windows.'24h'
Returns
TypeDescription
[DataFrameDataFrame with columns: systime, uuid, source_uuid, is_delta,
DataFramehealth_score, mean_drift_pct, variance_ratio, variance_factor
DataFrame(current / baseline variance; above 1 when the variance grew),
DataFrametrend_slope.
DataFrameCanonical twin columns: variance_factor (after
DataFramevariance_ratio, which is not a 0-1 fraction); it holds the
DataFramesame values as the deprecated column right before it, which is
DataFrameremoved in the next major release.