This repository has been archived by the owner on Apr 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
93 lines (67 loc) · 2.16 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
from flask import Flask, request, jsonify, render_template
#from flask_sqlalchemy import SQLAlchemy
from flask_marshmallow import Marshmallow
from helper import gettrafficFlow, overwrite_JSONvalues, azureJSONmaparser, tileToCoordJSON
from flask import make_response
from temp_helper import main
import os
#init app
app = Flask(__name__)
basedir = os.path.abspath(os.path.dirname(__file__))
#init ma
ma = Marshmallow(app)
class CoordinateJSONSchema(ma.Schema):
class Meta:
fields = ('long', 'lat')
#submit JSON request
@app.route('/Coordinate', methods=['GET','POST'])
def pull():
long = request.args.get('long')
lat = request.args.get('lat')
type(long)
return '''long is: {} and lat is: {}'''.format(long,lat)
@app.route('/CoordinateJSON', methods=['GET','POST'])
def add_CoordinateJSON():
long = float(request.args.get('long'))
lat = float(request.args.get('lat'))
tileSize = 256
zoom = 15
tileX, tileY = gettrafficFlow(lat, long, tileSize, zoom)
#print('Tile X Calculated: ' + str(tileX))
#print('Tile Y calculated: ' + str(tileY))
##return JSON file as obj
obj = azureJSONmaparser(tileX, tileY, tileSize, zoom)
##calculate pollution levels
key = 'traffic_level'
overwrite_JSONvalues(obj, key)
##change tile vector coordinates to lat and long
##this section of code is buggy. but this is an alpha
key = 'coordinates'
print('IMPORTANT')
tileToCoordJSON(obj, key, zoom)
#print(obj)
return '''{}'''.format(obj)
@app.route('/GetRoute', methods=['GET','POST'])
def get_Route():
lonA = float(request.args.get('lonA'))
latA = float(request.args.get('latA'))
lonB = float(request.args.get('lonB'))
latB = float(request.args.get('latB'))
A = (lonA,latA)
print('TEST: '+ str(A))
B = (lonB,latB)
obj = main(A,B)
print(str(obj))
return '''{}'''.format(obj)
@app.errorhandler(404)
def not_found(error):
return make_response(jsonify({'error': 'Not found'}), 404)
# CoordinateJSON = CoordinateJSON.query.get(id)
# db.session.delete(CoordinateJSON)
# db.session.commit()
# return jsonify(CoordinateJSON)
@app.route("/")
def index():
return render_template('index.html')
if __name__ == '__main__':
app.run(debug=True)