import { Component, OnInit } from '@angular/core'; import {CacheService} from '../cache.service'; @Component({ selector: 'app-labeling-window', templateUrl: './labeling-window.component.html', styleUrls: ['./labeling-window.component.css'] }) export class LabelingWindowComponent implements OnInit { public topk; public subplots = []; public labels: boolean[] = []; private k = 5; constructor(private service: CacheService) { } ngOnInit(): void { this.service.onNewSimilarity.subscribe(() => { this.getTopKSimilar(); }); } public changeTables() { this.service.labels = Object.assign({}, this.service.labels, this.labels); this.service.updateTables(); } public get windowSimilarity() { return this.service.windowSimilarity; } public labelCorrect(index: number) { this.labels[index] = true; } public labelUndefined(index: number) { if (this.labels[index] !== undefined) { delete this.labels[index]; } } public labelIncorrect(index: number) { this.labels[index] = false; } public getTopKSimilar() { this.labels = []; let abort = false; if (!this.windowSimilarity) { return; } let topk = []; let k = this.k; const keys = Object.keys(this.windowSimilarity).map(a => Number(a)).sort((a, b) => b - a); for (const key of keys) { const windows = this.windowSimilarity[key]; for (const index of windows) { if (this.service.labels[index] !== undefined) { continue; } topk.push({index, frequency: 100 * key / this.service.nrOfTables}); k -= 1; if (k < 1) { abort = true; break; } } if (abort) { break; } } this.topk = topk; this.subplots = []; for (const window of this.topk) { this.subplots.push( { index: window.index, data: [{ x: this.service.rawIndices.slice(window.index, window.index + this.service.windowSize), y: this.service.rawValues.slice(window.index, window.index + this.service.windowSize), type: 'line' }], layout: { title: `Index: ${window.index.toString()} Similarity: ${window.frequency.toString()}%`, hovermode: 'closest', autosize: true, margin: { l: 30, r: 30, t: 30, pad: 4 }, height: 200, width: 150, titlefont: { size: 9 }, xaxis: { showticklabels: false, } } } ); } } }