From 375848584d5a486e3f5666e0b5e0bfdd953e4008 Mon Sep 17 00:00:00 2001 From: Alexey Velikiy Date: Mon, 8 Nov 2021 22:48:25 +0300 Subject: [PATCH] detector config on client begin --- client/src/services/analytics.service.ts | 6 ++++ client/src/store/index.ts | 40 ++++++++++++++++++------ client/src/store/types.ts | 4 --- client/src/types/analytic_units/index.ts | 14 ++++++--- client/src/views/Home.vue | 6 ++-- client/src/views/Model.vue | 1 - 6 files changed, 48 insertions(+), 23 deletions(-) delete mode 100644 client/src/store/types.ts diff --git a/client/src/services/analytics.service.ts b/client/src/services/analytics.service.ts index 51a8544..e8a9350 100644 --- a/client/src/services/analytics.service.ts +++ b/client/src/services/analytics.service.ts @@ -16,6 +16,12 @@ export async function getStatus(): Promise { return data.status; } +export async function getConfig(): Promise { + const uri = ANALYTICS_API_URL + `config`; + const res = await axios.get(uri); + return res['data'] as any; +} + export function getStatusGenerator(): AsyncIterableIterator { return getGenerator(100, getStatus); } diff --git a/client/src/store/index.ts b/client/src/store/index.ts index 98ca7b9..7e401cb 100644 --- a/client/src/store/index.ts +++ b/client/src/store/index.ts @@ -1,37 +1,43 @@ import { auth } from "./auth.module"; import { createStore } from 'vuex' -import { getStatusGenerator } from "@/services/analytics.service"; -import { AnalyticType } from './types' +import { getConfig, getStatusGenerator } from "@/services/analytics.service"; +import { DetectorConfig, DetectorType } from '@/types/analytic_units' // import { notify } from "@kyvg/vue3-notification"; const SET_ANALYTICS_STATUS = 'SET_ANALYTICS_STATUS'; -const SET_ANALYTICS_TYPE = 'SET_ANALYTICS_TYPE'; +const SET_DETECTOR_CONFIG = 'SET_DETECTOR_CONFIG'; const _SET_STATUS_GENERATOR = '_SET_STATUS_GENERATOR'; - type State = { analyticStatus: string, - analyticType?: AnalyticType, + detectorType?: DetectorType, + // TODO: maybe rename it + analyticUnitConfig?: DetectorConfig, _statusGenerator: AsyncIterableIterator } const store = createStore({ state: { analyticStatus: 'loading...', - analyticType: null, + detectorType: null, + analyticUnitConfig: null, _statusGenerator: null }, mutations: { [SET_ANALYTICS_STATUS](state, status: string) { state.analyticStatus = status; }, - [SET_ANALYTICS_TYPE](state, atype: AnalyticType) { - state.analyticType = atype; + [SET_DETECTOR_CONFIG](state, { detectorType, detectorConfig }) { + console.log(detectorType); + console.log(detectorConfig); + + state.detectorType = detectorType; + state.analyticUnitConfig = detectorConfig; }, [_SET_STATUS_GENERATOR](state, generator: AsyncIterableIterator) { - this._statusGenerator = generator; + state._statusGenerator = generator; } }, actions: { @@ -43,11 +49,25 @@ const store = createStore({ if(state._statusGenerator !== null) { return; } + const g = getStatusGenerator(); - for await (const data of g) { + commit(_SET_STATUS_GENERATOR, g); + for await (const data of state._statusGenerator) { + const st = data.toLocaleLowerCase(); + if(state.analyticStatus.toLocaleLowerCase() != 'ready' && st == 'ready') { + this.dispatch('fetchConfig'); + // TODO: update segments from here + } // this.status = data.toLowerCase(); commit(SET_ANALYTICS_STATUS, data); } + }, + async fetchConfig({commit}) { + const c = await getConfig(); + // TODO: move this logic to service getConfig() + const detectorType = c['PatternDetector'] !== undefined ? DetectorType.PATTERN : DetectorType.ANOMALY; + const detectorConfig = c['PatternDetector'] as DetectorConfig; + commit(SET_DETECTOR_CONFIG, { detectorType, detectorConfig }); } }, modules: { diff --git a/client/src/store/types.ts b/client/src/store/types.ts deleted file mode 100644 index d3a5390..0000000 --- a/client/src/store/types.ts +++ /dev/null @@ -1,4 +0,0 @@ -export enum AnalyticType { - PATTERN_DETECTOR = 'pattern detector', - ANOMALY_DETECTOR = 'anomaly detector', -} diff --git a/client/src/types/analytic_units/index.ts b/client/src/types/analytic_units/index.ts index acece0f..3fd2297 100644 --- a/client/src/types/analytic_units/index.ts +++ b/client/src/types/analytic_units/index.ts @@ -13,14 +13,18 @@ export enum DetectorType { PATTERN = 'pattern', THRESHOLD = 'threshold', ANOMALY = 'anomaly' -}; +} + +export type DetectorConfig = { + correlation_score: number, model_score: number +} export enum LabelingMode { LABELING = 'LABELING', UNLABELING = 'UNLABELING', DELETING = 'DELETING', NOT_IN_LABELING_MODE = 'NOT_IN_LABELING_MODE' -}; +} export type AnalyticSegmentPair = { analyticUnit: AnalyticUnit, segment: AnalyticSegment }; export type AnalyticSegmentsSearcher = (point: number, rangeDist: number) => AnalyticSegmentPair[]; @@ -56,8 +60,8 @@ const LABELING_MODES = []; export class AnalyticUnit { private _labelingMode: LabelingMode = LabelingMode.LABELING; - private _selected: boolean = false; - private _saving: boolean = false; + private _selected = false; + private _saving = false; private _segmentSet = new SegmentArray(); private _detectionSpans: DetectionSpan[]; private _inspect = false; @@ -143,7 +147,7 @@ export class AnalyticUnit { } removeSegmentsInRange(from: number, to: number): AnalyticSegment[] { - let deletedSegments = this._segmentSet.removeInRange(from, to); + const deletedSegments = this._segmentSet.removeInRange(from, to); return deletedSegments; } diff --git a/client/src/views/Home.vue b/client/src/views/Home.vue index 89c9120..9ea1e2e 100644 --- a/client/src/views/Home.vue +++ b/client/src/views/Home.vue @@ -21,7 +21,7 @@ import { defineComponent } from 'vue'; import Graph from '@/components/Graph.vue'; import AnalyticStatus from '@/components/AnlyticsStatus.vue'; -import { AnalyticType } from '@/store/types'; +import { DetectorType } from '@/types/analytic_units'; export default defineComponent({ @@ -37,12 +37,12 @@ export default defineComponent({ }, data: function () { return { - analyticTypes: [AnalyticType.PATTERN_DETECTOR, AnalyticType.ANOMALY_DETECTOR], + analyticTypes: [DetectorType.PATTERN, DetectorType.ANOMALY], } }, computed: { analyticType() { - return this.$store.state.analyticType; + return this.$store.state.detectorType; } } }); diff --git a/client/src/views/Model.vue b/client/src/views/Model.vue index 2ceefba..dd904d0 100644 --- a/client/src/views/Model.vue +++ b/client/src/views/Model.vue @@ -2,7 +2,6 @@
Vue logo -