-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
147 lines (120 loc) · 3.98 KB
/
app.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import base64
from io import BytesIO
from flask import Flask, request, jsonify
import path2
import path3
# from path2 import *
# from path3 import set_nodes as set_nodes_5
from whereami import *
# Set G on initial
path3.set_nodes()
path2.set_nodes()
app = Flask(__name__)
predicter = Predicter()
@app.route('/train', methods=['POST'])
def learn_endpoint():
data = request.get_json()
name = data.get('name')
ap_data = data.get('data')
ap_dict = aps_to_dict(ap_data)
learn(name, data=ap_dict)
return jsonify({'message': 'Learning complete'})
@app.route("/predict", methods=["POST"])
def predict():
data = request.json["data"]
aps = []
for item in data:
ssid = item["ssid"]
bssid = item["bssid"]
quality = item["quality"]
aps.append({"ssid": ssid, "bssid": bssid, "quality": quality})
location = predicter.predict(aps)
return jsonify({"location": location})
@app.route('/path', methods=['POST'])
def find_path():
data = request.get_json()
start = data['start']
end = data['end']
if data['start'][0] == '4':
if start == end:
path_image = path2.arrived_image(start)
final_path, initial_pos, astar_path, intial_angle = None
else:
if start == "4층 아르테크네":
start = "7"
if end == "4층 아르테크네":
end = "7"
if start == "418":
start = "5"
if end == "418":
end = "5"
final_path, initial_pos, astar_path, intial_angle = path2.result_backend(
start, end)
path_image = path2.show_on_image(astar_path)
elif data['start'][0] == '5':
if start == end:
path_image = path3.arrived_image(start)
final_path, initial_pos, astar_path, intial_angle = None
else:
if start == "5층 아르테크네 앞 엘베":
start = "8"
if end == "5층 아르테크네 앞 엘베":
end = "8"
if start == "5층 아르테크네":
start = "7"
if end == "5층 아르테크네":
end = "7"
if start == "5층계단1":
start = "8"
if end == "5층계단1":
end = "8"
final_path, initial_pos, astar_path, intial_angle = path3.result_backend(
start, end)
path_image = path3.show_on_image(astar_path)
else:
print("인식 할 수 없음")
result_path = []
temp = final_path[0]['angle']
result_path.append({'distance': 0, 'angle': final_path[0]['angle']})
for i in range(1, len(final_path)):
if 'distance' in final_path[i]:
distance = final_path[i]['distance']
else:
distance = 0
if 'angle' in final_path[i]:
angle = temp - final_path[i]['angle']
angle = angle + 360
angle = angle % 360
temp = angle
else:
angle = 0
item = {'distance': distance, 'angle': angle}
print(item)
result_path.append(item)
if intial_angle < 0:
intial_angle = intial_angle+360
# for (i, item) in enumerate(result_path):
# # 예각은 그냥 90도로 표현, 둔각은 270도로 표현
# if item['angle'] > 180:
# item['angle'] = 270
# else:
# item['angle'] = 90
response = {
"start_direction": intial_angle,
"path": result_path,
"image": path_image,
}
return jsonify(response)
@app.route('/locations', methods=['GET'])
def get_locations():
folder_path = ensure_whereami_path()
location_list = []
for file_name in os.listdir(folder_path):
if file_name.endswith('.txt'):
location_list.append(file_name.replace('.txt', ''))
response = {
'locations': location_list
}
return jsonify(response)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)