labeling-window.component.ts 2.62 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import { Component, OnInit } from '@angular/core';
import {CacheService} from '../cache.service';

@Component({
  selector: 'app-labeling-window',
  templateUrl: './labeling-window.component.html',
  styleUrls: ['./labeling-window.component.css']
})
export class LabelingWindowComponent implements OnInit {
  public topk;
  public subplots = [];
  public labels: boolean[] = [];
  private k = 5;

  constructor(private service: CacheService) { }

  ngOnInit(): void {
18
    this.service.onNewSimilarity.subscribe(() => { this.getTopKSimilar(); });
19
20
21
  }

  public changeTables() {
22
23
    this.service.labels = Object.assign({}, this.service.labels, this.labels);
    this.service.updateTables();
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
  }

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

  public labelCorrect(index: number) {
    this.labels[index] = true;
  }

  public labelUndefined(index: number) {
    if (this.labels[index] !== undefined) {
      delete this.labels[index];
    }
  }

  public labelIncorrect(index: number) {
    this.labels[index] = false;
  }

  public getTopKSimilar() {
    this.labels = [];
46
    let abort = false;
47
48
49
    if (!this.windowSimilarity) {
      return;
    }
50
51
52
53
54
    let topk = [];
    let k = this.k;
    const keys = Object.keys(this.windowSimilarity).map(a => Number(a)).sort((a, b) => b - a);
    for (const key of keys) {
      const windows = this.windowSimilarity[key];
55
56
57
58
59
60
61
62
63
64
65
66
      for (const index of windows) {
        if (this.service.labels[index] !== undefined) {
          continue;
        }
        topk.push({index, frequency: 100 * key / this.service.nrOfTables});
        k -= 1;
        if (k < 1) {
          abort = true;
          break;
        }
      }
      if (abort) {
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
        break;
      }
    }
    this.topk = topk;

    this.subplots = [];
    for (const window of this.topk) {
      this.subplots.push(
        {
          index: window.index,
          data: [{
            x: this.service.rawIndices.slice(window.index, window.index + this.service.windowSize),
            y: this.service.rawValues.slice(window.index, window.index + this.service.windowSize),
            type: 'line'
          }],
          layout: {
            title: `Index: ${window.index.toString()}      Similarity: ${window.frequency.toString()}%`,
            hovermode: 'closest',
            autosize: true,
            margin: {
              l: 30,
              r: 30,
              t: 30,
              pad: 4
            },
            height: 200,
93
            width: 150,
94
95
96
            titlefont: {
              size: 9
            },
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
97
98
99
            xaxis: {
              showticklabels: false,
            }
100
101
102
103
104
105
          }
        }
      );
    }
  }
}