api.service.ts 4.26 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
45
46
47
48
49
50
51
52
53
54
55
56
57
  // Split data into windows and normalize
  async createMtsWindows(parameters): Promise<any> {
    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();
  }

58
// Generate LSH-tables by hashing each window
59
  async createTables(parameters): Promise<any> {
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
60
    console.log("creating tables");
61
    const postData = {parameters};
62
63
64
65
    const response = await fetch('http://127.0.0.1:5000/create-tables', {
      method: 'POST',
      headers: {
        'Accept': 'application/json',
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
        '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<any> {
    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',
81
82
        'Content-Type': 'application/json'
      },
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
83
      body: new Blob( [ JSON.stringify(postData) ], { type: 'text/plain' } )
84
85
86
87
    });
    return await response.json();
  }

88
89
90
91
92
93
94
95
96
97
98
99
  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();
  }

100
// Return similar windows based on an input query
101
  async getSimilarWindows(query, tables) {
102
    const response = await fetch('http://127.0.0.1:5000/similarity', {
103
104
105
106
107
      method: 'POST',
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
      },
108
      body: JSON.stringify({query, tables})
109
110
111
112
    });
    return await response.json();
  }

113
114
115
116
117
118
119
120
121
122
123
124
125
126
  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', {
127
128
129
130
131
132
133
134
135
136
      method: 'POST',
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({windows})
    });
    return await response.json();
  }

137
138
  async updateTables(query, labelData, tables, parameters): Promise<any> {
    const postData = {query, labelData, tables, parameters};
139
140
141
142
143
144
    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
145
      body: new Blob( [ JSON.stringify(postData) ], { type: 'text/plain' } )
146
147
148
149
    });
    return await response.json();
  }
}