Browse Source

correlation_score + fmt

pull/25/head
Alexey Velikiy 3 years ago
parent
commit
7c4d6cb79f
  1. 10
      server/src/services/analytic_service/analytic_service.rs
  2. 19
      server/src/services/analytic_service/analytic_unit/pattern_analytic_unit.rs
  3. 1
      server/src/services/analytic_service/analytic_unit/threshold_analytic_unit.rs

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

@ -174,7 +174,7 @@ impl AnalyticService {
} }
}; };
} }
// TODO: maybe make `consume_response` async // TODO: maybe make `consume_response` async
fn consume_response(&mut self, res: types::ResponseType) { fn consume_response(&mut self, res: types::ResponseType) {
match res { match res {
@ -219,9 +219,9 @@ impl AnalyticService {
self.analytic_unit_config = new_conf; self.analytic_unit_config = new_conf;
if need_learning { if need_learning {
self.consume_request(RequestType::RunLearning); self.consume_request(RequestType::RunLearning);
// TODO: it's not fullu correct: we need to wait when the learning starts // TODO: it's not fullu correct: we need to wait when the learning starts
match tx.send(()) { match tx.send(()) {
Ok(_) => {}, Ok(_) => {}
Err(_e) => { Err(_e) => {
println!("Can`t send patch config notification"); println!("Can`t send patch config notification");
} }
@ -234,7 +234,7 @@ impl AnalyticService {
async move { async move {
au.unwrap().write().await.set_config(cfg); au.unwrap().write().await.set_config(cfg);
match tx.send(()) { match tx.send(()) {
Ok(_) => {}, Ok(_) => {}
Err(_e) => { Err(_e) => {
println!("Can`t send patch config notification"); println!("Can`t send patch config notification");
} }
@ -243,7 +243,7 @@ impl AnalyticService {
}); });
} else { } else {
match tx.send(()) { match tx.send(()) {
Ok(_) => {}, Ok(_) => {}
Err(_e) => { Err(_e) => {
println!("Can`t send patch config notification"); println!("Can`t send patch config notification");
} }

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

@ -182,7 +182,6 @@ impl PatternAnalyticUnit {
#[async_trait] #[async_trait]
impl AnalyticUnit for PatternAnalyticUnit { impl AnalyticUnit for PatternAnalyticUnit {
fn set_config(&mut self, config: AnalyticUnitConfig) { fn set_config(&mut self, config: AnalyticUnitConfig) {
if let AnalyticUnitConfig::Pattern(cfg) = config { if let AnalyticUnitConfig::Pattern(cfg) = config {
self.config = cfg; self.config = cfg;
@ -363,21 +362,21 @@ impl AnalyticUnit for PatternAnalyticUnit {
} }
} }
{ let model_positive = {
let mut backet = Vec::<f64>::new(); let mut backet = Vec::<f64>::new();
for j in 0..pattern_match_len { for j in 0..pattern_match_len {
backet.push(nan_to_zero(ts[i + j].1)); backet.push(nan_to_zero(ts[i + j].1));
} }
let fs = PatternAnalyticUnit::get_features(&backet); let fs = PatternAnalyticUnit::get_features(&backet);
let detected = lr.model.lock().predict(Array::from_vec(fs.to_vec())); lr.model.lock().predict(Array::from_vec(fs.to_vec()))
if detected { };
pattern_match_score += self.config.model_score;
}
}
if pattern_match_score - anti_pattern_match_score * self.config.anti_correlation_score let mut score = pattern_match_score * self.config.correlation_score;
>= self.config.threshold_score score -= anti_pattern_match_score * self.config.anti_correlation_score;
{ if model_positive {
score += self.config.model_score;
}
if score >= self.config.threshold_score {
results.push((ts[i].0, ts[i + pattern_match_len - 1].0)); results.push((ts[i].0, ts[i + pattern_match_len - 1].0));
} }
} }

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

@ -17,7 +17,6 @@ impl ThresholdAnalyticUnit {
pub fn new(config: ThresholdConfig) -> ThresholdAnalyticUnit { pub fn new(config: ThresholdConfig) -> ThresholdAnalyticUnit {
ThresholdAnalyticUnit { config } ThresholdAnalyticUnit { config }
} }
} }
#[async_trait] #[async_trait]

Loading…
Cancel
Save