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>
<script lang="ts">
import { defineComponent } from 'vue';
import { defineComponent, watch } from 'vue';
import { HasticPod, TimeRange } from "./hastic_pod";
import { getMetrics } from '../services/metrics.service';
import { getSegments, postSegment, deleteSegment } from '../services/segments.service';
@ -88,7 +88,21 @@ export default defineComponent({
);
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: {
// @watch('analyticUnitConfig')
rerender() {
this.pod.fetchData();
},
@ -96,6 +110,11 @@ export default defineComponent({
await _deleteSegment.bind(this)(0, Date.now());
this.rerender();
}
},
computed: {
analyticUnitConfig() {
return this.$store.state.analyticUnitConfig;
}
}
});
</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) -> () {
match req {
RequestType::RunLearning => {
@ -168,14 +169,13 @@ impl AnalyticService {
tx.send(self.analytic_unit_config.clone()).unwrap();
}
RequestType::PatchConfig(patch_obj, tx) => {
// TODO: path config
// TODO: run learning if config type changed
self.patch_config(patch_obj);
tx.send(()).unwrap();
self.patch_config(patch_obj, tx);
// tx.send(()).unwrap();
}
};
}
// TODO: maybe make `consume_response` async
fn consume_response(&mut self, res: types::ResponseType) {
match res {
// 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);
self.analytic_unit_config = new_conf;
if need_learning {
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 {
if self.analytic_unit.is_some() {
tokio::spawn({
@ -226,8 +233,21 @@ impl AnalyticService {
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 {
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 {
PatternConfig {
correlation_score: 0.7,
anti_correlation_score: 0.7,
anti_correlation_score: 0.1,
model_score: 0.5,
threshold_score: 1.0,
}

Loading…
Cancel
Save