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 _ 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<string> {
return data.status;
}
export async function getConfig(): Promise<string> {
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<string> {

25
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<string>
}
const store = createStore<State>({
state: {
analyticStatus: 'loading...',
detectorType: null,
analyticUnitType: null,
analyticUnitConfig: null,
_statusGenerator: null
},
@ -29,12 +28,9 @@ const store = createStore<State>({
[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<string>) {
state._statusGenerator = generator;
@ -63,11 +59,8 @@ const store = createStore<State>({
}
},
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: {

23
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; }

10
client/src/views/Home.vue

@ -5,7 +5,7 @@
<analytic-status />
<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>A</pre> to label anti patterns <br/>
Holde key <pre>D</pre> 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;
}
}
});

2
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};

Loading…
Cancel
Save