progress-view.component.ts 3.5 KB
Newer Older
1
2
3
4
5
6
7
8
9
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 {
10
  public plot;
11
12
  public data;
  public layout;
13

Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
14
15
  private _sliderValue;

16
17
18
  constructor(private cache: CacheService) { }

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

Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
22
  averagePlot(averages) {
23
    let highest = 100;
24
25
    let data = averages.map((average, i) => {
      if (average.average.length !== 0 && i < highest) {
26
27
        highest = i;
      }
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
      return [
        {
          x: [...Array(average.average.length).keys()],
          y: average.average,
          type: 'line',
          visible: i === highest,
        },
        {
          x: [...Array(average.average.length).keys()],
          y: average.max,
          type: 'scatter',
          visible: i === highest,
          fill: null,
          mode: 'lines',
          line: {
            color: 'rgb(55, 128, 191)',
            width: 3
          }
          },
        {
          x: [...Array(average.average.length).keys()],
          y: average.min,
          type: 'scatter',
          visible: i === highest,
          fill: 'tonexty',
          mode: 'lines',
          line: {
            color: 'rgb(55, 128, 191)',
            width: 3
          }
          },
      ];
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
60
    });
61
62
    data = [].concat(...data);
    const visibility = Array(averages.length * 3).fill(false);
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
63
64
65
    const steps = [];
    for (let i = averages.length - 1; i >= 0; i--) {
      const v = visibility.slice();
66
67
68
      v[i * 3 + 2] = true;
      v[i * 3 + 1] = true;
      v[i * 3] = true;
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
69
70
71
72
73
74
      steps.push({
        label: (100 * (averages.length - i) / averages.length).toString() + '%',
        method: 'restyle',
        args: ['visible', v]
      });
    }
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
75
    this._sliderValue = averages.length - 1 - highest;
76
77
78
79
80
81
82
83
84
85
    this.data = data;
    this.layout = {
      showlegend: false,
      hovermode: 'closest',
      autosize: true,
      margin: {
        l: 50,
        r: 30,
        t: 30,
        pad: 4
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
86
      },
87
      xaxis: {
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
88
89
90
        showgrid: false,
        zeroline: false,
        showticklabels: false,
91
92
      },
      yaxis: {
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
93
94
        zeroline: false,
        showticklabels: false,
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
      },
      height: 300,
      width: 200,
      sliders: [{
        active: averages.length - 1 - highest,
        pad: {t: 30},
        currentvalue: {
          xanchor: 'right',
          prefix: 'Similarity: ',
          font: {
            color: '#888',
            size: 10
          }
        },
        steps
      }]
111
112
113
114
    };
  }

  async initializeInfo(): Promise<void> {
115
    console.log('Updating progress view');
116
    const allWindows = [];
117
118
119
120
121
122
123
    const keys = Object.keys(this.similarity);
    for (let i = this.cache.nrOfTables; i >= 1; i--) {
      if (keys.indexOf(i.toString()) === -1) {
        allWindows.push([]);
      } else {
        allWindows.push(this.similarity[i.toString()]);
      }
124
    }
125
    const averages = await this.cache.getAverageProgressWindows(allWindows);
126
    this.plot = this.averagePlot(averages);
127
128
129
130
131
  }

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

  public setSliderValue(v) {
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
134
135
136
137
138
139
140
141
    this._sliderValue = v.slider.active;
  }

  public showCandidates() {
    this.cache.sliderValue = this._sliderValue;
  }

  public get amountOfCandidates() {
142
    return this.similarity[this._sliderValue.toString()].length;
143
  }
144
}