Browse Source

analytic units on client

pull/25/head
Alexey Velikiy 3 years ago
parent
commit
adbf62a4c0
  1. 30
      client/src/services/analytics.service.ts
  2. 25
      client/src/store/index.ts
  3. 23
      client/src/types/analytic_units/index.ts
  4. 10
      client/src/views/Home.vue
  5. 2
      server/src/services/analytic_service/analytic_service.rs

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

@ -6,6 +6,10 @@ import axios from 'axios';
import { getGenerator } from '@/utils'; import { getGenerator } from '@/utils';
import _ from 'lodash'; import _ from 'lodash';
import {
AnalyticUnitType, AnlyticUnitConfig,
PatternConfig, ThresholdConfig, AnomalyConfig
} from "@/types/analytic_units";
const ANALYTICS_API_URL = API_URL + "analytics/"; const ANALYTICS_API_URL = API_URL + "analytics/";
@ -16,10 +20,32 @@ export async function getStatus(): Promise<string> {
return data.status; return data.status;
} }
export async function getConfig(): Promise<string> { export async function getConfig(): Promise<[AnalyticUnitType, AnlyticUnitConfig]> {
const uri = ANALYTICS_API_URL + `config`; const uri = ANALYTICS_API_URL + `config`;
const res = await axios.get(uri); 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<string> { export function getStatusGenerator(): AsyncIterableIterator<string> {

25
client/src/store/index.ts

@ -1,7 +1,7 @@
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 } from "@/services/analytics.service";
import { DetectorConfig, DetectorType } from '@/types/analytic_units' import { AnlyticUnitConfig, AnalyticUnitType } from '@/types/analytic_units'
// import { notify } from "@kyvg/vue3-notification"; // import { notify } from "@kyvg/vue3-notification";
@ -12,16 +12,15 @@ const _SET_STATUS_GENERATOR = '_SET_STATUS_GENERATOR';
type State = { type State = {
analyticStatus: string, analyticStatus: string,
detectorType?: DetectorType, analyticUnitType?: AnalyticUnitType,
// TODO: maybe rename it analyticUnitConfig?: AnlyticUnitConfig,
analyticUnitConfig?: DetectorConfig,
_statusGenerator: AsyncIterableIterator<string> _statusGenerator: AsyncIterableIterator<string>
} }
const store = createStore<State>({ const store = createStore<State>({
state: { state: {
analyticStatus: 'loading...', analyticStatus: 'loading...',
detectorType: null, analyticUnitType: null,
analyticUnitConfig: null, analyticUnitConfig: null,
_statusGenerator: null _statusGenerator: null
}, },
@ -29,12 +28,9 @@ const store = createStore<State>({
[SET_ANALYTICS_STATUS](state, status: string) { [SET_ANALYTICS_STATUS](state, status: string) {
state.analyticStatus = status; state.analyticStatus = status;
}, },
[SET_DETECTOR_CONFIG](state, { detectorType, detectorConfig }) { [SET_DETECTOR_CONFIG](state, { analyticUnitType, analyticUnitConfig }) {
console.log(detectorType); state.analyticUnitType = analyticUnitType;
console.log(detectorConfig); state.analyticUnitConfig = analyticUnitConfig;
state.detectorType = detectorType;
state.analyticUnitConfig = detectorConfig;
}, },
[_SET_STATUS_GENERATOR](state, generator: AsyncIterableIterator<string>) { [_SET_STATUS_GENERATOR](state, generator: AsyncIterableIterator<string>) {
state._statusGenerator = generator; state._statusGenerator = generator;
@ -63,11 +59,8 @@ const store = createStore<State>({
} }
}, },
async fetchConfig({commit}) { async fetchConfig({commit}) {
const c = await getConfig(); const [analyticUnitType, analyticUnitConfig] = await getConfig();
// TODO: move this logic to service getConfig() commit(SET_DETECTOR_CONFIG, { analyticUnitType, analyticUnitConfig });
const detectorType = c['PatternDetector'] !== undefined ? DetectorType.PATTERN : DetectorType.ANOMALY;
const detectorConfig = c['PatternDetector'] as DetectorConfig;
commit(SET_DETECTOR_CONFIG, { detectorType, detectorConfig });
} }
}, },
modules: { modules: {

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

@ -9,16 +9,27 @@ import _ from 'lodash';
// TODO: move types to ./types // TODO: move types to ./types
export enum DetectorType { export enum AnalyticUnitType {
PATTERN = 'pattern', PATTERN = 'pattern',
THRESHOLD = 'threshold', THRESHOLD = 'threshold',
ANOMALY = 'anomaly' ANOMALY = 'anomaly'
} }
export type DetectorConfig = { export type PatternConfig = {
correlation_score: number, model_score: number correlation_score: number,
model_score: number
} }
export type ThresholdConfig = {
threashold: number
}
export type AnomalyConfig = {
threashold: number
}
export type AnlyticUnitConfig = PatternConfig | ThresholdConfig;
export enum LabelingMode { export enum LabelingMode {
LABELING = 'LABELING', LABELING = 'LABELING',
UNLABELING = 'UNLABELING', UNLABELING = 'UNLABELING',
@ -47,7 +58,7 @@ const DEFAULTS = {
id: null, id: null,
name: 'AnalyticUnitName', name: 'AnalyticUnitName',
type: 'GENERAL', type: 'GENERAL',
detectorType: DetectorType.PATTERN, detectorType: AnalyticUnitType.PATTERN,
labeledColor: ANALYTIC_UNIT_COLORS[0], labeledColor: ANALYTIC_UNIT_COLORS[0],
deletedColor: DEFAULT_DELETED_SEGMENT_COLOR, deletedColor: DEFAULT_DELETED_SEGMENT_COLOR,
alert: false, alert: false,
@ -100,8 +111,8 @@ export class AnalyticUnit {
set name(value: string) { this._serverObject.name = value; } set name(value: string) { this._serverObject.name = value; }
get name(): string { return this._serverObject.name; } get name(): string { return this._serverObject.name; }
set detectorType(value: DetectorType) { this._serverObject.detectorType = value; } set detectorType(value: AnalyticUnitType) { this._serverObject.detectorType = value; }
get detectorType(): DetectorType { return this._serverObject.detectorType; } get detectorType(): AnalyticUnitType { return this._serverObject.detectorType; }
set type(value: string) { this._serverObject.type = value; } set type(value: string) { this._serverObject.type = value; }
get type(): string { return this._serverObject.type; } get type(): string { return this._serverObject.type; }

10
client/src/views/Home.vue

@ -5,7 +5,7 @@
<analytic-status /> <analytic-status />
<div id="controls"> <div id="controls">
<div v-if="analyticType == analyticTypes[0]"> <div v-if="analyticUnitType == analyticUnitTypes[1]">
Hold <pre>S</pre> to label patterns <br/> Hold <pre>S</pre> to label patterns <br/>
Hold <pre>A</pre> to label anti patterns <br/> Hold <pre>A</pre> to label anti patterns <br/>
Holde key <pre>D</pre> to delete patterns Holde key <pre>D</pre> to delete patterns
@ -21,7 +21,7 @@
import { defineComponent } from 'vue'; import { defineComponent } from 'vue';
import Graph from '@/components/Graph.vue'; import Graph from '@/components/Graph.vue';
import AnalyticStatus from '@/components/AnlyticsStatus.vue'; import AnalyticStatus from '@/components/AnlyticsStatus.vue';
import { DetectorType } from '@/types/analytic_units'; import { AnalyticUnitType } from '@/types/analytic_units';
export default defineComponent({ export default defineComponent({
@ -37,12 +37,12 @@ export default defineComponent({
}, },
data: function () { data: function () {
return { return {
analyticTypes: [DetectorType.PATTERN, DetectorType.ANOMALY], analyticUnitTypes: [AnalyticUnitType.THRESHOLD, AnalyticUnitType.PATTERN, AnalyticUnitType.ANOMALY],
} }
}, },
computed: { computed: {
analyticType() { analyticUnitType() {
return this.$store.state.detectorType; return this.$store.state.analyticUnitType;
} }
} }
}); });

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

@ -13,7 +13,7 @@ use crate::services::{
metric_service::MetricService, metric_service::MetricService,
segments_service::{self, Segment, SegmentType, SegmentsService, ID_LENGTH}, 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}; use crate::services::analytic_service::analytic_unit::types::{AnalyticUnit, LearningResult};

Loading…
Cancel
Save