import { Injectable } from '@angular/core'; export interface RawData { index: string[]; values: number[]; } @Injectable({ providedIn: 'root' }) export class ApiService { constructor() { } // Read input data async readFile(): Promise { const response = await fetch('http://127.0.0.1:5000/read-data'); const temp = await response.json(); const index = temp.index; const values = temp.values; return {index, values}; } // Split data into windows and normalize async createWindows(parameters): Promise { const postData = {parameters}; const response = await fetch('http://127.0.0.1:5000/create-windows', { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify(postData) }); return await response.json(); } // Generate LSH-tables by hashing each window async initialize(query): Promise { const response = await fetch('http://127.0.0.1:5000/initialize', { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, body: new Blob( [ JSON.stringify({query}) ], { type: 'text/plain' } ) }); return await response.json(); } // Update async update(query, hashFunctions, parameters): Promise { const response = await fetch('http://127.0.0.1:5000/update', { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, body: new Blob( [ JSON.stringify({query, hash_functions: hashFunctions, parameters}) ], { type: 'text/plain' } ) }); return await response.json(); } async getQueryWindow(window) { const response = await fetch('http://127.0.0.1:5000/query', { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify({window}) }); return await response.json(); } async getWindow(indices: number[]) { const response = await fetch('http://127.0.0.1:5000/window', { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify({indices}) }); return await response.json(); } async getAverageWindows(windows): Promise { const response = await fetch('http://127.0.0.1:5000/average', { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify({windows}) }); return await response.json(); } }