-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwebvlm.py
72 lines (64 loc) · 2.12 KB
/
webvlm.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
#!/usr/bin/python3
from flask import Flask
from flask import request
import json
import os
import vlm
DRONES = {
'm2phq': {'fov': 55.0, },
'm2pfov': {'fov': 75.0, },
'm2z': {'fov': 83.0, },
'mp': {'fov': 78.8, },
'ma': {'fov': 85.0, },
'spark': {'fov': 81.9, },
'p4p': {'fov': 84.0, },
'p4a': {'fov': 84.0, },
'p42': {'fov': 84.0, },
}
app = Flask(__name__)
#app.config['PROPAGATE_EXCEPTIONS'] = True
googlekey = os.getenv('GOOGLEKEY', '')
openapiurl = os.getenv('OPENAPIURL', '')
@app.route('/convert', methods=['POST'])
def api():
j = request.get_json()
if not j or not '0' in j.keys() or not '1' in j.keys():
return 'Bad request\n', 400, {'Content-Type': 'text/plain; charset=utf-8'}
try:
defspeed = float(j['horizontalSpeed'])
except (KeyError, ValueError):
try:
defspeed = float(j['defspeed'])
except (KeyError, ValueError):
defspeed = 10.0
try:
infilldist = float(j['maxWPDist'])
except (KeyError, ValueError):
infilldist = 1000.0
try:
if j['droneModel'] == 'custom':
fov = float(j['customFOV'])
else:
fov = DRONES[j['droneModel']]['fov']
except (KeyError, ValueError):
fov = DRONES['m2phq']['fov']
try:
headingmode = int(j['headingMode'])
except (KeyError, ValueError):
headingmode = 3
conv = vlm.Convert(googlekey=googlekey, openapiurl=openapiurl, speed=defspeed, infilldist=infilldist, fov=fov, headingmode=headingmode)
try:
mission = j['1'].rsplit('.', 1)[0]
csv = j['0'].split('\n')
conv.readcsv(csv, mission)
except:
return 'Bad request data\n', 400, {'Content-Type': 'text/plain; charset=utf-8'}
conv.smooth()
kml = conv.getkml()
resp = json.dumps({'kml':kml.decode('utf-8'), 'mission':mission})
return resp, 200, {'Content-Type': 'application/json; charset=utf-8'}
@app.route('/healthz')
def healthz():
return 'HEALTH_OK\nUsing ' + ['Google', 'Open'][int(googlekey=='')] + ' elevation API\n', 200, {'Content-Type': 'application/json; charset=utf-8'}
if __name__ == '__main__':
app.run()