-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
44 lines (35 loc) · 1.19 KB
/
server.py
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
"""
Creating a server for activity recognition
"""
from flask import Flask, jsonify, request
import numpy as np
import pickle
from sklearn.preprocessing import normalize
app = Flask('__name__')
filename = 'D:/Vacation/ML/sangam/main/classifier.sav'
time = [0, 0, 0]
data = {"walking":str(time[0])+",0", "running":str(time[1])+",0", "standing":str(time[2])+",0"}
@app.route('/', methods = ['GET', 'POST'])
def index():
global time
global data
arduino_data = request.get_json()
if request.method=="GET":
return jsonify(data)
else:
sensorValues = arduino_data["values"]
print(sensorValues)
X_test = np.array(sensorValues[0:9])
classifier = pickle.load(open(filename, 'rb'))
n = classifier.predict(normalize(X_test))
matcher = {'1':"walking", '2':"running", '3':"standing"}
print("")
print("")
print("The person appears to be " + matcher[str(int(n))] + ".")
print("")
print("")
time[int(n)-1]+=0.04
data = {"walking":str(time[0])+",0", "running":str(time[1])+",0", "standing":str(time[2])+",0"}
return jsonify(data)
if __name__ == '__main__':
app.run(host='0.0.0.0')