progress-view.component.ts 4 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;
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
13
  public amountOfCandidates;
14

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

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

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

Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
23
  averagePlot(averages) {
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
24
25
26
27
    console.log(averages);
    let highest = 0;
    averages.map((average, i) => {
      if (average.average.length !== 0 && i > highest) {
28
29
        highest = i;
      }
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
30
31
    });
    let data = averages.map((average, i) => {
32
33
34
35
36
37
      return [
        {
          x: [...Array(average.average.length).keys()],
          y: average.average,
          type: 'line',
          visible: i === highest,
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
38
39
40
41
          line: {
            color: 'red',
            width: 3
          }
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
        },
        {
          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
68
    });
69
70
    data = [].concat(...data);
    const visibility = Array(averages.length * 3).fill(false);
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
71
    const steps = [];
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
72
    for (let i = 0; i < this.cache.nrOfTables; i++) {
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
73
      const v = visibility.slice();
74
75
76
      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
77
      steps.push({
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
78
        label: (100 * (i + 1) / this.cache.nrOfTables).toString() + '%',
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
79
80
81
82
        method: 'restyle',
        args: ['visible', v]
      });
    }
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
83
    this._sliderValue = highest;
84
85
86
87
88
89
90
91
92
93
    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
94
      },
95
      xaxis: {
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
96
97
98
        showgrid: false,
        zeroline: false,
        showticklabels: false,
99
100
      },
      yaxis: {
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
101
102
        zeroline: false,
        showticklabels: false,
103
104
      },
      height: 300,
105
      width: 300,
106
      sliders: [{
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
107
        active: highest,
108
109
110
111
112
113
114
115
116
117
118
        pad: {t: 30},
        currentvalue: {
          xanchor: 'right',
          prefix: 'Similarity: ',
          font: {
            color: '#888',
            size: 10
          }
        },
        steps
      }]
119
120
121
122
    };
  }

  async initializeInfo(): Promise<void> {
123
    console.log('Updating progress view');
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
124
    console.log(this.similarity);
125
    const allWindows = [];
126
127
128
129
130
131
132
    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()]);
      }
133
    }
134
    const averages = await this.cache.getAverageProgressWindows(allWindows);
135
    this.plot = this.averagePlot(averages);
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
136
137
138
139
140
    let candidates = [];
    for (let i = this._sliderValue; i < this.cache.nrOfTables; i++) {
      candidates = candidates.concat(this.cache.windowSimilarity[i.toString()]);
    }
    this.amountOfCandidates = candidates.length;
141
142
143
144
145
  }

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

  public setSliderValue(v) {
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
148
    this._sliderValue = v.slider.active;
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
149
150
151
152
153
    let candidates = [];
    for (let i = this._sliderValue; i < this.cache.nrOfTables; i++) {
      candidates = candidates.concat(this.cache.windowSimilarity[i.toString()]);
    }
    this.amountOfCandidates = candidates.length;
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
154
155
156
157
158
  }

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