labeling-window.component.ts 2.25 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
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[] = [];
13
  private k = 12;
14
15
16
17

  constructor(private service: CacheService) { }

  ngOnInit(): void {
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
18
    this.service.onNewTables.subscribe(() => { this.getTopKSimilar(); });
19
20
  }

Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
21
  public train() {
22
    this.service.labels = Object.assign({}, this.service.labels, this.labels);
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
23
24
25
26
27
28
    this.service.update();
  }

  public updateQuery() {
    this.service.labels = Object.assign({}, this.service.labels, this.labels);
    this.service.getQueryWindow(this.service.labels);
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
  }

  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;
  }

Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
45
  async getTopKSimilar() {
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
46
    this.topk = this.service.candidates.slice(0, 12);
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
47
48
    await this.createPlots();
  }
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
49

Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
50
  async createPlots() {
51
    this.subplots = [];
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
52
53
    const values = await this.service.getWindow(this.topk);
    this.topk.forEach((index, i) => {
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
54
55
      this.subplots.push(
        {
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
56
          index,
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
57
          data: [{
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
58
59
            x: [...Array(values[i].length).keys()],
            y: values[i],
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
60
61
62
            type: 'line'
          }],
          layout: {
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
63
            title: `Index: ${index.toString()}`,
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
64
65
66
67
68
69
70
71
72
73
            hovermode: 'closest',
            autosize: true,
            margin: {
              l: 30,
              r: 30,
              t: 30,
              b: 0,
              pad: 4
            },
            height: 150,
74
            width: 300,
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
75
76
77
78
79
80
81
82
83
84
85
86
            titlefont: {
              size: 9
            },
            xaxis: {
              showgrid: false,
              zeroline: false,
              showticklabels: false,
            },
            yaxis: {
              zeroline: false,
              showticklabels: false,
            }
87
88
          }
        }
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
89
      );
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
90
91
92
    });
  }

Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
93
94
  public get candidates() {
    return this.service.candidates;
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
95
  }
96
}