api.service.ts 3.36 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
25
26
27
28
29
  // Read input data
  async readMtsFile(): Promise<any> {
    const response = await fetch('http://127.0.0.1:5000/read-mts-data');
    return await response.json();
  }

30
// Split data into windows and normalize
31
32
  async createWindows(parameters): Promise<any> {
    const postData = {parameters};
33
34
35
36
37
38
39
40
    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
41
    return await response.json();
42
43
44
  }

// Generate LSH-tables by hashing each window
45
  async createTables(parameters): Promise<any> {
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
46
    console.log("creating tables");
47
    const postData = {parameters};
48
49
50
51
52
53
    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
54
      body: new Blob( [ JSON.stringify(postData) ], { type: 'text/plain' } )
55
56
57
58
    });
    return await response.json();
  }

59
60
61
62
63
64
65
66
67
68
69
70
  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();
  }

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

84
85
86
87
88
89
90
91
92
93
94
95
96
97
  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', {
98
99
100
101
102
103
104
105
106
107
      method: 'POST',
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({windows})
    });
    return await response.json();
  }

108
109
  async updateTables(query, labelData, tables, parameters): Promise<any> {
    const postData = {query, labelData, tables, parameters};
110
111
112
113
114
115
    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
116
      body: new Blob( [ JSON.stringify(postData) ], { type: 'text/plain' } )
117
118
119
120
    });
    return await response.json();
  }
}