diff --git a/client/src/components/Graph.vue b/client/src/components/Graph.vue index 26d31f2..e5a9516 100644 --- a/client/src/components/Graph.vue +++ b/client/src/components/Graph.vue @@ -118,7 +118,6 @@ export default defineComponent({ }, // TODO: it's a hack: listen real events about analytics update and use store watch: { - // TODO: choose pog based on config type analyticUnitConfig(newConfig, prevConfig) { if(prevConfig == null) { return; @@ -135,7 +134,6 @@ export default defineComponent({ } }, methods: { - // @watch('analyticUnitConfig') rerender() { this.pod.fetchData(); }, @@ -154,7 +152,7 @@ export default defineComponent({ if(aut == null) { return; } - + if(aut === AnalyticUnitType.PATTERN) { this.pod = new PatternPod( document.getElementById('chart'), diff --git a/client/src/components/pods/anomaly_pod.ts b/client/src/components/pods/anomaly_pod.ts new file mode 100644 index 0000000..6b8256a --- /dev/null +++ b/client/src/components/pods/anomaly_pod.ts @@ -0,0 +1,51 @@ +import { HasticPod } from './hastic_pod'; +import { TimeRange } from '@/types'; + +import { Segment } from "@/types/segment"; +import { LineTimeSerie } from '@chartwerk/line-pod'; +import { SegmentsSet } from '@/types/segment_set'; + + +export type UpdateDataCallback = (range: TimeRange) => Promise<{ + timeserie: LineTimeSerie[], + segments: Segment[] +}>; + + +export class AnomalyPod extends HasticPod { + + constructor( + el: HTMLElement, + udc: UpdateDataCallback, + segmentSet: SegmentsSet + ) { + super(el, udc, segmentSet) + + this.fetchData(); + } + + // TODO: implement renderMetrics + + public fetchData(): void { + let to = Math.floor(Date.now() / 1000); + let from = to - 50000; // -50000 seconds + + if(!(this.state.xValueRange[0] == 0 && this.state.xValueRange[1] == 1)) { + [from, to] = this.state?.xValueRange; + } + + this.udc({ from, to }) + .then(resp => { + this.updateSegments(resp.segments); + this.updateData(resp.timeserie, undefined, true); + }) + .catch(() => { /* set "error" message */ }) + } + + + protected updateSegments(segments: Segment[]): void { + this.segmentSet.clear(); + this.segmentSet.setSegments(segments); + } + +} \ No newline at end of file diff --git a/client/src/components/pods/pattern_pod.ts b/client/src/components/pods/pattern_pod.ts index d169e6d..cee788a 100644 --- a/client/src/components/pods/pattern_pod.ts +++ b/client/src/components/pods/pattern_pod.ts @@ -157,13 +157,10 @@ export class PatternPod extends HasticPod { } const segment = new Segment(id, from, to, type); - //const storedId = + await this._csc(segment); this.fetchData(); - // segment.id = storedId; - // this._segmentSet.addSegment(segment); - // this.renderSegment(segment); } protected async deleteSegment(from: number, to: number): Promise { @@ -181,7 +178,7 @@ export class PatternPod extends HasticPod { } - + // TODO: maybe not override this protected updateSegments(segments: Segment[]): void { this.segmentSet.clear(); this.segmentSet.setSegments(segments); diff --git a/client/src/components/pods/threshold_pod.ts b/client/src/components/pods/threshold_pod.ts index a8c0a14..a2341ea 100644 --- a/client/src/components/pods/threshold_pod.ts +++ b/client/src/components/pods/threshold_pod.ts @@ -41,7 +41,7 @@ export class ThresholdPod extends HasticPod { .catch(() => { /* set "error" message */ }) } - + // TODO: maybe not override this protected updateSegments(segments: Segment[]): void { this.segmentSet.clear(); this.segmentSet.setSegments(segments);