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::PatchConfig;
use super::types::DetectionTask;
use super::types::HSR;
use super::types::HSRTask;
use super::types::LearningStatus;
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 req = AnalyticServiceMessage::Request(RequestType::GetHSR(HSRTask {
sender: tx,
@ -88,7 +89,7 @@ impl AnalyticClient {
// TODO: handle second error
match rx.await? {
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 super::analytic_unit::types::{AnalyticUnitConfig, PatchConfig, PatternConfig};
use super::types::{self, DetectionRunnerConfig, LearningTrain, LearningWaiter};
use super::types::{self, DetectionRunnerConfig, HSR, LearningTrain, LearningWaiter};
use super::{
analytic_client::AnalyticClient,
analytic_unit::pattern_analytic_unit::{self, LearningResults, PatternAnalyticUnit},
@ -178,7 +178,6 @@ impl AnalyticService {
}
RequestType::PatchConfig(patch_obj, tx) => {
self.patch_config(patch_obj, tx);
// tx.send(()).unwrap();
}
RequestType::GetHSR(task) => {
if self.analytic_unit.is_some() {
@ -346,7 +345,7 @@ impl AnalyticService {
}
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>>>,
ms: MetricService,
from: u64,

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

@ -1,6 +1,4 @@
use crate::services::{
analytic_service::types, metric_service::MetricService, segments_service::SegmentsService,
};
use crate::services::{analytic_service::types::{self, HSR}, metric_service::MetricService, segments_service::SegmentsService};
use super::types::{AnalyticUnit, AnalyticUnitConfig, AnomalyConfig, LearningResult};
@ -58,22 +56,22 @@ impl AnalyticUnit for AnomalyAnalyticUnit {
Ok(Default::default())
}
// TODO: use hsr for learning and detections
async fn get_hsr(
&self,
ms: MetricService,
from: u64,
to: u64,
) -> anyhow::Result<Vec<(u64, f64)>> {
// TODO: implement
) -> anyhow::Result<HSR> {
let mr = ms.query(from, to, DETECTION_STEP).await.unwrap();
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 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 crate::services::{
analytic_service::types::{self, LearningTrain},
metric_service::MetricService,
segments_service::{Segment, SegmentType, SegmentsService},
};
use crate::services::{analytic_service::types::{self, HSR, LearningTrain}, metric_service::MetricService, segments_service::{Segment, SegmentType, SegmentsService}};
use super::types::{AnalyticUnit, AnalyticUnitConfig, LearningResult, PatternConfig};
@ -403,21 +399,22 @@ impl AnalyticUnit for PatternAnalyticUnit {
Ok(results)
}
// TODO: use hsr for learning and detections
async fn get_hsr(
&self,
ms: MetricService,
from: u64,
to: u64,
) -> anyhow::Result<Vec<(u64, f64)>> {
) -> anyhow::Result<HSR> {
let mr = ms.query(from, to, DETECTION_STEP).await.unwrap();
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 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::{
analytic_service::types, metric_service::MetricService, segments_service::SegmentsService,
};
use crate::services::{analytic_service::types::{self, HSR}, metric_service::MetricService, segments_service::SegmentsService};
use super::types::{AnalyticUnit, AnalyticUnitConfig, LearningResult, ThresholdConfig};
@ -75,21 +73,22 @@ impl AnalyticUnit for ThresholdAnalyticUnit {
Ok(result)
}
// TODO: use hsr for learning and detections
async fn get_hsr(
&self,
ms: MetricService,
from: u64,
to: u64,
) -> anyhow::Result<Vec<(u64, f64)>> {
) -> anyhow::Result<HSR> {
let mr = ms.query(from, to, DETECTION_STEP).await.unwrap();
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 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 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)]
pub struct PatternConfig {
@ -136,7 +136,7 @@ pub trait AnalyticUnit {
ms: MetricService,
from: u64,
to: u64,
) -> anyhow::Result<Vec<(u64, f64)>>;
) -> anyhow::Result<HSR>;
}
#[derive(Deserialize, Serialize, Debug)]

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

@ -61,10 +61,18 @@ pub struct DetectionTask {
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)]
pub struct HSRTask {
// 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 to: u64,
}

Loading…
Cancel
Save