ts_shape.events.quality.statistical_process_control
¤
Classes:
-
StatisticalProcessControlRuleBased
–Inherits from Base and applies SPC rules (Western Electric Rules) to a DataFrame for event detection.
StatisticalProcessControlRuleBased
¤
StatisticalProcessControlRuleBased(dataframe: DataFrame, value_column: str, tolerance_uuid: str, actual_uuid: str, event_uuid: str)
Bases: Base
Inherits from Base and applies SPC rules (Western Electric Rules) to a DataFrame for event detection. Processes data based on control limit UUIDs, actual value UUIDs, and generates events with an event UUID.
Parameters:
-
dataframe
¤DataFrame
) –The input DataFrame containing the data to be processed.
-
value_column
¤str
) –The column containing the values to monitor.
-
tolerance_uuid
¤str
) –UUID identifier for rows that set tolerance values.
-
actual_uuid
¤str
) –UUID identifier for rows containing actual values.
-
event_uuid
¤str
) –UUID to assign to generated events.
Methods:
-
calculate_control_limits
–Calculate the control limits (mean ± 1σ, 2σ, 3σ) for the tolerance values.
-
get_dataframe
–Returns the processed DataFrame.
-
process
–Applies the selected SPC rules and generates a DataFrame of events where any rules are violated.
-
rule_1
–Rule 1: One point beyond the 3σ control limits.
-
rule_2
–Rule 2: Nine consecutive points on one side of the mean.
-
rule_3
–Rule 3: Six consecutive points steadily increasing or decreasing.
-
rule_4
–Rule 4: Fourteen consecutive points alternating up and down.
-
rule_5
–Rule 5: Two out of three consecutive points near the control limit (beyond 2σ but within 3σ).
-
rule_6
–Rule 6: Four out of five consecutive points near the control limit (beyond 1σ but within 2σ).
-
rule_7
–Rule 7: Fifteen consecutive points within 1σ of the centerline.
-
rule_8
–Rule 8: Eight consecutive points on both sides of the mean within 1σ.
Source code in src/ts_shape/events/quality/statistical_process_control.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
|
calculate_control_limits
¤
calculate_control_limits() -> DataFrame
Calculate the control limits (mean ± 1σ, 2σ, 3σ) for the tolerance values.
Returns:
-
DataFrame
–pd.DataFrame: DataFrame with control limits for each tolerance group.
Source code in src/ts_shape/events/quality/statistical_process_control.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
|
get_dataframe
¤
get_dataframe() -> DataFrame
Returns the processed DataFrame.
Source code in src/ts_shape/utils/base.py
34 35 36 |
|
process
¤
process(selected_rules: Optional[List[str]] = None) -> DataFrame
Applies the selected SPC rules and generates a DataFrame of events where any rules are violated.
Parameters:
-
selected_rules
¤Optional[List[str]]
, default:None
) –List of rule names (e.g., ['rule_1', 'rule_3']) to apply.
Returns:
-
DataFrame
–pd.DataFrame: DataFrame with rule violations and detected events.
Source code in src/ts_shape/events/quality/statistical_process_control.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
|
rule_1
¤
rule_1(df: DataFrame, limits: DataFrame) -> DataFrame
Rule 1: One point beyond the 3σ control limits.
Returns:
-
DataFrame
–pd.DataFrame: Filtered DataFrame with rule violations.
Source code in src/ts_shape/events/quality/statistical_process_control.py
53 54 55 56 57 58 59 60 61 |
|
rule_2
¤
rule_2(df: DataFrame) -> DataFrame
Rule 2: Nine consecutive points on one side of the mean.
Returns:
-
DataFrame
–pd.DataFrame: Filtered DataFrame with rule violations.
Source code in src/ts_shape/events/quality/statistical_process_control.py
63 64 65 66 67 68 69 70 71 72 73 74 |
|
rule_3
¤
rule_3(df: DataFrame) -> DataFrame
Rule 3: Six consecutive points steadily increasing or decreasing.
Returns:
-
DataFrame
–pd.DataFrame: Filtered DataFrame with rule violations.
Source code in src/ts_shape/events/quality/statistical_process_control.py
76 77 78 79 80 81 82 83 84 85 86 |
|
rule_4
¤
rule_4(df: DataFrame) -> DataFrame
Rule 4: Fourteen consecutive points alternating up and down.
Returns:
-
DataFrame
–pd.DataFrame: Filtered DataFrame with rule violations.
Source code in src/ts_shape/events/quality/statistical_process_control.py
88 89 90 91 92 93 94 95 96 97 |
|
rule_5
¤
rule_5(df: DataFrame, limits: DataFrame) -> DataFrame
Rule 5: Two out of three consecutive points near the control limit (beyond 2σ but within 3σ).
Returns:
-
DataFrame
–pd.DataFrame: Filtered DataFrame with rule violations.
Source code in src/ts_shape/events/quality/statistical_process_control.py
99 100 101 102 103 104 105 106 107 108 109 110 111 |
|
rule_6
¤
rule_6(df: DataFrame, limits: DataFrame) -> DataFrame
Rule 6: Four out of five consecutive points near the control limit (beyond 1σ but within 2σ).
Returns:
-
DataFrame
–pd.DataFrame: Filtered DataFrame with rule violations.
Source code in src/ts_shape/events/quality/statistical_process_control.py
113 114 115 116 117 118 119 120 121 122 123 124 125 |
|
rule_7
¤
rule_7(df: DataFrame, limits: DataFrame) -> DataFrame
Rule 7: Fifteen consecutive points within 1σ of the centerline.
Returns:
-
DataFrame
–pd.DataFrame: Filtered DataFrame with rule violations.
Source code in src/ts_shape/events/quality/statistical_process_control.py
127 128 129 130 131 132 133 134 135 136 137 138 |
|
rule_8
¤
rule_8(df: DataFrame, limits: DataFrame) -> DataFrame
Rule 8: Eight consecutive points on both sides of the mean within 1σ.
Returns:
-
DataFrame
–pd.DataFrame: Filtered DataFrame with rule violations.
Source code in src/ts_shape/events/quality/statistical_process_control.py
140 141 142 143 144 145 146 147 148 149 150 151 |
|