Browse Source

need_learning on patch case

analytic-unit-type-and-meta-in-db-#65
Alexey Velikiy 2 years ago
parent
commit
21f4b6eaaa
  1. 52
      server/src/services/analytic_service/analytic_service.rs
  2. 41
      server/src/services/analytic_service/analytic_unit/types.rs

52
server/src/services/analytic_service/analytic_service.rs

@ -276,29 +276,46 @@ impl AnalyticService {
fn patch_config(&mut self, patch: PatchConfig, tx: oneshot::Sender<()>) {
let my_id = self.analytic_unit_service.get_config_id(&self.analytic_unit_config);
let patch_id = patch.get_type_id();
let same_type = my_id == patch_id;
// TODO: need_learning and same_type logic overlaps, there is a way to optimise this
let need_learning = self.analytic_unit_config.patch_needs_learning(&patch);
if same_type {
// TODO: check when learning should be started
let new_conf = patch.get_new_config();
self.analytic_unit_config = new_conf.clone();
self.analytic_unit_service.update_config_by_id(&my_id, &new_conf).unwrap();
if self.analytic_unit.is_some() {
tokio::spawn({
let au = self.analytic_unit.clone();
let cfg = self.analytic_unit_config.clone();
async move {
au.unwrap().write().await.set_config(cfg);
match tx.send(()) {
Ok(_) => {}
Err(_e) => {
println!("Can`t send patch config notification");
}
if need_learning {
self.consume_request(RequestType::RunLearning);
match tx.send(()) {
Ok(_) => {}
Err(_e) => {
println!("Can`t send patch config notification");
}
}
});
return;
} else {
tokio::spawn({
let au = self.analytic_unit.clone();
let cfg = self.analytic_unit_config.clone();
async move {
au.unwrap().write().await.set_config(cfg);
match tx.send(()) {
Ok(_) => {}
Err(_e) => {
println!("Can`t send patch config notification");
}
}
}
});
}
} else {
// TODO: check if we need this else
match tx.send(()) {
@ -309,7 +326,6 @@ impl AnalyticService {
}
}
} else {
// TODO: extracdt from db
let new_conf = self.analytic_unit_service.get_config_by_id(&patch_id).unwrap();
self.analytic_unit_config = new_conf.clone();
self.consume_request(RequestType::RunLearning);
@ -320,18 +336,6 @@ impl AnalyticService {
}
}
}
// TODO: update analytic_unit config if some
// TODO: save updated
// TODO: run learning when different
// TODO: run learning when it's necessary
}
pub async fn serve(&mut self) {

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

@ -73,6 +73,47 @@ impl AnalyticUnitConfig {
_ => panic!("bad id for getting get_default_by_id")
}
}
pub fn patch_needs_learning(&self, patch: &PatchConfig) -> bool {
// TODO: maybe use type id's to optimise code
match patch {
PatchConfig::Pattern(tcfg) => match self.clone() {
AnalyticUnitConfig::Pattern(_) => {
return false;
}
_ => {
return true
}
},
PatchConfig::Anomaly(tcfg) => match self.clone() {
AnalyticUnitConfig::Anomaly(scfg) => {
if tcfg.is_some() {
let t = tcfg.as_ref().unwrap();
let mut need_learning = t.seasonality != scfg.seasonality;
need_learning |= t.seasonality_iterations != scfg.seasonality_iterations;
return need_learning;
} else {
return false;
}
}
_ => {
return true;
}
},
PatchConfig::Threshold(tcfg) => match self.clone() {
AnalyticUnitConfig::Threshold(_) => {
return false;
}
_ => {
return true;
}
},
}
}
// TODO: maybe this method depricated
// return true if need needs relearning
pub fn patch(&self, patch: PatchConfig) -> (AnalyticUnitConfig, bool) {
match patch {

Loading…
Cancel
Save