api.service.ts 3.18 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
26
  async createWindows(parameters): Promise<any> {
    const postData = {parameters};
27
28
29
30
31
32
33
34
    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)
    });
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
35
    return await response.json();
36
37
38
  }

// Generate LSH-tables by hashing each window
39
  async createTables(parameters): Promise<any> {
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
40
    console.log("creating tables");
41
    const postData = {parameters};
42
43
44
45
46
47
    const response = await fetch('http://127.0.0.1:5000/create-tables', {
      method: 'POST',
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
      },
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
48
      body: new Blob( [ JSON.stringify(postData) ], { type: 'text/plain' } )
49
50
51
52
    });
    return await response.json();
  }

53
54
55
56
57
58
59
60
61
62
63
64
  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();
  }

65
// Return similar windows based on an input query
66
  async getSimilarWindows(query, tables) {
67
    const response = await fetch('http://127.0.0.1:5000/similarity', {
68
69
70
71
72
      method: 'POST',
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
      },
73
      body: JSON.stringify({query, tables})
74
75
76
77
    });
    return await response.json();
  }

78
79
80
81
82
83
84
85
86
87
88
89
90
91
  async getAverageProgressWindows(windows): Promise<number[][]> {
    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<number[][]> {
    const response = await fetch('http://127.0.0.1:5000/average-table', {
92
93
94
95
96
97
98
99
100
101
102
103
      method: 'POST',
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({windows})
    });
    return await response.json();
  }

  async updateTables(labelData, tables, parameters): Promise<any> {
    const postData = {labelData, tables, parameters};
104
105
106
107
108
109
    const response = await fetch('http://127.0.0.1:5000/update', {
      method: 'POST',
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
      },
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
110
      body: new Blob( [ JSON.stringify(postData) ], { type: 'text/plain' } )
111
112
113
114
    });
    return await response.json();
  }
}