table-overview.component.ts 3.32 KB
Newer Older
1
2
import { Component, OnInit } from '@angular/core';
import {CacheService} from '../cache.service';
3
import {element} from 'protractor';
4
5
6
7
8
9
10
11

@Component({
  selector: 'app-table-overview',
  templateUrl: './table-overview.component.html',
  styleUrls: ['./table-overview.component.css']
})
export class TableOverviewComponent implements OnInit {
  public subplots;
12
  public averages;
13
14
15
16
  constructor(private service: CacheService) { }

  ngOnInit(): void {
    this.service.onNewTables.subscribe(() => this.createPlots());
17
    this.service.onNewSimilarity.subscribe(() => this.createPlots());
18
19
20
21
22
23
  }

  public get tables() {
    return this.service.tables;
  }

24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
  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,
      }
    };
  }

53
54
55
56
57
58
59
60
61
62
63
  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('');
  }

64
  async createPlots() {
65
    this.subplots = [];
66
67
    this.averages = [];
    const listOfWindows = [];
68
69
    for (const tableIndex in this.tables) {
      const table = this.tables[tableIndex];
70
71
      if (this.service.queryWindow) {
        const queryEntry = this.calculateSignature(table.hash, this.service.queryWindow);
72
73
        listOfWindows.push(table.entries[queryEntry]);
      }
74
75
76
77
      this.subplots.push(
        {
          data: [{
            x: Object.keys(table.entries).map((hash: string) => {
78
              return Number('0b' + hash);
79
80
              }
            ),
81
82
83
84
85
86
87
88
89
90
            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';
              })
            }
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
          }],
          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,
          }
        }
      );
    }
114
    if (this.service.queryWindow) {
115
116
      console.log(listOfWindows);
      const temp = await this.service.getAverageTableWindows(listOfWindows);
117
118
      this.averages = temp.map(x => this.averagePlot(x));
    }
119
  }
120

121
122
123
124
  async setQuery(data) {
    console.log('clicked for query');
    this.service.queryWindow = data[0].y;
    await this.service.getSimilarWindows();
125
  }
126
}