|
|
|
@ -56,31 +56,31 @@ impl SARIMA {
|
|
|
|
|
)); |
|
|
|
|
} |
|
|
|
|
// TODO: ensure capacity with seasonality size
|
|
|
|
|
let mut res_ts = Vec::<(u64, f64)>::new(); |
|
|
|
|
let from = ts[0].0; |
|
|
|
|
// TODO: unwrap -> ?
|
|
|
|
|
let to = ts.last().unwrap().0; |
|
|
|
|
let iter_steps = (self.seasonality / DETECTION_STEP) as usize; |
|
|
|
|
|
|
|
|
|
if to - from != self.seasonality_iterations * self.seasonality { |
|
|
|
|
return Err(anyhow::format_err!( |
|
|
|
|
"timeserie to learn from should be {} * sasonality", |
|
|
|
|
self.seasonality_iterations |
|
|
|
|
)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for k in 0..iter_steps { |
|
|
|
|
let mut vts = Vec::new(); |
|
|
|
|
for si in 0..self.seasonality_iterations { |
|
|
|
|
vts.push(ts[k + iter_steps * si as usize].1); |
|
|
|
|
} |
|
|
|
|
let mut vt: f64 = vts.iter().sum(); |
|
|
|
|
vt /= self.seasonality_iterations as f64; |
|
|
|
|
let t = ts[ts.len() - iter_steps + k].0; |
|
|
|
|
res_ts.push((t, vt)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
self.ts = res_ts; |
|
|
|
|
// let mut res_ts = Vec::<(u64, f64)>::new();
|
|
|
|
|
// let from = ts[0].0;
|
|
|
|
|
// // TODO: unwrap -> ?
|
|
|
|
|
// let to = ts.last().unwrap().0;
|
|
|
|
|
// let iter_steps = 5 as usize;
|
|
|
|
|
|
|
|
|
|
// if to - from != self.seasonality_iterations * self.seasonality {
|
|
|
|
|
// return Err(anyhow::format_err!(
|
|
|
|
|
// "timeserie to learn from should be {} * seasonality",
|
|
|
|
|
// self.seasonality_iterations
|
|
|
|
|
// ));
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// for k in 0..iter_steps {
|
|
|
|
|
// let mut vts = Vec::new();
|
|
|
|
|
// for si in 0..self.seasonality_iterations {
|
|
|
|
|
// vts.push(ts[k + iter_steps * si as usize].1);
|
|
|
|
|
// }
|
|
|
|
|
// let mut vt: f64 = vts.iter().sum();
|
|
|
|
|
// vt /= self.seasonality_iterations as f64;
|
|
|
|
|
// let t = ts[ts.len() - iter_steps + k].0;
|
|
|
|
|
// res_ts.push((t, vt));
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
self.ts = ts.to_vec(); |
|
|
|
|
|
|
|
|
|
return Ok(()); |
|
|
|
|
} |
|
|
|
@ -194,7 +194,7 @@ impl AnalyticUnit for AnomalyAnalyticUnit {
|
|
|
|
|
|
|
|
|
|
let utc: DateTime<Utc> = Utc::now(); |
|
|
|
|
let to = utc.timestamp() as u64; |
|
|
|
|
let from = to - self.config.seasonality * self.config.seasonality_iterations; |
|
|
|
|
let from = to - 86400; |
|
|
|
|
|
|
|
|
|
let mr = ms.query(from, to, DETECTION_STEP).await?; |
|
|
|
|
if mr.data.keys().len() == 0 { |
|
|
|
|