progress-view.component.ts 1.43 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
53
54
55
56
57
58
59
60
61
import { Component, OnInit } from '@angular/core';
import {CacheService} from '../cache.service';

@Component({
  selector: 'app-progress-view',
  templateUrl: './progress-view.component.html',
  styleUrls: ['./progress-view.component.css']
})
export class ProgressViewComponent implements OnInit {
  public plots;

  constructor(private cache: CacheService) { }

  ngOnInit(): void {
    this.cache.onNewSimilarity.subscribe(() => { this.initializeInfo() });
  }

  averagePlot(average) {
    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,
      }
    };
  }

  async initializeInfo(): Promise<void> {
    this.plots = [];
    const keys = Object.keys(this.similarity).map(a => Number(a)).sort((a, b) => b - a);
    const allWindows = [];
    for (const key of keys) {
      allWindows.push(this.similarity[key]);
    }
    const averages = await this.cache.getAverageWindow(allWindows);
    this.plots = averages.map(x => this.averagePlot(x));
  }

  public get similarity() {
    return this.cache.windowSimilarity;
  }
}