Skip to main content
Version: 0.0.98

ts_shape.events.quality.capability_trending

Classes
NameDescription
CapabilityTrendingEventsQuality: Process Capability Trending

CapabilityTrendingEvents​

classsource
CapabilityTrendingEvents(
dataframe: pd.DataFrame,
signal_uuid: str,
*,
upper_spec: float | None = None,
lower_spec: float | None = None,
upper_spec_uuid: str | None = None,
lower_spec_uuid: str | None = None,
value_column: str = "value_double",
event_uuid: str = "quality:capability_trend",
time_column: str = "systime",
sigma_method: SigmaMethod = "moving_range"
) -> None

Bases: Base

Quality: Process Capability Trending

Track process capability indices (Cp, Cpk, Pp, Ppk) over rolling time windows to detect capability degradation before quality escapes occur.

Specification limits can be provided as fixed floats or as UUIDs referencing signal rows in the DataFrame (matching the ToleranceDeviationEvents pattern).

Sigma (AIAG SPC manual; Montgomery, Introduction to Statistical Quality Control, section 8.3), per window:

  • Cp = (USL - LSL) / 6 sigma_within, Cpk = min(USL - mean, mean - LSL) / 3 sigma_within, with the within (short-term) sigma MR-bar / 1.128 of consecutive samples in the window (sigma_method="moving_range", default);
  • Pp / Ppk: the same formulas with the window's overall sample standard deviation s (ddof=1).

sigma_method="std" uses s for Cp/Cpk as well (Cp = Pp, the earlier Cp/Cpk). Before October 2026, Pp/Ppk combined the window mean with the standard deviation of the whole signal (later windows included); they now use only the window's own data.

Methods:

  • capability_over_time: Cp/Cpk/Pp/Ppk per time window.
  • detect_capability_drop: Alert when Cpk falls below threshold.
  • capability_forecast: Extrapolate Cpk trend to predict threshold breach.
  • yield_estimate: Estimated yield, DPMO, and sigma level per window.
Example
>>> import ts_shape
>>> df = ts_shape.make_timeseries(["dia"], n_points=960, freq="1min", drift=3.0)
>>> cap = ts_shape.CapabilityTrendingEvents(df, "dia", upper_spec=105, lower_spec=95)
>>> out = cap.capability_over_time(window="8h")
>>> out[["start", "cpk", "ppk"]].round({"cpk": 2, "ppk": 2})
start cpk ppk
0 2025-01-01 00:00:00 1.56 1.33
1 2025-01-01 08:00:00 0.94 0.83
Functions
NameDescription
capability_over_timeCompute Cp, Cpk, Pp, Ppk per time window.
detect_capability_dropDetect windows where Cpk drops below threshold or degrades significantly.
capability_forecastExtrapolate Cpk trend to predict when it will breach threshold.
yield_estimateEstimate yield, DPMO, and sigma level per window.
Parameters
NameTypeDescriptionDefault
dataframeDataFrameLong-format timeseries frame (one row per sample, uuid identifies the signal).required
signal_uuidstrUUID of the signal to analyze.required
upper_specfloat | NoneFixed upper specification limit. Required unless upper_spec_uuid is given.None
lower_specfloat | NoneFixed lower specification limit. Required unless lower_spec_uuid is given. Must be below upper_spec.None
upper_spec_uuidstr | NoneUUID of a signal holding the upper limit (required unless upper_spec is given).None
lower_spec_uuidstr | NoneUUID of a signal holding the lower limit (required unless lower_spec is given).None
value_columnstrColumn holding the signal values.'value_double'
event_uuidstrUUID stamped on emitted events.'quality:capability_trend'
time_columnstrTimestamp column.'systime'
sigma_methodSigmaMethod"moving_range" (default) or "std": the within sigma used for Cp/Cpk (see the class docstring).'moving_range'

capability_over_time​

methodsource
capability_over_time(window: str = '8h') -> pd.DataFrame

Compute Cp, Cpk, Pp, Ppk per time window.

Each window uses only its own samples (see the class docstring): Cp/Cpk from the within sigma (MR-bar / 1.128 of consecutive samples; the window's s with sigma_method="std"), Pp/Ppk from the window's sample standard deviation s (ddof=1).

Parameters
NameTypeDescriptionDefault
windowstrResample window size.'8h'
Returns
TypeDescription
DataFrameDataFrame with columns: start, end, duration_seconds, uuid,
DataFramesource_uuid, cp, cpk, pp, ppk, mean, std (the window's s),
DataFramestd_within (the sigma behind cp/cpk), n_samples.
DataFrameend is start plus one window. Windows with fewer than
DataFrametwo samples are skipped. Without spread (constant values) the
DataFrameindices are NaN; a signal without any spread also emits a
DataFrameclass:~ts_shape.errors.DataQualityWarning.
DataFrameCanonical twin columns: sample_count (after n_samples); each holds
DataFramethe same values as the deprecated column right before it, which is removed
DataFramein the next major release.

detect_capability_drop​

methodsource
detect_capability_drop(
window: str = "8h", min_cpk: float = 1.33, lookback: int = 5
) -> pd.DataFrame

Detect windows where Cpk drops below threshold or degrades significantly.

Parameters
NameTypeDescriptionDefault
windowstrResample window size.'8h'
min_cpkfloatMinimum acceptable Cpk value.1.33
lookbackintNumber of previous windows for rolling average comparison.5
Returns
TypeDescription
DataFrameDataFrame with columns: start, end, duration_seconds, uuid,
DataFramesource_uuid, cpk, prev_avg_cpk, drop_pct, alert.
DataFrameend is start plus one window.

capability_forecast​

methodsource
capability_forecast(
window: str = "8h", horizon: int = 5, threshold: float = 1.33
) -> pd.DataFrame

Extrapolate Cpk trend to predict when it will breach threshold.

Parameters
NameTypeDescriptionDefault
windowstrResample window size.'8h'
horizonintNumber of future windows to forecast.5
thresholdfloatCpk threshold to predict breach for.1.33
Returns
TypeDescription
DataFrameDataFrame with columns: start, end, duration_seconds, uuid,
DataFramesource_uuid, cpk, trend_slope, forecast_cpk,
DataFramewindows_to_threshold. end is start plus one window.

yield_estimate​

methodsource
yield_estimate(window: str = '8h') -> pd.DataFrame

Estimate yield, DPMO, and sigma level per window.

Assumes normal distribution within each window.

Parameters
NameTypeDescriptionDefault
windowstrResample window size.'8h'
Returns
TypeDescription
DataFrameDataFrame with columns: start, end, duration_seconds, uuid,
DataFramesource_uuid, estimated_yield_pct, dpmo, sigma_level.
DataFrameend is start plus one window.