Browse Source

pattern_detector begin

pull/25/head
Alexey Velikiy 3 years ago
parent
commit
99637211ff
  1. 3
      server/src/analytic_unit.rs
  2. 2
      server/src/api/analytics.rs
  3. 17
      server/src/services/analytic_service.rs
  4. 20
      server/src/services/analytic_service/pattern_detector.rs

3
server/src/analytic_unit.rs

@ -1,3 +0,0 @@
struct AnalyticUnit {
// TODO: field
}

2
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<impl warp::Reply, warp::Rejection> {
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)),
}

17
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<Vec<Segment>> {
// 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<Vec<Segment>> {
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::<Segment>::new();
let mut from: Option<u64> = None;
for (t, v) in ts {
if *v > 100_000.0 {
if *v > threashold {
if from.is_some() {
continue;
} else {

20
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<Vec<(u64, f64)>>) {
// TODO: implement
}
fn detect(ts: &Vec<(u64, f64)>) -> Vec<(u64, u64)> {
// fill backet
return Vec::new();
}
}
Loading…
Cancel
Save