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()); } public get tables() { return this.service.tables; } averagePlot(average): object { return { data: [{ x: [...Array(average.length).keys()], y: average, type: 'line', }], 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, } }; } 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(''); } async createPlots() { this.subplots = []; this.averages = []; const listOfWindows = []; for (const tableIndex in this.tables) { const table = this.tables[tableIndex]; if (this.service.queryWindow) { const queryEntry = this.calculateSignature(table.hash, this.service.queryWindow); listOfWindows.push(table.entries[queryEntry]); } this.subplots.push( { data: [{ x: Object.keys(table.entries).map((hash: string) => { return Number('0b' + hash); } ), y: Object.values(table.entries).map((values: number[]) => values.length / (this.service.rawValues.length - this.service.windowSize)), type: 'bar', marker: { color: Object.values(table.entries).map((values: number[]) => { if (values.indexOf(this.service.query) > -1) { return 'red'; } return 'blue'; }) } }], 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, } } ); } if (this.service.queryWindow) { console.log(listOfWindows); 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 = data[0].y; await this.service.getSimilarWindows(); } }