Browse Source

patch config: same type param

active-analytic-unit-#66
Alexey Velikiy 2 years ago
parent
commit
1f2d6f551e
  1. 6
      server/src/services/analytic_service/analytic_service.rs
  2. 28
      server/src/services/analytic_service/analytic_unit/types.rs

6
server/src/services/analytic_service/analytic_service.rs

@ -72,9 +72,7 @@ impl AnalyticService {
alerting, alerting,
// TODO: get it from persistance
analytic_unit: None, analytic_unit: None,
// TODO: get pattern from saved in analytic_unit_service
analytic_unit_config: analytic_unit_service.get_active_config().unwrap(), analytic_unit_config: analytic_unit_service.get_active_config().unwrap(),
analytic_unit_learning_status: LearningStatus::Initialization, analytic_unit_learning_status: LearningStatus::Initialization,
@ -277,7 +275,7 @@ impl AnalyticService {
fn patch_config(&mut self, patch: PatchConfig, tx: oneshot::Sender<()>) { fn patch_config(&mut self, patch: PatchConfig, tx: oneshot::Sender<()>) {
// TODO: update config in db // TODO: update config in db
let (new_conf, need_learning) = self.analytic_unit_config.patch(patch); let (new_conf, need_learning, same_type) = self.analytic_unit_config.patch(patch);
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);
@ -312,6 +310,8 @@ impl AnalyticService {
} }
} }
} }
// TODO: save config depending on type
} }
pub async fn serve(&mut self) { pub async fn serve(&mut self) {

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

@ -63,22 +63,22 @@ pub enum AnalyticUnitConfig {
} }
impl AnalyticUnitConfig { impl AnalyticUnitConfig {
// return true if patch is different type // return true if need needs relearning and true if the config of the same type
pub fn patch(&self, patch: PatchConfig) -> (AnalyticUnitConfig, bool) { pub fn patch(&self, patch: PatchConfig) -> (AnalyticUnitConfig, bool, bool) {
match patch { match patch {
PatchConfig::Pattern(tcfg) => match self.clone() { PatchConfig::Pattern(tcfg) => match self.clone() {
AnalyticUnitConfig::Pattern(_) => { AnalyticUnitConfig::Pattern(_) => {
if tcfg.is_some() { if tcfg.is_some() {
return (AnalyticUnitConfig::Pattern(tcfg.unwrap()), false); return (AnalyticUnitConfig::Pattern(tcfg.unwrap()), false, true);
} else { } else {
return (AnalyticUnitConfig::Pattern(Default::default()), false); return (AnalyticUnitConfig::Pattern(Default::default()), false, true);
} }
} }
_ => { _ => {
if tcfg.is_some() { if tcfg.is_some() {
return (AnalyticUnitConfig::Pattern(tcfg.unwrap()), true); return (AnalyticUnitConfig::Pattern(tcfg.unwrap()), true, false);
} else { } else {
return (AnalyticUnitConfig::Pattern(Default::default()), true); return (AnalyticUnitConfig::Pattern(Default::default()), true, false);
} }
} }
}, },
@ -89,16 +89,16 @@ impl AnalyticUnitConfig {
let t = tcfg.as_ref().unwrap(); let t = tcfg.as_ref().unwrap();
let mut need_learning = t.seasonality != scfg.seasonality; let mut need_learning = t.seasonality != scfg.seasonality;
need_learning |= t.seasonality_iterations != scfg.seasonality_iterations; need_learning |= t.seasonality_iterations != scfg.seasonality_iterations;
return (AnalyticUnitConfig::Anomaly(tcfg.unwrap()), need_learning); return (AnalyticUnitConfig::Anomaly(tcfg.unwrap()), need_learning, true);
} else { } else {
return (AnalyticUnitConfig::Anomaly(Default::default()), false); return (AnalyticUnitConfig::Anomaly(Default::default()), false, true);
} }
} }
_ => { _ => {
if tcfg.is_some() { if tcfg.is_some() {
return (AnalyticUnitConfig::Anomaly(tcfg.unwrap()), true); return (AnalyticUnitConfig::Anomaly(tcfg.unwrap()), true, false);
} else { } else {
return (AnalyticUnitConfig::Anomaly(Default::default()), true); return (AnalyticUnitConfig::Anomaly(Default::default()), true, false);
} }
} }
}, },
@ -106,16 +106,16 @@ impl AnalyticUnitConfig {
PatchConfig::Threshold(tcfg) => match self.clone() { PatchConfig::Threshold(tcfg) => match self.clone() {
AnalyticUnitConfig::Threshold(_) => { AnalyticUnitConfig::Threshold(_) => {
if tcfg.is_some() { if tcfg.is_some() {
return (AnalyticUnitConfig::Threshold(tcfg.unwrap()), false); return (AnalyticUnitConfig::Threshold(tcfg.unwrap()), false, true);
} else { } else {
return (AnalyticUnitConfig::Threshold(Default::default()), false); return (AnalyticUnitConfig::Threshold(Default::default()), false, true);
} }
} }
_ => { _ => {
if tcfg.is_some() { if tcfg.is_some() {
return (AnalyticUnitConfig::Threshold(tcfg.unwrap()), true); return (AnalyticUnitConfig::Threshold(tcfg.unwrap()), true, false);
} else { } else {
return (AnalyticUnitConfig::Threshold(Default::default()), true); return (AnalyticUnitConfig::Threshold(Default::default()), true, false);
} }
} }
}, },

Loading…
Cancel
Save