anomalyzer-ts 0.1.0

Probabilistic anomaly detection for time-series data
Documentation
//! Simulate CPU usage monitoring
use anomalyzer_ts::{Anomalyzer, AnomalyzerConf, NA};
use std::thread::sleep;
use std::time::Duration;

fn main() {
    let conf = AnomalyzerConf {
        active_size: 2,
        n_seasons: 30, // last hour if sampling every 2 seconds
        upper_bound: 90.0,
        methods: vec![
            "magnitude".to_string(),
            "fence".to_string(),
            "highrank".to_string(),
            "cdf".to_string(),
        ],
        ..Default::default()
    };

    let mut detector = Anomalyzer::new(conf, None).unwrap();

    // Simulate normal CPU usage
    let normal_usage = [45.0, 52.0, 48.0, 55.0, 50.0];
    for &cpu in normal_usage.iter().cycle().take(100) {
        let prob = detector.push(cpu);
        if prob > 0.9 {
            println!("ALERT: High anomaly probability {prob:.3} at CPU {cpu}%");
        }
        sleep(Duration::from_millis(100));
    }

    // Simulate spike
    println!("\n--- CPU Spike ---");
    for cpu in [60.0, 75.0, 88.0, 92.0, 85.0] {
        let prob = detector.push(cpu);
        println!("CPU: {cpu:>5}% → Probability: {prob:.3} {}", if prob > 0.9 { "⚠️  ANOMALY!" } else { "" });
        sleep(Duration::from_millis(200));
    }
}