Browse Source

SARIMA++

pull/25/head
Alexey Velikiy 3 years ago
parent
commit
d4ca2fbf5b
  1. 53
      server/src/services/analytic_service/analytic_unit/anomaly_analytic_unit.rs

53
server/src/services/analytic_service/analytic_unit/anomaly_analytic_unit.rs

@ -9,8 +9,26 @@ use subbeat::metric::MetricResult;
use chrono::prelude::*; use chrono::prelude::*;
// TODO: move to config
const DETECTION_STEP: u64 = 10;
// offset from intex in timrange in seconds
fn get_value_with_offset(ts: &Vec<(u64, f64)>, index: usize, offset: u64) -> anyhow::Result<f64> {
// TODO: implement
if index == 0 {
return Err(anyhow::format_err!("index should be > 0"));
}
return Ok(0.0);
// let step =
// let index_candidate =
// let intex_candidate =
}
struct SARIMA { struct SARIMA {
pub ts: Vec<f64>, pub ts: Vec<(u64, f64)>,
pub seasonality: u64, pub seasonality: u64,
} }
@ -22,8 +40,26 @@ impl SARIMA {
}; };
} }
pub fn learn(&mut self, ts: &Vec<(u64, f64)>) { pub fn learn(&mut self, ts: &Vec<(u64, f64)>) -> anyhow::Result<()> {
if ts.len() < 2 {
return Err(anyhow::format_err!("to short timeserie to learn from"));
}
// TODO: ensure capacity with seasonality size
let res_ts = Vec::<(u64, f64)>::new();
let from = ts[0].0;
let to = ts.last().unwrap().0;
if to - from != 3 * self.seasonality {
return Err(anyhow::format_err!("timeserie to learn from should be 3 * sasonality"));
}
// TODO: compute avg based on seasonality // TODO: compute avg based on seasonality
self.ts = res_ts;
return Ok(());
} }
pub fn predict(&self, timestamp: u64, value: f64) -> (f64, f64, f64) { pub fn predict(&self, timestamp: u64, value: f64) -> (f64, f64, f64) {
// TODO: implement // TODO: implement
@ -37,20 +73,7 @@ impl SARIMA {
// TODO: don't count NaNs in model // TODO: don't count NaNs in model
} }
// TODO: move to config
const DETECTION_STEP: u64 = 10;
// offset from intex in timrange in seconds
fn get_value_with_offset(ts: &Vec<(u64, f64)>, index: usize, offset: u64) -> anyhow::Result<f64> {
// TODO: implement
if index == 0 {
return Err(anyhow::format_err!("index should be > 0"));
}
return Ok(0.0);
// let step =
// let index_candidate =
// let intex_candidate =
}
pub struct AnomalyAnalyticUnit { pub struct AnomalyAnalyticUnit {
config: AnomalyConfig, config: AnomalyConfig,

Loading…
Cancel
Save