Browse Source

anomaly continue

pull/25/head
Alexey Velikiy 3 years ago
parent
commit
ea6cbf13b3
  1. 43
      client/src/components/Graph.vue
  2. 21
      client/src/views/Home.vue
  3. 5
      server/src/services/analytic_service/analytic_unit/types.rs

43
client/src/components/Graph.vue

@ -5,9 +5,11 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { defineComponent, watch } from 'vue';
import { TimeRange } from "@/types"; import { TimeRange } from "@/types";
import { PatternPod } from "./pods/pattern_pod"; import { PatternPod } from "./pods/pattern_pod";
import { ThresholdPod } from './pods/threshold_pod';
import { AnomalyPod } from './pods/anomaly_pod';
import { getMetrics } from '../services/metrics.service'; import { getMetrics } from '../services/metrics.service';
import { getSegments, postSegment, deleteSegment } from '../services/segments.service'; import { getSegments, postSegment, deleteSegment } from '../services/segments.service';
import { LineTimeSerie } from "@chartwerk/line-pod"; import { LineTimeSerie } from "@chartwerk/line-pod";
@ -17,8 +19,8 @@ import { Segment, SegmentId } from '@/types/segment';
import _ from "lodash"; import _ from "lodash";
import { AnalyticUnitType } from '@/types/analytic_units'; import { AnalyticUnitType } from '@/types/analytic_units';
import { ThresholdPod } from './pods/threshold_pod';
import { defineComponent, watch } from 'vue';
// TODO: move to store // TODO: move to store
async function resolveDataPatterns(range: TimeRange): Promise<{ async function resolveDataPatterns(range: TimeRange): Promise<{
@ -79,6 +81,36 @@ async function resolveDataThreshold(range: TimeRange): Promise<{
} }
} }
// TODO: move to store
// TODO: remove code repetition
async function resolveDataAnomaly(range: TimeRange): Promise<{
timeserie: LineTimeSerie[],
segments: Segment[]
}> {
const endTime = Math.floor(range.to);
const startTime = Math.floor(range.from);
const step = Math.max(Math.round((endTime - startTime) / 5000), 1);
try {
// TODO: request in parallel
let [target, values] = await getMetrics(startTime, endTime, step);
let segments = await getSegments(startTime, endTime, false);
return {
timeserie: [{ target: target, datapoints: values, color: 'green' }],
segments: segments
}
} catch (e) {
this.$notify({
title: "Error during extracting data",
text: e,
type: 'error'
});
console.error(e);
}
}
// TODO: move to store // TODO: move to store
async function addSegment(segment: Segment): Promise<SegmentId> { async function addSegment(segment: Segment): Promise<SegmentId> {
@ -169,6 +201,13 @@ export default defineComponent({
sa sa
); );
} }
if(aut === AnalyticUnitType.ANOMALY) {
this.pod = new AnomalyPod(
document.getElementById('chart'),
resolveDataAnomaly.bind(this),
sa
);
}
this.pod.render(); this.pod.render();
} }
}, },

21
client/src/views/Home.vue

@ -32,6 +32,12 @@
<input :value="analyticUnitConfig.threshold_score" @change="thresholdScoreChange" /> <br/><br/> <input :value="analyticUnitConfig.threshold_score" @change="thresholdScoreChange" /> <br/><br/>
<button @click="clearAllLabeling"> clear all labeling </button> <button @click="clearAllLabeling"> clear all labeling </button>
</div> </div>
<div v-if="analyticUnitType == analyticUnitTypes[2]">
Alpha:
<input :value="analyticUnitConfig.alpha" @change="alphaChange" /> <br/>
Confidence:
<input :value="analyticUnitConfig.confidence" @change="confidenceChange" /> <br/><br/>
</div>
</div> </div>
</div> </div>
</template> </template>
@ -45,6 +51,7 @@ import { AnalyticUnitType } from '@/types/analytic_units';
import * as _ from 'lodash'; import * as _ from 'lodash';
// TODO: move config editig to component
export default defineComponent({ export default defineComponent({
name: 'Home', name: 'Home',
components: { components: {
@ -86,7 +93,19 @@ export default defineComponent({
let cfg = _.clone(this.analyticUnitConfig); let cfg = _.clone(this.analyticUnitConfig);
cfg.threshold_score = parseFloat(e.target.value); cfg.threshold_score = parseFloat(e.target.value);
this.$store.dispatch('patchConfig', { Pattern: cfg }); this.$store.dispatch('patchConfig', { Pattern: cfg });
} },
// Anomaly
alphaChange(e) {
let cfg = _.clone(this.analyticUnitConfig);
cfg.alpha = parseFloat(e.target.value);
this.$store.dispatch('patchConfig', { Anomaly: cfg });
},
confidenceChange(e) {
let cfg = _.clone(this.analyticUnitConfig);
cfg.confidence = parseFloat(e.target.value);
this.$store.dispatch('patchConfig', { Anomaly: cfg });
},
}, },
data: function () { data: function () {

5
server/src/services/analytic_service/analytic_unit/types.rs

@ -25,12 +25,13 @@ impl Default for PatternConfig {
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
pub struct AnomalyConfig { pub struct AnomalyConfig {
pub sesonality: bool, pub alpha: f64,
pub confidence: f64,
} }
impl Default for AnomalyConfig { impl Default for AnomalyConfig {
fn default() -> Self { fn default() -> Self {
AnomalyConfig { sesonality: false } AnomalyConfig { alpha: 0.5, confidence: 10.0 }
} }
} }

Loading…
Cancel
Save