From 6b4442858645995b1b27744cc5256eaee5c6c7a2 Mon Sep 17 00:00:00 2001 From: Alexey Velikiy Date: Fri, 24 Dec 2021 17:30:36 +0300 Subject: [PATCH] detection step in matric service and update of t_from \ t_to --- server/src/services/analytic_service/detection_runner.rs | 5 ++++- server/src/services/metric_service.rs | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/server/src/services/analytic_service/detection_runner.rs b/server/src/services/analytic_service/detection_runner.rs index eb3efcf..1a5128a 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, @@ -50,7 +49,9 @@ impl DetectionRunner { // TODO: define window for detection // TODO: handle case when detection is in the end and continues after "now" // TODO: update t_from / t_to + 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; @@ -88,6 +89,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; + } + }