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 = JSON.parse(temp.index); const values = JSON.parse(temp.values).map(Number); return {index, values}; } // Read input data async readMtsFile(): Promise { const response = await fetch('http://127.0.0.1:5000/read-mts-data'); return await response.json(); } // 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(); } // Split data into windows and normalize async createMtsWindows(parameters): Promise { const postData = {parameters}; const response = await fetch('http://127.0.0.1:5000/create-mts-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 createTables(parameters): Promise { console.log("creating tables"); const postData = {parameters}; const response = await fetch('http://127.0.0.1:5000/create-tables', { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, body: new Blob( [ JSON.stringify(postData) ], { type: 'text/plain' } ) }); return await response.json(); } // Generate LSH-tables by hashing each window async createMtsTables(parameters): Promise { console.log("creating tables"); const postData = {parameters}; const response = await fetch('http://127.0.0.1:5000/create-mts-tables', { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, body: new Blob( [ JSON.stringify(postData) ], { 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(); } // Return similar windows based on an input query async getSimilarWindows(query, tables) { const response = await fetch('http://127.0.0.1:5000/similarity', { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify({query, tables}) }); return await response.json(); } async getAverageProgressWindows(windows): Promise { const response = await fetch('http://127.0.0.1:5000/average-progress', { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify({windows}) }); return await response.json(); } async getAverageTableWindows(windows): Promise { const response = await fetch('http://127.0.0.1:5000/average-table', { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify({windows}) }); return await response.json(); } async updateTables(query, labelData, tables, parameters): Promise { const postData = {query, labelData, tables, parameters}; 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(postData) ], { type: 'text/plain' } ) }); return await response.json(); } }