anomalyzer-ts 0.1.0

Probabilistic anomaly detection for time-series data
Documentation
//! examples/async_basic.rs
//!
//! Basic async anomaly detection — the async equivalent of `basic.rs`.
//!
//! Run with:
//!   cargo run --example async_basic --features async

use anomalyzer_ts::{AnomalyzerConf, async_anomalyzer::AsyncAnomalyzer};

#[tokio::main]
async fn main() {
    let conf = AnomalyzerConf {
        active_size: 1,
        n_seasons: 4,
        methods: vec!["magnitude".to_string(), "highrank".to_string()],
        ..Default::default()
    };

    let detector = AsyncAnomalyzer::new(
        conf,
        Some(vec![10.0, 10.1, 10.2, 10.0, 10.15]),
    )
    .await
    .unwrap();

    let values = vec![
        ("normal",    10.15),
        ("normal",    10.3),
        ("anomalous", 15.0),   // spike
        ("normal",    9.8),
        ("anomalous", 0.5),    // dip
    ];

    println!("{:<12} {:>8}  {:>10}", "kind", "value", "prob");
    println!("{}", "-".repeat(36));

    for (label, v) in values {
        let prob = detector.push(v).await;
        let flag = if prob > 0.7 { " ⚠️  ANOMALY" } else { "" };
        println!("{:<12} {:>8.2}  {:>10.3}{}", label, v, prob, flag);
    }
}