diff --git a/server/src/analytic_unit.rs b/server/src/analytic_unit.rs deleted file mode 100644 index 03d0b5c..0000000 --- a/server/src/analytic_unit.rs +++ /dev/null @@ -1,3 +0,0 @@ -struct AnalyticUnit { - // TODO: field -} diff --git a/server/src/api/analytics.rs b/server/src/api/analytics.rs index 49b11f6..1f453a0 100644 --- a/server/src/api/analytics.rs +++ b/server/src/api/analytics.rs @@ -37,7 +37,7 @@ mod handlers { use crate::api::{BadQuery, API}; pub async fn list(opts: ListOptions, srv: Srv) -> Result { - match srv.get_detections(opts.from, opts.to, 10).await { + match srv.get_threshold_detections(opts.from, opts.to, 10, 100_000.).await { Ok(segments) => Ok(API::json(&segments)), Err(e) => Err(warp::reject::custom(BadQuery)), } diff --git a/server/src/services/analytic_service.rs b/server/src/services/analytic_service.rs index a5f2512..e96db9e 100644 --- a/server/src/services/analytic_service.rs +++ b/server/src/services/analytic_service.rs @@ -6,6 +6,9 @@ use subbeat::metric::Metric; use anyhow; +mod pattern_detector; + + #[derive(Clone)] pub struct AnalyticService { metric_service: MetricService, @@ -20,11 +23,21 @@ impl AnalyticService { } } - pub async fn get_detections( + pub async fn get_pattern_detection() -> anyhow::Result> { + // TODO: get segments + // TODO: get reads from segments + // TODO: run learn + // TODO: run detections + // TODO: convert detections to segments + Ok(Vec::new()) + } + + pub async fn get_threshold_detections( &self, from: u64, to: u64, step: u64, + threashold: f64 ) -> anyhow::Result> { let prom = self.metric_service.get_prom(); let mr = prom.query(from, to, step).await?; @@ -39,7 +52,7 @@ impl AnalyticService { let mut result = Vec::::new(); let mut from: Option = None; for (t, v) in ts { - if *v > 100_000.0 { + if *v > threashold { if from.is_some() { continue; } else { diff --git a/server/src/services/analytic_service/pattern_detector.rs b/server/src/services/analytic_service/pattern_detector.rs new file mode 100644 index 0000000..7c0644b --- /dev/null +++ b/server/src/services/analytic_service/pattern_detector.rs @@ -0,0 +1,20 @@ +use subbeat::metric::MetricResult; + +struct PatternDetector { + +} + +impl PatternDetector { + fn new() -> PatternDetector { + PatternDetector{} + } + + fn learn(reads: &Vec>) { + // TODO: implement + } + + fn detect(ts: &Vec<(u64, f64)>) -> Vec<(u64, u64)> { + // fill backet + return Vec::new(); + } +} \ No newline at end of file