Browse Source

reactive config

pull/25/head
Alexey Velikiy 3 years ago
parent
commit
94a1dbcea7
  1. 21
      client/src/components/Graph.vue
  2. 32
      server/src/services/analytic_service/analytic_service.rs
  3. 2
      server/src/services/analytic_service/analytic_unit/types.rs

21
client/src/components/Graph.vue

@ -5,7 +5,7 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { defineComponent } from 'vue'; import { defineComponent, watch } from 'vue';
import { HasticPod, TimeRange } from "./hastic_pod"; import { HasticPod, TimeRange } from "./hastic_pod";
import { getMetrics } from '../services/metrics.service'; import { getMetrics } from '../services/metrics.service';
import { getSegments, postSegment, deleteSegment } from '../services/segments.service'; import { getSegments, postSegment, deleteSegment } from '../services/segments.service';
@ -88,7 +88,21 @@ export default defineComponent({
); );
this.pod.render(); this.pod.render();
}, },
// TODO: it's a hack: listen real events about analytics update and use store
watch: {
analyticUnitConfig(newConfig, prevConfig) {
console.log("CONFIG CHANGED");
if(prevConfig == null) {
return;
}
console.log(prevConfig);
console.log(newConfig);
this.rerender();
}
},
methods: { methods: {
// @watch('analyticUnitConfig')
rerender() { rerender() {
this.pod.fetchData(); this.pod.fetchData();
}, },
@ -96,6 +110,11 @@ export default defineComponent({
await _deleteSegment.bind(this)(0, Date.now()); await _deleteSegment.bind(this)(0, Date.now());
this.rerender(); this.rerender();
} }
},
computed: {
analyticUnitConfig() {
return this.$store.state.analyticUnitConfig;
}
} }
}); });
</script> </script>

32
server/src/services/analytic_service/analytic_service.rs

@ -109,6 +109,7 @@ impl AnalyticService {
// })); // }));
// } // }
// TODO: maybe make `consume_request` async
fn consume_request(&mut self, req: types::RequestType) -> () { fn consume_request(&mut self, req: types::RequestType) -> () {
match req { match req {
RequestType::RunLearning => { RequestType::RunLearning => {
@ -168,14 +169,13 @@ impl AnalyticService {
tx.send(self.analytic_unit_config.clone()).unwrap(); tx.send(self.analytic_unit_config.clone()).unwrap();
} }
RequestType::PatchConfig(patch_obj, tx) => { RequestType::PatchConfig(patch_obj, tx) => {
// TODO: path config self.patch_config(patch_obj, tx);
// TODO: run learning if config type changed // tx.send(()).unwrap();
self.patch_config(patch_obj);
tx.send(()).unwrap();
} }
}; };
} }
// 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 {
// TODO: handle when learning panic // TODO: handle when learning panic
@ -214,11 +214,18 @@ impl AnalyticService {
} }
} }
fn patch_config(&mut self, patch: PatchConfig) { fn patch_config(&mut self, patch: PatchConfig, tx: oneshot::Sender<()>) {
let (new_conf, need_learning) = self.analytic_unit_config.patch(patch); let (new_conf, need_learning) = 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);
// TODO: it's not fullu correct: we need to wait when the learning starts
match tx.send(()) {
Ok(_) => {},
Err(_e) => {
println!("Can`t send patch config notification");
}
}
} else { } else {
if self.analytic_unit.is_some() { if self.analytic_unit.is_some() {
tokio::spawn({ tokio::spawn({
@ -226,8 +233,21 @@ impl AnalyticService {
let cfg = self.analytic_unit_config.clone(); let cfg = self.analytic_unit_config.clone();
async move { async move {
au.unwrap().write().await.set_config(cfg); au.unwrap().write().await.set_config(cfg);
match tx.send(()) {
Ok(_) => {},
Err(_e) => {
println!("Can`t send patch config notification");
}
}
} }
}); });
} else {
match tx.send(()) {
Ok(_) => {},
Err(_e) => {
println!("Can`t send patch config notification");
}
}
} }
} }
} }

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

@ -17,7 +17,7 @@ impl Default for PatternConfig {
fn default() -> Self { fn default() -> Self {
PatternConfig { PatternConfig {
correlation_score: 0.7, correlation_score: 0.7,
anti_correlation_score: 0.7, anti_correlation_score: 0.1,
model_score: 0.5, model_score: 0.5,
threshold_score: 1.0, threshold_score: 1.0,
} }

Loading…
Cancel
Save