Skip to content

tolerance_deviation

tolerance_deviation ¤

ToleranceDeviationEvents ¤

ToleranceDeviationEvents(
    dataframe: DataFrame,
    tolerance_column: str,
    actual_column: str,
    tolerance_uuid: Optional[str] = None,
    actual_uuid: str = None,
    event_uuid: str = None,
    compare_func: Callable[
        [Series, Series], Series
    ] = operator.ge,
    time_threshold: str = "5min",
    upper_tolerance_uuid: Optional[str] = None,
    lower_tolerance_uuid: Optional[str] = None,
    warning_threshold: float = 0.8,
    tolerance_lag: str = "0s",
)

Bases: Base

Inherits from Base and processes DataFrame data for specific events, comparing tolerance and actual values.

Enhanced features: - Separate upper and lower tolerances - Warning zones with configurable thresholds - Deviation magnitude tracking (absolute and percentage) - Severity level classification (minor, major, critical) - Process capability indices (Cp, Cpk, Pp, Ppk) - Time-lagged tolerance application

Initializes the ToleranceDeviationEvents with specific event attributes. Inherits the sorted dataframe from the Base class.

Parameters:

Name Type Description Default
dataframe DataFrame

Input DataFrame with measurement data

required
tolerance_column str

Column name containing tolerance values

required
actual_column str

Column name containing actual measurement values

required
tolerance_uuid Optional[str]

UUID for tolerance (backward compatibility, used if upper/lower not specified)

None
actual_uuid str

UUID for actual measurements

None
event_uuid str

UUID for generated events

None
compare_func Callable[[Series, Series], Series]

Comparison function (default: operator.ge for greater-than-or-equal)

ge
time_threshold str

Time window for grouping events (default: '5min')

'5min'
upper_tolerance_uuid Optional[str]

UUID for upper tolerance limit (optional)

None
lower_tolerance_uuid Optional[str]

UUID for lower tolerance limit (optional)

None
warning_threshold float

Threshold ratio for warning zone (default: 0.8 = 80% of tolerance)

0.8
tolerance_lag str

Time lag for tolerance application (default: '0s')

'0s'

process_and_group_data_with_events ¤

process_and_group_data_with_events() -> pd.DataFrame

Processes DataFrame to apply tolerance checks, group events by time, and generate an events DataFrame.

Enhanced with: - Separate upper/lower tolerances - Deviation magnitude tracking (absolute and percentage) - Warning zones - Severity level classification - Time-lagged tolerance application

Returns:

Type Description
DataFrame

pd.DataFrame: A DataFrame of processed and grouped event data with enhanced metrics.

compute_capability_indices ¤

compute_capability_indices(
    target_value: Optional[float] = None,
) -> Dict[str, float]

Calculate process capability indices (Cp, Cpk, Pp, Ppk).

Process capability indices measure how well a process meets specification limits: - Cp: Process capability (potential capability assuming perfect centering) - Cpk: Process capability index (accounts for process centering) - Pp: Process performance (overall variability) - Ppk: Process performance index (accounts for centering)

Parameters:

Name Type Description Default
target_value Optional[float]

Target/nominal value for the process. If None, uses midpoint of tolerances.

None

Returns:

Type Description
Dict[str, float]

Dictionary containing: - 'Cp': Process capability - 'Cpk': Process capability index - 'Pp': Process performance - 'Ppk': Process performance index - 'mean': Process mean - 'std': Process standard deviation - 'usl': Upper specification limit - 'lsl': Lower specification limit - 'target': Target value used

Note
  • Cp/Cpk use short-term variation (within-subgroup)
  • Pp/Ppk use long-term variation (overall)
  • Values > 1.33 are generally considered acceptable
  • Values > 1.67 are considered good