Browse Source

hst type

pull/25/head
Alexey Velikiy 3 years ago
parent
commit
512458a7c0
  1. 5
      server/src/services/analytic_service/analytic_client.rs
  2. 5
      server/src/services/analytic_service/analytic_service.rs
  3. 12
      server/src/services/analytic_service/analytic_unit/anomaly_analytic_unit.rs
  4. 13
      server/src/services/analytic_service/analytic_unit/pattern_analytic_unit.rs
  5. 11
      server/src/services/analytic_service/analytic_unit/threshold_analytic_unit.rs
  6. 4
      server/src/services/analytic_service/analytic_unit/types.rs
  7. 10
      server/src/services/analytic_service/types.rs

5
server/src/services/analytic_service/analytic_client.rs

@ -7,6 +7,7 @@ use crate::services::segments_service::Segment;
use super::analytic_unit::types::AnalyticUnitConfig; use super::analytic_unit::types::AnalyticUnitConfig;
use super::analytic_unit::types::PatchConfig; use super::analytic_unit::types::PatchConfig;
use super::types::DetectionTask; use super::types::DetectionTask;
use super::types::HSR;
use super::types::HSRTask; use super::types::HSRTask;
use super::types::LearningStatus; use super::types::LearningStatus;
use super::types::LearningTrain; use super::types::LearningTrain;
@ -77,7 +78,7 @@ impl AnalyticClient {
} }
} }
pub async fn get_hsr(&self, from: u64, to: u64) -> anyhow::Result<Vec<(u64, f64)>> { pub async fn get_hsr(&self, from: u64, to: u64) -> anyhow::Result<HSR> {
let (tx, rx) = oneshot::channel(); let (tx, rx) = oneshot::channel();
let req = AnalyticServiceMessage::Request(RequestType::GetHSR(HSRTask { let req = AnalyticServiceMessage::Request(RequestType::GetHSR(HSRTask {
sender: tx, sender: tx,
@ -88,7 +89,7 @@ impl AnalyticClient {
// TODO: handle second error // TODO: handle second error
match rx.await? { match rx.await? {
Ok(r) => Ok(r), Ok(r) => Ok(r),
Err(e) => Ok(Vec::new()), Err(e) => Ok(HSR::TimeSerie(Vec::new())),
} }
} }
} }

5
server/src/services/analytic_service/analytic_service.rs

@ -1,7 +1,7 @@
use std::sync::Arc; use std::sync::Arc;
use super::analytic_unit::types::{AnalyticUnitConfig, PatchConfig, PatternConfig}; use super::analytic_unit::types::{AnalyticUnitConfig, PatchConfig, PatternConfig};
use super::types::{self, DetectionRunnerConfig, LearningTrain, LearningWaiter}; use super::types::{self, DetectionRunnerConfig, HSR, LearningTrain, LearningWaiter};
use super::{ use super::{
analytic_client::AnalyticClient, analytic_client::AnalyticClient,
analytic_unit::pattern_analytic_unit::{self, LearningResults, PatternAnalyticUnit}, analytic_unit::pattern_analytic_unit::{self, LearningResults, PatternAnalyticUnit},
@ -178,7 +178,6 @@ impl AnalyticService {
} }
RequestType::PatchConfig(patch_obj, tx) => { RequestType::PatchConfig(patch_obj, tx) => {
self.patch_config(patch_obj, tx); self.patch_config(patch_obj, tx);
// tx.send(()).unwrap();
} }
RequestType::GetHSR(task) => { RequestType::GetHSR(task) => {
if self.analytic_unit.is_some() { if self.analytic_unit.is_some() {
@ -346,7 +345,7 @@ impl AnalyticService {
} }
async fn get_hsr( async fn get_hsr(
tx: oneshot::Sender<anyhow::Result<Vec<(u64, f64)>>>, tx: oneshot::Sender<anyhow::Result<HSR>>,
analytic_unit: Arc<RwLock<Box<dyn AnalyticUnit + Send + Sync>>>, analytic_unit: Arc<RwLock<Box<dyn AnalyticUnit + Send + Sync>>>,
ms: MetricService, ms: MetricService,
from: u64, from: u64,

12
server/src/services/analytic_service/analytic_unit/anomaly_analytic_unit.rs

@ -1,6 +1,4 @@
use crate::services::{ use crate::services::{analytic_service::types::{self, HSR}, metric_service::MetricService, segments_service::SegmentsService};
analytic_service::types, metric_service::MetricService, segments_service::SegmentsService,
};
use super::types::{AnalyticUnit, AnalyticUnitConfig, AnomalyConfig, LearningResult}; use super::types::{AnalyticUnit, AnalyticUnitConfig, AnomalyConfig, LearningResult};
@ -58,22 +56,22 @@ impl AnalyticUnit for AnomalyAnalyticUnit {
Ok(Default::default()) Ok(Default::default())
} }
// TODO: use hsr for learning and detections
async fn get_hsr( async fn get_hsr(
&self, &self,
ms: MetricService, ms: MetricService,
from: u64, from: u64,
to: u64, to: u64,
) -> anyhow::Result<Vec<(u64, f64)>> { ) -> anyhow::Result<HSR> {
// TODO: implement
let mr = ms.query(from, to, DETECTION_STEP).await.unwrap(); let mr = ms.query(from, to, DETECTION_STEP).await.unwrap();
if mr.data.keys().len() == 0 { if mr.data.keys().len() == 0 {
return Ok(Vec::new()); return Ok(HSR::TimeSerie(Vec::new()));
} }
let k = mr.data.keys().nth(0).unwrap(); let k = mr.data.keys().nth(0).unwrap();
let ts = mr.data[k].clone(); let ts = mr.data[k].clone();
Ok(ts) Ok(HSR::TimeSerie(ts))
} }
} }

13
server/src/services/analytic_service/analytic_unit/pattern_analytic_unit.rs

@ -10,11 +10,7 @@ use linfa_svm::Svm;
use ndarray::Array; use ndarray::Array;
use crate::services::{ use crate::services::{analytic_service::types::{self, HSR, LearningTrain}, metric_service::MetricService, segments_service::{Segment, SegmentType, SegmentsService}};
analytic_service::types::{self, LearningTrain},
metric_service::MetricService,
segments_service::{Segment, SegmentType, SegmentsService},
};
use super::types::{AnalyticUnit, AnalyticUnitConfig, LearningResult, PatternConfig}; use super::types::{AnalyticUnit, AnalyticUnitConfig, LearningResult, PatternConfig};
@ -403,21 +399,22 @@ impl AnalyticUnit for PatternAnalyticUnit {
Ok(results) Ok(results)
} }
// TODO: use hsr for learning and detections
async fn get_hsr( async fn get_hsr(
&self, &self,
ms: MetricService, ms: MetricService,
from: u64, from: u64,
to: u64, to: u64,
) -> anyhow::Result<Vec<(u64, f64)>> { ) -> anyhow::Result<HSR> {
let mr = ms.query(from, to, DETECTION_STEP).await.unwrap(); let mr = ms.query(from, to, DETECTION_STEP).await.unwrap();
if mr.data.keys().len() == 0 { if mr.data.keys().len() == 0 {
return Ok(Vec::new()); return Ok(HSR::TimeSerie(Vec::new()));
} }
let k = mr.data.keys().nth(0).unwrap(); let k = mr.data.keys().nth(0).unwrap();
let ts = mr.data[k].clone(); let ts = mr.data[k].clone();
Ok(ts) Ok(HSR::TimeSerie(ts))
} }
} }

11
server/src/services/analytic_service/analytic_unit/threshold_analytic_unit.rs

@ -1,6 +1,4 @@
use crate::services::{ use crate::services::{analytic_service::types::{self, HSR}, metric_service::MetricService, segments_service::SegmentsService};
analytic_service::types, metric_service::MetricService, segments_service::SegmentsService,
};
use super::types::{AnalyticUnit, AnalyticUnitConfig, LearningResult, ThresholdConfig}; use super::types::{AnalyticUnit, AnalyticUnitConfig, LearningResult, ThresholdConfig};
@ -75,21 +73,22 @@ impl AnalyticUnit for ThresholdAnalyticUnit {
Ok(result) Ok(result)
} }
// TODO: use hsr for learning and detections
async fn get_hsr( async fn get_hsr(
&self, &self,
ms: MetricService, ms: MetricService,
from: u64, from: u64,
to: u64, to: u64,
) -> anyhow::Result<Vec<(u64, f64)>> { ) -> anyhow::Result<HSR> {
let mr = ms.query(from, to, DETECTION_STEP).await.unwrap(); let mr = ms.query(from, to, DETECTION_STEP).await.unwrap();
if mr.data.keys().len() == 0 { if mr.data.keys().len() == 0 {
return Ok(Vec::new()); return Ok(HSR::TimeSerie(Vec::new()));
} }
let k = mr.data.keys().nth(0).unwrap(); let k = mr.data.keys().nth(0).unwrap();
let ts = mr.data[k].clone(); let ts = mr.data[k].clone();
Ok(ts) Ok(HSR::TimeSerie(ts))
} }
} }

4
server/src/services/analytic_service/analytic_unit/types.rs

@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};
use async_trait::async_trait; use async_trait::async_trait;
use crate::services::{metric_service::MetricService, segments_service::SegmentsService}; use crate::services::{analytic_service::types::HSR, metric_service::MetricService, segments_service::SegmentsService};
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
pub struct PatternConfig { pub struct PatternConfig {
@ -136,7 +136,7 @@ pub trait AnalyticUnit {
ms: MetricService, ms: MetricService,
from: u64, from: u64,
to: u64, to: u64,
) -> anyhow::Result<Vec<(u64, f64)>>; ) -> anyhow::Result<HSR>;
} }
#[derive(Deserialize, Serialize, Debug)] #[derive(Deserialize, Serialize, Debug)]

10
server/src/services/analytic_service/types.rs

@ -61,10 +61,18 @@ pub struct DetectionTask {
pub to: u64, pub to: u64,
} }
// HSR Stands for Hastic Signal Representation,
// varies for different analytic units
#[derive(Debug, Serialize)]
pub enum HSR {
TimeSerie(Vec<(u64, f64)>)
}
#[derive(Debug)] #[derive(Debug)]
pub struct HSRTask { pub struct HSRTask {
// TODO: make enum for HSR which is different for different Analytic Types // TODO: make enum for HSR which is different for different Analytic Types
pub sender: oneshot::Sender<Result<Vec<(u64, f64)>>>, pub sender: oneshot::Sender<Result<HSR>>,
pub from: u64, pub from: u64,
pub to: u64, pub to: u64,
} }

Loading…
Cancel
Save