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 windows: number[][]; public hashFunctions; public tables; public windowSimilarity; public windowSize = 20; public nrOfTables = 10; public hashSize = 10; public onQuery: EventEmitter = new EventEmitter(); public onNewTables: EventEmitter = new EventEmitter(); public onNewWindows: EventEmitter = new EventEmitter(); public initialized: Promise; constructor(private api: ApiService) { this.initialized = this.initialize(); } async initialize(): Promise { await this.getRawData(); await this.getWindows(); await this.createTables(); } async reset(): Promise { this.windowSimilarity = undefined; await this.getWindows(); await this.createTables(); } async getRawData(): Promise { const rawData: RawData = await this.api.readFile(); this.rawIndices = rawData.index; this.rawValues = rawData.values; } async getWindows(): Promise { this.windows = await this.api.createWindows(this.rawValues, this.parameters); this.onNewWindows.emit(); } async createTables(): Promise { this.tables = await this.api.createTables(this.windows, this.parameters); this.onNewTables.emit(); } async getSimilarWindows(window): Promise { this.windowSimilarity = await this.api.getSimilarWindows(window, this.tables); this.onQuery.emit(); return this.windowSimilarity; } async updateTables(labeldata): Promise { this.tables = await this.api.updateTables(this.windows, labeldata, this.tables, this.parameters); this.onNewTables.emit(); } public get parameters(): {[parameter: string]: any} { return { windowsize: this.windowSize, hashsize: this.hashSize, tablesize: this.nrOfTables }; } }