Browse Source

config update continue

pull/25/head
Alexey Velikiy 3 years ago
parent
commit
d6212104ab
  1. 5
      client/src/services/analytics.service.ts
  2. 12
      client/src/store/index.ts
  3. 6
      client/src/types/analytic_units/index.ts
  4. 14
      client/src/views/Home.vue
  5. 30
      server/src/api/analytics.rs
  6. 2
      server/src/api/mod.rs

5
client/src/services/analytics.service.ts

@ -48,6 +48,11 @@ export async function getConfig(): Promise<[AnalyticUnitType, AnlyticUnitConfig]
return [analyticUnitType, analyticUnitConfig]; return [analyticUnitType, analyticUnitConfig];
} }
export async function patchConfig(patchObj: any) {
const uri = ANALYTICS_API_URL + `config`;
await axios.patch(uri, patchObj);
}
export function getStatusGenerator(): AsyncIterableIterator<string> { export function getStatusGenerator(): AsyncIterableIterator<string> {
return getGenerator<string>(100, getStatus); return getGenerator<string>(100, getStatus);
} }

12
client/src/store/index.ts

@ -1,14 +1,17 @@
import { auth } from "./auth.module"; import { auth } from "./auth.module";
import { createStore } from 'vuex' import { createStore } from 'vuex'
import { getConfig, getStatusGenerator } from "@/services/analytics.service"; import { getConfig, getStatusGenerator, patchConfig } from "@/services/analytics.service";
import { AnlyticUnitConfig, AnalyticUnitType } from '@/types/analytic_units' import { AnlyticUnitConfig, AnalyticUnitType } from '@/types/analytic_units'
// import { notify } from "@kyvg/vue3-notification"; // import { notify } from "@kyvg/vue3-notification";
const SET_ANALYTICS_STATUS = 'SET_ANALYTICS_STATUS'; const SET_ANALYTICS_STATUS = 'SET_ANALYTICS_STATUS';
const SET_DETECTOR_CONFIG = 'SET_DETECTOR_CONFIG'; const SET_DETECTOR_CONFIG = 'SET_DETECTOR_CONFIG';
// const PATCH_CONFIG = 'PATCH_CONFIG';
const _SET_STATUS_GENERATOR = '_SET_STATUS_GENERATOR'; const _SET_STATUS_GENERATOR = '_SET_STATUS_GENERATOR';
// TODO: consts for actions
type State = { type State = {
analyticStatus: string, analyticStatus: string,
@ -32,6 +35,9 @@ const store = createStore<State>({
state.analyticUnitType = analyticUnitType; state.analyticUnitType = analyticUnitType;
state.analyticUnitConfig = analyticUnitConfig; state.analyticUnitConfig = analyticUnitConfig;
}, },
// [PATCH_CONFIG](state, patchObj) {
// patchConfig(patchConfig)
// }
[_SET_STATUS_GENERATOR](state, generator: AsyncIterableIterator<string>) { [_SET_STATUS_GENERATOR](state, generator: AsyncIterableIterator<string>) {
state._statusGenerator = generator; state._statusGenerator = generator;
} }
@ -65,6 +71,10 @@ const store = createStore<State>({
async fetchConfig({commit}) { async fetchConfig({commit}) {
const [analyticUnitType, analyticUnitConfig] = await getConfig(); const [analyticUnitType, analyticUnitConfig] = await getConfig();
commit(SET_DETECTOR_CONFIG, { analyticUnitType, analyticUnitConfig }); commit(SET_DETECTOR_CONFIG, { analyticUnitType, analyticUnitConfig });
},
async patchConfig({commit}, payload) {
patchConfig(payload);
this.dispatch('fetchConfig');
} }
}, },
modules: { modules: {

6
client/src/types/analytic_units/index.ts

@ -10,9 +10,9 @@ import _ from 'lodash';
// TODO: move types to ./types // TODO: move types to ./types
export enum AnalyticUnitType { export enum AnalyticUnitType {
PATTERN = 'pattern', PATTERN = 'Pattern',
THRESHOLD = 'threshold', THRESHOLD = 'Threshold',
ANOMALY = 'anomaly' ANOMALY = 'Anomaly'
} }
export type PatternConfig = { export type PatternConfig = {

14
client/src/views/Home.vue

@ -5,7 +5,7 @@
<analytic-status /> <analytic-status />
<div> <div>
Analytic unit type: <select :value="analyticUnitType" @input="changeAnalyticUnitType"> Analytic unit type: <select :value="analyticUnitType" @change="changeAnalyticUnitType">
<option disabled value="">Please Select</option> <option disabled value="">Please Select</option>
<option v-bind:key="option" v-for="option in analyticUnitTypes" :value="option">{{option}}</option> <option v-bind:key="option" v-for="option in analyticUnitTypes" :value="option">{{option}}</option>
</select> <br/><br/> </select> <br/><br/>
@ -18,9 +18,9 @@
<br/> <br/>
<hr/> <hr/>
Correlation score: Correlation score:
<input :value="analyticUnitConfig.correlation_score" @input="correlationScoreChange" /> <br/> <input :value="analyticUnitConfig.correlation_score" @change="correlationScoreChange" /> <br/>
Model score: Model score:
<input :value="analyticUnitConfig.model_score" @input="modelScoreChange" /> <br/><br/> <input :value="analyticUnitConfig.model_score" @change="modelScoreChange" /> <br/><br/>
<button @click="clearAllLabeling"> clear all labeling </button> <button @click="clearAllLabeling"> clear all labeling </button>
</div> </div>
</div> </div>
@ -45,15 +45,13 @@ export default defineComponent({
this.$refs.graph.deleteAllSegments(); this.$refs.graph.deleteAllSegments();
}, },
changeAnalyticUnitType(e) { changeAnalyticUnitType(e) {
console.log(e); this.$store.dispatch('patchConfig', { [e.target.value]: true } );
}, },
correlationScoreChange(e) { correlationScoreChange(e) {
// TODO: store value this.$store.dispatch('patchConfig', { Pattern: { correlation_score: e.target.value } });
console.log(e);
}, },
modelScoreChange(e) { modelScoreChange(e) {
// TODO: store value this.$store.dispatch('patchConfig', { Pattern: { model_score: e.target.value } });
console.log(e);
} }
}, },
data: function () { data: function () {

30
server/src/api/analytics.rs

@ -10,6 +10,7 @@ pub mod filters {
list(client.clone()) list(client.clone())
.or(status(client.clone())) .or(status(client.clone()))
.or(get_config(client.clone())) .or(get_config(client.clone()))
.or(put_config(client.clone()))
// .or(list_train(client.clone())) // .or(list_train(client.clone()))
// .or(create(db.clone())) // .or(create(db.clone()))
// // .or(update(db.clone())) // // .or(update(db.clone()))
@ -44,7 +45,18 @@ pub mod filters {
warp::path!("analytics" / "config") warp::path!("analytics" / "config")
.and(warp::get()) .and(warp::get())
.and(with_client(client)) .and(with_client(client))
.and_then(handlers::config) .and_then(handlers::get_config)
}
/// PATCH /analytics/config
pub fn put_config(
client: Client,
) -> impl Filter<Extract = impl warp::Reply, Error = warp::Rejection> + Clone {
warp::path!("analytics" / "config")
.and(warp::patch())
.and(with_client(client))
.and(warp::body::json())
.and_then(handlers::patch_config)
} }
/// GET /analytics/model /// GET /analytics/model
@ -66,6 +78,8 @@ pub mod filters {
mod handlers { mod handlers {
use serde_json::Value;
use super::models::{Client, ListOptions, Status}; use super::models::{Client, ListOptions, Status};
use crate::api::{BadQuery, API}; use crate::api::{BadQuery, API};
@ -93,7 +107,19 @@ mod handlers {
} }
} }
pub async fn config(client: Client) -> Result<impl warp::Reply, warp::Rejection> { pub async fn get_config(client: Client) -> Result<impl warp::Reply, warp::Rejection> {
match client.get_config().await {
Ok(cf) => Ok(API::json(&cf)),
Err(e) => {
println!("{:?}", e);
Err(warp::reject::custom(BadQuery))
}
}
}
pub async fn patch_config(client: Client, obj: Value) -> Result<impl warp::Reply, warp::Rejection> {
println!("{:?}", obj);
match client.get_config().await { match client.get_config().await {
Ok(cf) => Ok(API::json(&cf)), Ok(cf) => Ok(API::json(&cf)),
Err(e) => { Err(e) => {

2
server/src/api/mod.rs

@ -63,7 +63,7 @@ impl API<'_> {
hs.insert("Access-Control-Allow-Origin", HeaderValue::from_static("*")); hs.insert("Access-Control-Allow-Origin", HeaderValue::from_static("*"));
hs.insert( hs.insert(
"Access-Control-Allow-Methods", "Access-Control-Allow-Methods",
HeaderValue::from_static("POST, GET, OPTIONS, DELETE"), HeaderValue::from_static("POST, GET, OPTIONS, DELETE, PATCH"),
); );
hs.insert( hs.insert(
"Access-Control-Allow-Headers", "Access-Control-Allow-Headers",

Loading…
Cancel
Save