import { Component, OnInit } from '@angular/core'; import {CacheService} from '../cache.service'; import {element} from 'protractor'; @Component({ selector: 'app-table-overview', templateUrl: './table-overview.component.html', styleUrls: ['./table-overview.component.css'] }) export class TableOverviewComponent implements OnInit { public subplots; public averages; constructor(private service: CacheService) { } ngOnInit(): void { this.service.onNewTables.subscribe(() => this.createPlots()); this.service.onNewSimilarity.subscribe(() => this.createPlots()); } averagePlot(average): object { return { data: [ { x: [...Array(average.average.length).keys()], y: average.average, type: 'line', }, { x: [...Array(average.average.length).keys()], y: average.max, type: 'scatter', fill: null, mode: 'lines', line: { color: 'rgb(55, 128, 191)', width: 3 } }, { x: [...Array(average.average.length).keys()], y: average.min, type: 'scatter', fill: 'tonexty', mode: 'lines', line: { color: 'rgb(55, 128, 191)', width: 3 } } ], layout: { showlegend: false, hovermode: 'closest', autosize: true, margin: { l: 10, r: 10, t: 10, b: 10, pad: 4 }, xaxis: { showticklabels: false }, yaxis: { showticklabels: false }, height: 100, width: screen.width * 0.1, } }; } calculateSignature(hashFunction, window): string { const output = new Array(hashFunction[0].length); output.fill(0); for (const hash of hashFunction) { for (let i = 0; i < hash.length; i++) { output[i] += window[i] * hash[i]; } } return output.map((x) => x > 0 ? '1' : '0').join(''); } distanceMetric(hash) { let sum = 0; for (let i = 0; i < hash.length; i++) { if (hash[i] === '1') { sum++; } } return sum; } async createPlots() { this.subplots = []; this.averages = []; const listOfWindows = []; for (const tableIndex in this.tables) { const table = this.tables[tableIndex]; let rank = undefined; let opacity = new Array(Object.keys(table.entries).length); opacity.fill(1); const orderedHashes = Object.keys(table.entries).sort((hash1, hash2) => { return this.distanceMetric(hash1) - this.distanceMetric(hash2); }); if (this.service.queryWindow) { const queryEntry = this.calculateSignature(table.hash, this.service.queryWindow[0]); listOfWindows.push(table.entries[queryEntry]); opacity = orderedHashes.map((hash: string) => { return hash === queryEntry ? 1.0 : 0.5; } ); rank = table.entries[queryEntry].length; } this.subplots.push( { rank: rank, data: [{ x: orderedHashes.map((hash: string, i) => { return i; // Number('0b' + hash); } ), y: orderedHashes.map((hash: string) => table.entries[hash].length ), // / (this.service.rawValues.length - this.service.windowSize)), type: 'bar', marker: { opacity } }], layout: { hovermode: 'closest', autosize: true, margin: { l: 10, r: 10, t: 10, b: 10, pad: 4 }, xaxis: { showticklabels: false }, yaxis: { showticklabels: false }, height: 100, width: screen.width * 0.1, } } ); } this.subplots.sort((plot1, plot2) => plot1.rank - plot2.rank); if (this.service.queryWindow) { const temp = await this.service.getAverageTableWindows(listOfWindows); this.averages = temp.map(x => this.averagePlot(x)); } } async setQuery(data) { console.log('clicked for query'); this.service.queryWindow = await this.service.getQueryWindow(data[0].y); await this.service.getSimilarWindows(); } public get tables() { return this.service.tables; } public get visible() { return !this.service.querySelectionMode; } }