api.service.ts 3.47 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
    const temp = await response.json();
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
19 20
    const index = temp.index;
    const values = temp.values;
21
    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();
  }

Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
65 66 67 68 69 70 71 72 73 74 75 76
  async getWindow(indices: number[]) {
    const response = await fetch('http://127.0.0.1:5000/window', {
      method: 'POST',
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({indices})
    });
    return await response.json();
  }

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

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

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