-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplication.py
40 lines (34 loc) · 1.19 KB
/
application.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
from flask import Flask, jsonify, request
from flask_expects_json import expects_json
from tracks import TracksDetector
app = Flask(__name__)
schema = {
'type': 'object',
'properties': {
'track_length': {
"title": "Track length in kilometers",
'type': 'number'},
'geozone1': {
"title": "The source geozone polygon",
"$ref": "http://geojson.org/schema/Polygon.json",
},
'geozone2': {
"title": "The destination geozone polygon",
"$ref": "http://geojson.org/schema/Polygon.json",
}
},
'required': ['track_length', 'geozone1', 'geozone2']
}
@app.route('/tracks', methods=['POST'])
@expects_json(schema)
def register():
try:
geo_request = request.get_json()
track_length = geo_request['track_length']
source_geo_zone = geo_request['geozone1']
destination_geo_zone = geo_request['geozone2']
tracks_detector = TracksDetector(source_geo_zone, destination_geo_zone, track_length)
detection_id = tracks_detector.detect()
except Exception as e:
return jsonify(dict(message=e)), 409
return jsonify(dict(message=detection_id)), 200