import { Component, OnInit } from '@angular/core'; import {StateService} from '../state.service'; @Component({ selector: 'app-labeling-window', templateUrl: './labeling-window.component.html', styleUrls: ['./labeling-window.component.css'] }) export class LabelingWindowComponent implements OnInit { public topk: number[]; public subplots = []; public labels: boolean[] = []; private k = 12; constructor(private state: StateService) { } ngOnInit(): void { this.state.onNewTable.subscribe(() => this.showSamples()); } async train() { this.state.labels = Object.assign({}, this.state.labels, this.labels); await this.state.getQueryWindow(this.state.labels); await this.state.update(); } async updateQuery() { this.state.labels = Object.assign({}, this.state.labels, this.labels); await this.state.getQueryWindow(this.state.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 showSamples() { this.topk = this.state.lshData.average_candidates .filter((candidate) => this.state.labels[candidate] !== true) .slice(0, this.k); this.subplots = []; const values: number[][][] = await this.state.getWindow(this.topk); for (const idx in this.topk) { const window = values[idx]; const data = []; window.forEach((channel: number[], index: number) => { data.push({ x: [...Array(channel.length).keys()], y: channel, type: 'line', xaxis: 'x', yaxis: `y${index + 2}`, }); }); const subplots = []; window.forEach((channel: number[], index: number) => { subplots.push([`xy${index + 2}`]); }); const plot = { index: this.topk[idx], data: data, layout: { grid: { rows: this.state.queryWindow.length, columns: 1, subplots: subplots, }, showlegend: false, title: `Index: ${this.topk[idx].toString()}`, hovermode: 'closest', autosize: true, margin: { l: 30, r: 30, t: 30, b: 0, pad: 4 }, height: 100 * values[0].length, width: 300, titlefont: { size: 9 }, xaxis: { showgrid: false, zeroline: false, showticklabels: false, }, yaxis: { zeroline: false, showticklabels: false, } } }; window.forEach((channel: number[], index: number) => { plot.layout[`yaxis${index + 2}`] = { zeroline: false, showticklabels: false, }; }); this.subplots.push(plot); } } public get show() { return !!this.state.lshData; } }