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 = 12; constructor(private service: CacheService) { } ngOnInit(): void { this.service.onNewTables.subscribe(() => { this.getTopKSimilar(); }); } public train() { this.service.labels = Object.assign({}, this.service.labels, this.labels); this.service.update(); } public updateQuery() { this.service.labels = Object.assign({}, this.service.labels, this.labels); this.service.getQueryWindow(this.service.labels); } 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.topk = this.service.candidates.slice(0, 20); await this.createPlots(); } async createPlots() { this.subplots = []; const values = await this.service.getWindow(this.topk); this.topk.forEach((index, i) => { this.subplots.push( { index, data: [{ x: [...Array(values[i].length).keys()], y: values[i], type: 'line' }], layout: { title: `Index: ${index.toString()}`, hovermode: 'closest', autosize: true, margin: { l: 30, r: 30, t: 30, b: 0, pad: 4 }, height: 150, width: 300, titlefont: { size: 9 }, xaxis: { showgrid: false, zeroline: false, showticklabels: false, }, yaxis: { zeroline: false, showticklabels: false, } } } ); }); } public get candidates() { return this.service.candidates; } }