diff --git a/server/src/services/analytic_service/analytic_service.rs b/server/src/services/analytic_service/analytic_service.rs index f13e38e..0cd3844 100644 --- a/server/src/services/analytic_service/analytic_service.rs +++ b/server/src/services/analytic_service/analytic_service.rs @@ -114,7 +114,6 @@ impl AnalyticService { } } - // TODO: make fn run_detection_runner(&mut self, from: u64) { // TODO: handle case or make it impossible to run_detection_runner second time @@ -136,8 +135,7 @@ impl AnalyticService { self.detection_runner = Some(dr); self.detection_runner.as_mut().unwrap().run(from); - // TODO: create DetectionRunnerConfig from alerting - // TODO: rerun detection runner on analytic unit change + // TODO: rerun detection runner on analytic unit change (by setting analytic unit) // if self.runner_handler.is_some() { // self.runner_handler.as_mut().unwrap().abort(); // } diff --git a/server/src/services/analytic_service/analytic_unit/anomaly_analytic_unit.rs b/server/src/services/analytic_service/analytic_unit/anomaly_analytic_unit.rs index 0ce7c87..70685bb 100644 --- a/server/src/services/analytic_service/analytic_unit/anomaly_analytic_unit.rs +++ b/server/src/services/analytic_service/analytic_unit/anomaly_analytic_unit.rs @@ -46,7 +46,7 @@ impl SARIMA { pub fn learn(&mut self, ts: &Vec<(u64, f64)>) -> anyhow::Result<()> { // TODO: don't count NaNs in model - // TODO: add exponental smooting to model + // TODO: add exponental smooting to the model // TODO: trend detection if ts.len() < 2 { diff --git a/server/src/services/analytic_service/detection_runner.rs b/server/src/services/analytic_service/detection_runner.rs index 8318523..1f01717 100644 --- a/server/src/services/analytic_service/detection_runner.rs +++ b/server/src/services/analytic_service/detection_runner.rs @@ -1,7 +1,3 @@ -use crate::services::analytic_service::analytic_unit::types::AnalyticUnit; - -use std::sync::Arc; - use chrono::Utc; use tokio::sync::{mpsc, RwLock}; @@ -52,12 +48,11 @@ impl DetectionRunner { ResponseType::DetectionRunnerStarted(from), ))) .await - { - Ok(_) => {} - Err(_e) => println!("Fail to send detection runner started notification"), - } + { + Ok(_) => {} + Err(_e) => println!("Fail to send detection runner started notification"), + } - loop { // TODO: run detection periodically sleep(Duration::from_secs(cfg.interval)).await; @@ -71,5 +66,8 @@ impl DetectionRunner { // self.analytic_unit = analytic_unit; // // TODO: stop running_handler // // TODO: rerun detection with new anomaly units + // if self.runner_handler.is_some() { + // self.runner_handler.as_mut().unwrap().abort(); + // } // } } diff --git a/server/src/services/analytic_unit_service.rs b/server/src/services/analytic_unit_service.rs new file mode 100644 index 0000000..851a3b9 --- /dev/null +++ b/server/src/services/analytic_unit_service.rs @@ -0,0 +1,32 @@ +use crate::utils::get_random_str; + +use rusqlite::{params, Connection, Row}; + +pub struct AnalyticUnitService { + // TODO: resolve by setting id for 3 types + // TODO: create database + // TODO: update detection + + +} + +impl AnalyticUnitService { + pub fn new() -> anyhow::Result { + // TODO: remove repetitoin with segment_service + std::fs::create_dir_all("./data").unwrap(); + let conn = Connection::open("./data/analytic_units.db")?; + + // TODO: add learning results field + conn.execute( + "CREATE TABLE IF NOT EXISTS analytic_unit ( + id TEXT PRIMARY KEY, + last_detection INTEGER NOT NULL, + )", + [], + )?; + + Ok(AnalyticUnitService { + connection: Arc::new(Mutex::new(conn)), + }) + } +} \ No newline at end of file diff --git a/server/src/services/segments_service.rs b/server/src/services/segments_service.rs index 52ea86b..9b2b711 100644 --- a/server/src/services/segments_service.rs +++ b/server/src/services/segments_service.rs @@ -68,6 +68,7 @@ impl SegmentsService { // TODO: move it to data service std::fs::create_dir_all("./data").unwrap(); + // TODO: add unilytic_unit id as a new field let conn = Connection::open("./data/segments.db")?; conn.execute( "CREATE TABLE IF NOT EXISTS segment (