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

@Injectable({
  providedIn: 'root'
})
export class CacheService {
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
8
9
  public rawValues: number[];
  public rawIndices: string[];
10
  public loadingProgress: number = 0;
11

12
  private _currentTab: number;
13
  private _query = undefined;
14
15
16
  private _labels = {};
  private _tables;
  private _windowSimilarity;
17
  private _sliderValue;
18
  private _queryWindow;
19

20
21
22
  public windowSize = 120;
  public nrOfTables = 50;
  public hashSize = 4;
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
23
  public stepSize = 200;
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
24
  public querySelectionMode = true;
25

26
  public onNewData: EventEmitter<void> = new EventEmitter<void>();
27
28
29
  public onNewSimilarity: EventEmitter<void> = new EventEmitter<void>();
  public onNewLabels: EventEmitter<void> = new EventEmitter<void>();
  public onNewQuery: EventEmitter<void> = new EventEmitter<void>();
30
31
  public onNewTables: EventEmitter<void> = new EventEmitter<void>();
  public onNewWindows: EventEmitter<void> = new EventEmitter<void>();
32
  public onNewTab: EventEmitter<void> = new EventEmitter<void>();
33
  public onNewSlider: EventEmitter<void> = new EventEmitter<void>();
34
35

  constructor(private api: ApiService) {
36
     this.initialize();
37
38
39
  }

  async initialize(): Promise<void> {
40
    this.loadingProgress = 0;
41
    await this.getRawData();
42
    this.loadingProgress = 30;
43
    await this.createWindows();
44
    this.loadingProgress = 60;
45
    await this.createTables();
46
    this.loadingProgress = 100;
47
48
49
50
  }

  async reset(): Promise<void> {
    this.windowSimilarity = undefined;
51
    this.loadingProgress = 30;
52
    await this.createWindows();
53
    this.loadingProgress = 60;
54
    await this.createTables();
55
    this.loadingProgress = 100;
56
57
58
  }

  async getRawData(): Promise<void> {
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
59
60
61
    const rawData: RawData = await this.api.readFile();
    this.rawIndices = rawData.index;
    this.rawValues = rawData.values;
62
    this.onNewData.emit();
63
64
  }

65
  async createWindows(): Promise<void> {
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
66
    await this.api.createWindows(this.parameters);
67
    this.onNewWindows.emit();
68
69
70
  }

  async createTables(): Promise<void> {
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
71
    this.tables = await this.api.createTables(this.parameters);
72
73
  }

74
75
  async getSimilarWindows(): Promise<any> {
    this.windowSimilarity = await this.api.getSimilarWindows(this._queryWindow, this.tables);
76
77
78
    return this.windowSimilarity;
  }

79
80
81
82
83
84
85
86
  async getAverageProgressWindows(windows): Promise<number[][]> {
    return await this.api.getAverageProgressWindows(windows);
  }

  async getAverageTableWindows(windows): Promise<number[][]> {
    return await this.api.getAverageTableWindows(windows);
  }

87
88
  async getQueryWindow(window): Promise<number[]> {
    this.queryWindow = await this.api.getQueryWindow(window);
89
    return this._queryWindow;
90
91
  }

Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
92
93
94
95
  async getWindow(indices: number[]): Promise<number[][]> {
    return await this.api.getWindow(indices);
  }

96
  async updateTables(): Promise<void> {
97
    this.tables = await this.api.updateTables(this.queryWindow, this.labels, this.tables, this.parameters);
98
99
100
101
102
103
104
105
106
107
108
  }

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

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

  public get windows(): number[][] {
109
    return [];
110
111
112
113
  }

  public set tables(v) {
    this._tables = v;
114
115
116
    this.onNewTables.emit();
  }

117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
  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;
    this.onNewSimilarity.emit();
  }

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

139
140
141
142
143
144
145
146
147
  public set currentTab(v) {
    this._currentTab = v;
    this.onNewTab.emit();
  }

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

148
149
150
151
152
153
154
155
156
  public set sliderValue(v) {
    this._sliderValue = v;
    this.onNewSlider.emit(v);
  }

  public get sliderValue() {
    return this._sliderValue;
  }

157
158
159
160
161
  public set queryWindow(v) {
    this._queryWindow = v;
    this.onNewQuery.emit();
  }

162
163
164
165
  public get queryWindow() {
    return this._queryWindow;
  }

166
167
168
169
  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
170
171
      tablesize: this.nrOfTables,
      stepsize: this.stepSize
172
173
174
    };
  }
}