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 train() { this.service.labels = Object.assign({}, this.service.labels, this.labels); this.service.updateTables(); } 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; } async getTopKSimilar() { this.labels = []; let abort = false; const topk = []; let k = this.k; const keys = Object.keys(this.windowSimilarity).map(a => Number(a)).sort((a, b) => b - a); for (let i = 0; i < this.k; i++) { const windows = this.windowSimilarity[keys[i]]; this.shuffleArray(windows); for (const index of windows) { if (this.service.labels[index] !== undefined) { continue; } topk.push({index, frequency: 100 * keys[i] / this.service.nrOfTables}); k -= 1; if (k < 1) { abort = true; break; } // break; } if (abort) { break; } } this.topk = topk; await this.createPlots(); } async createPlots() { this.subplots = []; const values = await this.service.getWindow(this.topk.map((window) => window.index)); this.topk.forEach((window, i) => { this.subplots.push( { index: window.index, data: [{ x: [...Array(values[i].length).keys()], y: values[i], type: 'line' }], layout: { title: `Index: ${window.index.toString()} Similarity: ${window.frequency.toString()}%`, hovermode: 'closest', autosize: true, margin: { l: 30, r: 30, t: 30, b: 0, pad: 4 }, height: 150, width: 150, titlefont: { size: 9 }, xaxis: { showgrid: false, zeroline: false, showticklabels: false, }, yaxis: { zeroline: false, showticklabels: false, } } } ); }); } shuffleArray(array) { for (var i = array.length - 1; i > 0; i--) { const j = Math.floor(Math.random() * (i + 1)); const temp = array[i]; array[i] = array[j]; array[j] = temp; } } public get windowSimilarity() { return this.service.windowSimilarity; } }