diff --git a/server/src/services/analytic_service/analytic_unit/pattern_analytic_unit.rs b/server/src/services/analytic_service/analytic_unit/pattern_analytic_unit.rs index 3beb203..d0ce90a 100644 --- a/server/src/services/analytic_service/analytic_unit/pattern_analytic_unit.rs +++ b/server/src/services/analytic_service/analytic_unit/pattern_analytic_unit.rs @@ -220,8 +220,8 @@ impl AnalyticUnit for PatternAnalyticUnit { return self.id.to_owned(); } fn get_detection_window(&self) -> u64 { - // TODO: return window based on real petterns info - return DETECTION_STEP; + let lr = self.learning_results.as_ref().unwrap(); + return lr.avg_pattern_length as u64; } fn set_config(&mut self, config: AnalyticUnitConfig) { if let AnalyticUnitConfig::Pattern(cfg) = config { diff --git a/server/src/services/analytic_service/detection_runner.rs b/server/src/services/analytic_service/detection_runner.rs index 66ff8a4..ce1d804 100644 --- a/server/src/services/analytic_service/detection_runner.rs +++ b/server/src/services/analytic_service/detection_runner.rs @@ -7,7 +7,6 @@ use crate::services::metric_service::MetricService; use super::types::{AnalyticServiceMessage, AnalyticUnitRF, DetectionRunnerConfig, ResponseType}; use tokio::time::{sleep, Duration}; -const DETECTION_STEP: u64 = 10; pub struct DetectionRunner { metric_service: MetricService, @@ -49,7 +48,9 @@ impl DetectionRunner { // TODO: parse detections to webhooks // TODO: define window for detection // TODO: handle case when detection is in the end and continues after "now" + let window_size = au.as_ref().read().await.get_detection_window(); + let detection_step = ms.get_detection_step(); let mut t_from = from - window_size; let mut t_to = from; @@ -71,7 +72,6 @@ impl DetectionRunner { println!("detection: {} {}", d.0, d.1); } - // TODO: run detection periodically // TODO: set info about detections to tx match tx @@ -88,6 +88,8 @@ impl DetectionRunner { } sleep(Duration::from_secs(cfg.interval)).await; + t_from += detection_step; + t_to += detection_step; } } })); diff --git a/server/src/services/metric_service.rs b/server/src/services/metric_service.rs index 14a5091..ca3a2ad 100644 --- a/server/src/services/metric_service.rs +++ b/server/src/services/metric_service.rs @@ -32,4 +32,11 @@ impl MetricService { } return Ok(mr); } + + // TODO: it a hack for DetectionRunner: it should vary for different analytic units + // and it's config + pub fn get_detection_step(&self) -> u64 { + return 10; + } + }