Browse Source

Merge pull request #85 from hastic/backet-detection-window-for-pattern-analytic-unit-#83

Bucket detection window for pattern analytic unit #83
pull/91/head
glitch4347 2 years ago committed by GitHub
parent
commit
4f66b59b7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      server/src/services/analytic_service/analytic_unit/pattern_analytic_unit.rs
  2. 6
      server/src/services/analytic_service/detection_runner.rs
  3. 7
      server/src/services/metric_service.rs

4
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 {

6
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;
}
}
}));

7
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;
}
}

Loading…
Cancel
Save