1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use std::fmt::Display;

/// 样本偏差值
pub fn stddev<T: Display + std::fmt::Debug>(array: Vec<T>) -> f64 {
    let len = array.len();
    if len <= 1 {
        return 0.0;
    }
    let mut total = 0.0;
    let mut values = vec![];
    for item in array {
        let value = item.to_string().parse::<f64>().unwrap();
        values.push(value);
        total += value;
    }
    let mean = total / len.to_string().parse::<f64>().unwrap();
    total = 0.0;
    let _: Vec<f64> = values.iter_mut().map(|val| {
        let t = (*val - mean).powi(2);
        total += t;
        t
    }).collect();
    (total / (len - 1) as f64).sqrt()
}

/// 统计过程控制
/// Statistical Process Control
pub struct Spc {}

impl Spc {

}