import {EventEmitter, Injectable} from '@angular/core'; import {ApiService, RawData} from './api.service'; @Injectable({ providedIn: 'root' }) export class CacheService { public rawValues: number[][]; public rawIndices: string[][]; public loadingProgress: number = 0; private _currentTab: number; private _query = undefined; private _labels = {}; private _tables; private _windowSimilarity; private _sliderValue; private _queryWindow; public windowSize = 500; public nrOfTables = 10; public hashSize = 5; public stepSize = 1; public querySelectionMode = true; public onNewData: EventEmitter = new EventEmitter(); public onNewSimilarity: EventEmitter = new EventEmitter(); public onNewLabels: EventEmitter = new EventEmitter(); public onNewQuery: EventEmitter = new EventEmitter(); public onNewTables: EventEmitter = new EventEmitter(); public onNewWindows: EventEmitter = new EventEmitter(); public onNewTab: EventEmitter = new EventEmitter(); public onNewSlider: EventEmitter = new EventEmitter(); constructor(private api: ApiService) { this.initialize(); } async initialize(): Promise { this.loadingProgress = 0; await this.getRawData(); this.loadingProgress = 30; await this.createWindows(); this.loadingProgress = 60; await this.createTables(); this.loadingProgress = 100; } async reset(): Promise { this.windowSimilarity = undefined; this.loadingProgress = 30; await this.createWindows(); this.loadingProgress = 60; await this.createTables(); this.loadingProgress = 100; } async getRawData(): Promise { const channels = await this.api.readMtsFile(); console.log(channels); this.rawIndices = channels.map((channel) => channel.index); this.rawValues = channels.map((channel) => channel.values); this.onNewData.emit(); } async createWindows(): Promise { await this.api.createWindows(this.parameters); this.onNewWindows.emit(); } async createTables(): Promise { this.tables = await this.api.createTables(this.parameters); } async getSimilarWindows(): Promise { this.windowSimilarity = await this.api.getSimilarWindows(this._queryWindow, this.tables); return this.windowSimilarity; } async getAverageProgressWindows(windows): Promise { return await this.api.getAverageProgressWindows(windows); } async getAverageTableWindows(windows): Promise { return await this.api.getAverageTableWindows(windows); } async getQueryWindow(window): Promise { this.queryWindow = await this.api.getQueryWindow(window); return this._queryWindow; } async updateTables(): Promise { this.tables = await this.api.updateTables(this.queryWindow, this.labels, this.tables, this.parameters); } public set query(v) { this._query = v; } public get query(): number { return this._query; } public get windows(): number[][] { return []; } public set tables(v) { this._tables = v; this.onNewTables.emit(); } 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; } public set currentTab(v) { this._currentTab = v; this.onNewTab.emit(); } public get currentTab() { return this._currentTab; } public set sliderValue(v) { this._sliderValue = v; this.onNewSlider.emit(v); } public get sliderValue() { return this._sliderValue; } public set queryWindow(v) { this._queryWindow = v; this.onNewQuery.emit(); } public get queryWindow() { return this._queryWindow; } public get parameters(): {[parameter: string]: any} { return { windowsize: this.windowSize, hashsize: this.hashSize, tablesize: this.nrOfTables, stepsize: this.stepSize }; } }