cache.service.ts 3.18 KB
Newer Older
1
2
3
4
5
6
7
8
9
import {EventEmitter, Injectable} from '@angular/core';
import {ApiService, RawData} from './api.service';

@Injectable({
  providedIn: 'root'
})
export class CacheService {
  public rawValues: number[];
  public rawIndices: string[];
10

11
  private _currentTab: number;
12
  private _query = undefined;
13
14
15
  private _labels = {};
  private _tables;
  private _windowSimilarity;
16

17
  public windowSize = 500;
18
  public nrOfTables = 10;
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
19
20
  public hashSize = 5;
  public stepSize = 1;
21

22
  public onNewData: EventEmitter<void> = new EventEmitter<void>();
23
24
25
  public onNewSimilarity: EventEmitter<void> = new EventEmitter<void>();
  public onNewLabels: EventEmitter<void> = new EventEmitter<void>();
  public onNewQuery: EventEmitter<void> = new EventEmitter<void>();
26
27
  public onNewTables: EventEmitter<void> = new EventEmitter<void>();
  public onNewWindows: EventEmitter<void> = new EventEmitter<void>();
28
  public onNewTab: EventEmitter<void> = new EventEmitter<void>();
29
30
31
32
33
34
35
36
37
38


  public initialized: Promise<void>;

  constructor(private api: ApiService) {
     this.initialized = this.initialize();
  }

  async initialize(): Promise<void> {
    await this.getRawData();
39
    await this.createWindows();
40
41
42
43
44
    await this.createTables();
  }

  async reset(): Promise<void> {
    this.windowSimilarity = undefined;
45
    await this.createWindows();
46
47
48
49
50
51
52
    await this.createTables();
  }

  async getRawData(): Promise<void> {
    const rawData: RawData = await this.api.readFile();
    this.rawIndices = rawData.index;
    this.rawValues = rawData.values;
53
    this.onNewData.emit();
54
55
  }

56
57
58
  async createWindows(): Promise<void> {
    await this.api.createWindows(this.parameters);
    this.onNewWindows.emit();
59
60
61
  }

  async createTables(): Promise<void> {
62
    this.tables = await this.api.createTables(this.parameters);
63
64
  }

65
66
  async getSimilarWindows(query): Promise<any> {
    this.windowSimilarity = await this.api.getSimilarWindows(query, this.tables);
67
68
69
    return this.windowSimilarity;
  }

70
71
72
73
  async getAverageWindow(windows): Promise<number[][]> {
    return await this.api.getAverageWindow(windows);
  }

74
  async updateTables(): Promise<void> {
75
    this.tables = await this.api.updateTables(this.labels, this.tables, this.parameters);
76
77
78
79
80
81
82
83
84
85
86
87
  }

  public set query(v) {
    this._query = v;
    this.onNewQuery.emit();
  }

  public get query(): number {
    return this._query;
  }

  public get windows(): number[][] {
88
    return [];
89
90
91
  }

  public set tables(v) {
92
    console.log(v);
93
    this._tables = v;
94
95
96
    this.onNewTables.emit();
  }

97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
  public get tables() {
    return this._tables;
  }

  public set labels(v) {
    this._labels = v;
    this.onNewLabels.emit();
  }

  public get labels() {
    return this._labels;
  }

  public set windowSimilarity(v) {
    this._windowSimilarity = v;
112
    console.log(v);
113
114
115
116
117
118
119
    this.onNewSimilarity.emit();
  }

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

120
121
122
123
124
125
126
127
128
  public set currentTab(v) {
    this._currentTab = v;
    this.onNewTab.emit();
  }

  public get currentTab() {
    return this._currentTab;
  }

129
130
131
132
  public get parameters(): {[parameter: string]: any} {
    return {
      windowsize: this.windowSize,
      hashsize: this.hashSize,
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
133
134
      tablesize: this.nrOfTables,
      stepsize: this.stepSize
135
136
137
    };
  }
}