cache.service.ts 3.2 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
12
  private _currentTab: number;
  private _windows: number[][];
13
  private _query = undefined;
14
15
16
  private _labels = {};
  private _tables;
  private _windowSimilarity;
17

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

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
39
40
41
42
43
44
45
46
47
48
49
50


  public initialized: Promise<void>;

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

  async initialize(): Promise<void> {
    await this.getRawData();
    await this.getWindows();
    await this.createTables();
  }

  async reset(): Promise<void> {
    this.windowSimilarity = undefined;
    await this.getWindows();
    await this.createTables();
  }

  async getRawData(): Promise<void> {
    const rawData: RawData = await this.api.readFile();
51
    console.log(rawData);
52
53
54
55
56
57
    this.rawIndices = rawData.index;
    this.rawValues = rawData.values;
  }

  async getWindows(): Promise<void> {
    this.windows = await this.api.createWindows(this.rawValues, this.parameters);
58
    console.log(this.windows);
59
60
61
62
  }

  async createTables(): Promise<void> {
    this.tables = await this.api.createTables(this.windows, this.parameters);
63
    console.log(this.tables);
64
65
66
67
68
69
70
  }

  async getSimilarWindows(window): Promise<any> {
    this.windowSimilarity = await this.api.getSimilarWindows(window, this.tables);
    return this.windowSimilarity;
  }

71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
  async updateTables(): Promise<void> {
    this.tables = await this.api.updateTables(this.windows, this.labels, this.tables, this.parameters);
  }

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

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

  public set windows(v) {
    this._windows = v;
    this.onNewWindows.emit();
  }

  public get windows(): number[][] {
    return this._windows;
  }

  public set tables(v) {
    this._tables = v;
95
96
97
    this.onNewTables.emit();
  }

98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
  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;
  }

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

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

130
131
132
133
  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
134
135
      tablesize: this.nrOfTables,
      stepsize: this.stepSize
136
137
138
    };
  }
}