-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
49 lines (39 loc) · 1.35 KB
/
app.py
File metadata and controls
49 lines (39 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from flask import Flask, jsonify, request
import algorithm
import numpy as np
app = Flask(__name__)
# ----------------------------------------------------------------------------------------------------------------------
# API - Routing
# ----------------------------------------------------------------------------------------------------------------------
@app.route("/getData", methods=['POST'])
def get_data():
plot_data, centers = algorithm.cluster_results(request.json)
res = {}
res['center_points'] = []
res['data_points'] = []
count = 1
for cluster in plot_data.get_values():
temp = {}
temp['item_no'] = count
temp['cluster'] = np.int32(cluster[0]).item()
temp['x'] = cluster[1]
temp['y'] = cluster[2]
res['data_points'].append(temp)
count = count + 1
for j, center in enumerate(centers):
temp = {}
temp['x'] = center[0]
temp['y'] = center[1]
res['center_points'].append(temp)
return jsonify(res)
@app.route("/getCluster", methods=['POST'])
def get_cluster():
prediction = algorithm.find_cluster(request.json)
temp = {}
temp['cluster'] = np.int32(prediction).item()
return jsonify(temp)
if __name__ == "__main__":
app.run(
host="0.0.0.0",
port=int(7891)
)