pub struct RuleSet { /* private fields */ }Expand description
A chosen subset of the run tests.
Each test reports exactly one ViolationType, so a rule is named by what
it would report rather than by a parallel enum that would have to be kept in
step with this one.
Three sets have names – shewhart (the 3-sigma test
alone, the default), western_electric and
nelson – and RuleSet::named looks them up by the
names a wire request uses; any other combination is built from the tests a
process actually warrants. A rule that a process is known to
trigger for a benign reason – a deliberately drifting tool, a bimodal
fixture – otherwise has to be filtered out downstream, after it has already
been counted as an out-of-control signal.
§Examples
use u_analytics::spc::{RuleSet, RunRule, ChartPoint, ControlLimits, ViolationType};
// Only the 3-sigma test, and nothing else.
let rules = RuleSet::from_iter([ViolationType::BeyondLimits]);
let limits = ControlLimits { ucl: 28.0, cl: 25.0, lcl: 22.0 };
let points: Vec<ChartPoint> = (0..12)
.map(|i| ChartPoint { value: 26.0, index: i, violations: vec![] })
.collect();
// Twelve points above the centre line would trip Nelson rule 2, but that
// test is not in this set.
assert!(rules.check(&points, &limits).is_empty());
assert!(RuleSet::nelson().check(&points, &limits).len() > 0);Implementations§
Source§impl RuleSet
impl RuleSet
Sourcepub const NAMES: [&'static str; 3]
pub const NAMES: [&'static str; 3]
The names RuleSet::named takes, in the order a refusal lists them.
Sourcepub fn shewhart() -> Self
pub fn shewhart() -> Self
The 3-sigma test alone – Shewhart’s criterion, and the default.
In routine monitoring each added test raises the false alarm rate of an in-control process (ISO 7870-2:2023, 8.2.7), so the supplementary tests are chosen, not assumed.
Sourcepub fn western_electric() -> Self
pub fn western_electric() -> Self
The four Western Electric tests (1956): Nelson rules 1, 5 and 6, and eight points in a row on one side of the centre line.
Sourcepub fn named(name: &str) -> Option<Self>
pub fn named(name: &str) -> Option<Self>
The set a name in RuleSet::NAMES stands for.
Sourcepub fn none() -> Self
pub fn none() -> Self
The empty set: no run test is applied.
Useful as a base to add to, and as the honest way to say “limits only”.
Sourcepub fn contains(&self, rule: ViolationType) -> bool
pub fn contains(&self, rule: ViolationType) -> bool
Whether this set applies the test that reports rule.
Sourcepub fn with(self, rule: ViolationType) -> Self
pub fn with(self, rule: ViolationType) -> Self
This set with rule added.
Sourcepub fn without(self, rule: ViolationType) -> Self
pub fn without(self, rule: ViolationType) -> Self
This set with rule removed.
Sourcepub fn iter(&self) -> impl Iterator<Item = ViolationType> + '_
pub fn iter(&self) -> impl Iterator<Item = ViolationType> + '_
The tests in this set, in the order of ViolationType::ALL.
Trait Implementations§
impl Copy for RuleSet
Source§impl Default for RuleSet
impl Default for RuleSet
Source§fn default() -> Self
fn default() -> Self
RuleSet::shewhart – the 3-sigma test alone.