progress-view.component.ts 2.58 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
14
15
16

  constructor(private cache: CacheService) { }

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

Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
20
  averagePlot(averages) {
21
    let highest = 100;
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
22
    const data = averages.map((average, i) => {
23
24
25
      if (average.length !== 0 && i < highest) {
        highest = i;
      }
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
26
      return {
27
28
29
        x: [...Array(average.length).keys()],
        y: average,
        type: 'line',
30
        visible: i === highest
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
31
32
33
34
35
36
37
38
39
40
41
42
43
      };
    });
    const visibility = Array(averages.length).fill(false);
    const steps = [];
    for (let i = averages.length - 1; i >= 0; i--) {
      const v = visibility.slice();
      v[i] = true;
      steps.push({
        label: (100 * (averages.length - i) / averages.length).toString() + '%',
        method: 'restyle',
        args: ['visible', v]
      });
    }
44
45
46
47
48
49
50
51
52
53
54
55
    console.log(averages.length - 1 - highest);
    visibility[averages.length - 1 - highest] = true;
    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
56
      },
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
      xaxis: {
        showticklabels: false
      },
      yaxis: {
        showticklabels: false
      },
      height: 300,
      width: 200,
      sliders: [{
        active: averages.length - 1 - highest,
        pad: {t: 30},
        currentvalue: {
          xanchor: 'right',
          prefix: 'Similarity: ',
          font: {
            color: '#888',
            size: 10
          }
        },
        steps
      }]
78
79
80
81
    };
  }

  async initializeInfo(): Promise<void> {
82
    console.log('Updating progress view');
83
    const allWindows = [];
84
85
86
87
88
89
90
    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()]);
      }
91
    }
92
    console.log(allWindows);
93
    const averages = await this.cache.getAverageProgressWindows(allWindows);
94
    console.log(averages);
95
    this.plot = this.averagePlot(averages);
96
97
98
99
100
  }

  public get similarity() {
    return this.cache.windowSimilarity;
  }
101
102
103
104

  public setSliderValue(v) {
    this.cache.sliderValue = v.slider.active;
  }
105
}