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, 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();
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));
}
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));
}
}