diff --git a/client/src/services/analytics.service.ts b/client/src/services/analytics.service.ts index e8a9350..721a78d 100644 --- a/client/src/services/analytics.service.ts +++ b/client/src/services/analytics.service.ts @@ -6,6 +6,10 @@ import axios from 'axios'; import { getGenerator } from '@/utils'; import _ from 'lodash'; +import { + AnalyticUnitType, AnlyticUnitConfig, + PatternConfig, ThresholdConfig, AnomalyConfig +} from "@/types/analytic_units"; const ANALYTICS_API_URL = API_URL + "analytics/"; @@ -16,10 +20,32 @@ export async function getStatus(): Promise { return data.status; } -export async function getConfig(): Promise { +export async function getConfig(): Promise<[AnalyticUnitType, AnlyticUnitConfig]> { const uri = ANALYTICS_API_URL + `config`; const res = await axios.get(uri); - return res['data'] as any; + + const data = res['data']; + + let analyticUnitType = AnalyticUnitType.ANOMALY; + let analyticUnitConfig = undefined; + if(data['Pattern'] !== undefined) { + analyticUnitType = AnalyticUnitType.PATTERN; + analyticUnitConfig = data['Pattern'] as PatternConfig + } + if(data['Threshold'] !== undefined) { + analyticUnitType = AnalyticUnitType.THRESHOLD; + analyticUnitConfig = data['Threshold'] as ThresholdConfig + } + if(data['Anomaly'] !== undefined) { + analyticUnitType = AnalyticUnitType.ANOMALY; + analyticUnitConfig = data['Anomaly'] as AnomalyConfig + } + + if(analyticUnitConfig === undefined) { + throw new Error("unknows config type" + _.keys(data)); + } + + return [analyticUnitType, analyticUnitConfig]; } export function getStatusGenerator(): AsyncIterableIterator { diff --git a/client/src/store/index.ts b/client/src/store/index.ts index 7e401cb..d0c1f55 100644 --- a/client/src/store/index.ts +++ b/client/src/store/index.ts @@ -1,7 +1,7 @@ import { auth } from "./auth.module"; import { createStore } from 'vuex' import { getConfig, getStatusGenerator } from "@/services/analytics.service"; -import { DetectorConfig, DetectorType } from '@/types/analytic_units' +import { AnlyticUnitConfig, AnalyticUnitType } from '@/types/analytic_units' // import { notify } from "@kyvg/vue3-notification"; @@ -12,16 +12,15 @@ const _SET_STATUS_GENERATOR = '_SET_STATUS_GENERATOR'; type State = { analyticStatus: string, - detectorType?: DetectorType, - // TODO: maybe rename it - analyticUnitConfig?: DetectorConfig, + analyticUnitType?: AnalyticUnitType, + analyticUnitConfig?: AnlyticUnitConfig, _statusGenerator: AsyncIterableIterator } const store = createStore({ state: { analyticStatus: 'loading...', - detectorType: null, + analyticUnitType: null, analyticUnitConfig: null, _statusGenerator: null }, @@ -29,12 +28,9 @@ const store = createStore({ [SET_ANALYTICS_STATUS](state, status: string) { state.analyticStatus = status; }, - [SET_DETECTOR_CONFIG](state, { detectorType, detectorConfig }) { - console.log(detectorType); - console.log(detectorConfig); - - state.detectorType = detectorType; - state.analyticUnitConfig = detectorConfig; + [SET_DETECTOR_CONFIG](state, { analyticUnitType, analyticUnitConfig }) { + state.analyticUnitType = analyticUnitType; + state.analyticUnitConfig = analyticUnitConfig; }, [_SET_STATUS_GENERATOR](state, generator: AsyncIterableIterator) { state._statusGenerator = generator; @@ -63,11 +59,8 @@ const store = createStore({ } }, 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 }); + const [analyticUnitType, analyticUnitConfig] = await getConfig(); + commit(SET_DETECTOR_CONFIG, { analyticUnitType, analyticUnitConfig }); } }, modules: { diff --git a/client/src/types/analytic_units/index.ts b/client/src/types/analytic_units/index.ts index 3fd2297..f308f53 100644 --- a/client/src/types/analytic_units/index.ts +++ b/client/src/types/analytic_units/index.ts @@ -9,16 +9,27 @@ import _ from 'lodash'; // TODO: move types to ./types -export enum DetectorType { +export enum AnalyticUnitType { PATTERN = 'pattern', THRESHOLD = 'threshold', ANOMALY = 'anomaly' } -export type DetectorConfig = { - correlation_score: number, model_score: number +export type PatternConfig = { + correlation_score: number, + model_score: number } +export type ThresholdConfig = { + threashold: number +} + +export type AnomalyConfig = { + threashold: number +} + +export type AnlyticUnitConfig = PatternConfig | ThresholdConfig; + export enum LabelingMode { LABELING = 'LABELING', UNLABELING = 'UNLABELING', @@ -47,7 +58,7 @@ const DEFAULTS = { id: null, name: 'AnalyticUnitName', type: 'GENERAL', - detectorType: DetectorType.PATTERN, + detectorType: AnalyticUnitType.PATTERN, labeledColor: ANALYTIC_UNIT_COLORS[0], deletedColor: DEFAULT_DELETED_SEGMENT_COLOR, alert: false, @@ -100,8 +111,8 @@ export class AnalyticUnit { set name(value: string) { this._serverObject.name = value; } get name(): string { return this._serverObject.name; } - set detectorType(value: DetectorType) { this._serverObject.detectorType = value; } - get detectorType(): DetectorType { return this._serverObject.detectorType; } + set detectorType(value: AnalyticUnitType) { this._serverObject.detectorType = value; } + get detectorType(): AnalyticUnitType { return this._serverObject.detectorType; } set type(value: string) { this._serverObject.type = value; } get type(): string { return this._serverObject.type; } diff --git a/client/src/views/Home.vue b/client/src/views/Home.vue index 9ea1e2e..bfa4564 100644 --- a/client/src/views/Home.vue +++ b/client/src/views/Home.vue @@ -5,7 +5,7 @@
-
+
Hold
S
to label patterns
Hold
A
to label anti patterns
Holde key
D
to delete patterns @@ -21,7 +21,7 @@ import { defineComponent } from 'vue'; import Graph from '@/components/Graph.vue'; import AnalyticStatus from '@/components/AnlyticsStatus.vue'; -import { DetectorType } from '@/types/analytic_units'; +import { AnalyticUnitType } from '@/types/analytic_units'; export default defineComponent({ @@ -37,12 +37,12 @@ export default defineComponent({ }, data: function () { return { - analyticTypes: [DetectorType.PATTERN, DetectorType.ANOMALY], + analyticUnitTypes: [AnalyticUnitType.THRESHOLD, AnalyticUnitType.PATTERN, AnalyticUnitType.ANOMALY], } }, computed: { - analyticType() { - return this.$store.state.detectorType; + analyticUnitType() { + return this.$store.state.analyticUnitType; } } }); diff --git a/server/src/services/analytic_service/analytic_service.rs b/server/src/services/analytic_service/analytic_service.rs index dbc4f71..776bbc1 100644 --- a/server/src/services/analytic_service/analytic_service.rs +++ b/server/src/services/analytic_service/analytic_service.rs @@ -13,7 +13,7 @@ use crate::services::{ metric_service::MetricService, segments_service::{self, Segment, SegmentType, SegmentsService, ID_LENGTH}, }; -use crate::utils::{self, get_random_str}; +use crate::utils::{self}; use crate::services::analytic_service::analytic_unit::types::{AnalyticUnit, LearningResult};