api.service.ts 2.12 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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<RawData> {
    const response = await fetch('http://127.0.0.1:5000/read-data');
18
19
20
21
    const temp = await response.json();
    const index = JSON.parse(temp.index);
    const values = JSON.parse(temp.values).map(Number);
    return {index, values};
22
23
24
  }

// Split data into windows and normalize
25
  async createWindows(values, parameters): Promise<any> {
26
27
28
29
30
31
32
33
34
    const postData = {values, 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)
    });
35
    return (await response.json()).data;
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
  }

// Generate LSH-tables by hashing each window
  async createTables(windows, parameters): Promise<any> {
    const postData = {windows, parameters};
    const response = await fetch('http://127.0.0.1:5000/create-tables', {
      method: 'POST',
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
      },
      body: JSON.stringify(postData)
    });
    return await response.json();
  }

// Return similar windows based on an input query
  async getSimilarWindows(window, tables) {
    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, tables})
    });
    return await response.json();
  }

  async updateTables(windows, labelData, tables, parameters): Promise<any> {
    const postData = {windows, 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: JSON.stringify(postData)
    });
    return await response.json();
  }
}