labeling-window.component.ts 2.72 KB
Newer Older
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
1
import {Component, EventEmitter, OnInit, Output} from '@angular/core';
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
2
import {StateService} from '../state.service';
3
4
5
6
7
8
9

@Component({
  selector: 'app-labeling-window',
  templateUrl: './labeling-window.component.html',
  styleUrls: ['./labeling-window.component.css']
})
export class LabelingWindowComponent implements OnInit {
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
10
  public topk: number[];
11
12
  public subplots = [];
  public labels: boolean[] = [];
13
  private k = 5;
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
14
  @Output() labelsOutput = new EventEmitter<boolean[]>();
15

Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
16
  constructor(private state: StateService) { }
17
18

  ngOnInit(): void {
19
    this.state.onNewLshData.subscribe(() => this.showSamples());
20
21
22
23
  }

  public labelCorrect(index: number) {
    this.labels[index] = true;
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
24
    this.labelsOutput.emit(this.labels);
25
26
27
28
29
  }

  public labelUndefined(index: number) {
    if (this.labels[index] !== undefined) {
      delete this.labels[index];
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
30
      this.labelsOutput.emit(this.labels);
31
32
33
34
35
    }
  }

  public labelIncorrect(index: number) {
    this.labels[index] = false;
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
36
    this.labelsOutput.emit(this.labels);
37
38
  }

Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
39
  async showSamples() {
40
41
42
    this.labels = [];
    this.topk = this.state.lshData.samples;

43
    this.subplots = [];
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
44
45
    const values: number[][][] = await this.state.getWindow(this.topk);
    for (const idx in this.topk) {
46
      const window = values[idx];
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
      const data = [];
      window.forEach((channel: number[], index: number) => {
        data.push({
          x: [...Array(channel.length).keys()],
          y: channel,
          type: 'line',
          xaxis: 'x',
          yaxis: `y${index + 2}`,
        });
      });
      const subplots = [];
      window.forEach((channel: number[], index: number) => {
        subplots.push([`xy${index + 2}`]);
      });
      const plot = {
        index: this.topk[idx],
        data: data,
        layout: {
          grid: {
66
            rows: this.state.queryWindow.length,
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
67
68
69
70
71
72
73
74
75
76
77
78
79
80
            columns: 1,
            subplots: subplots,
          },
          showlegend: false,
          title: `Index: ${this.topk[idx].toString()}`,
          hovermode: 'closest',
          autosize: true,
          margin: {
            l: 30,
            r: 30,
            t: 30,
            b: 0,
            pad: 4
          },
81
          height: 100 * values[0].length,
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
82
83
84
85
86
87
88
89
90
91
92
93
          width: 300,
          titlefont: {
            size: 9
          },
          xaxis: {
            showgrid: false,
            zeroline: false,
            showticklabels: false,
          },
          yaxis: {
            zeroline: false,
            showticklabels: false,
94
95
          }
        }
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
96
97
98
99
100
101
102
103
104
      };
      window.forEach((channel: number[], index: number) => {
        plot.layout[`yaxis${index + 2}`] = {
          zeroline: false,
          showticklabels: false,
        };
      });
      this.subplots.push(plot);
    }
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
105
  }
106
}