-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
66 lines (43 loc) · 1.49 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
from flask import Flask, render_template, request
from spatial import Spatial
import sqlite3
import time
app = Flask(__name__)
@app.route('/')
def home():
# global conn
is_btree = request.args.get('tree')
if is_btree == None:
is_btree = True
else:
is_btree = False
# conn = sqlite3.connect('location_btree.db', check_same_thread=False)
conn = None
if is_btree:
conn = sqlite3.connect('restaurants.db', check_same_thread=False)
else:
conn = sqlite3.connect('restaurants_rtree.db', check_same_thread=False)
radius = request.args.get('radius')
if radius == None:
radius = 1
else:
radius = int(radius)
lat = request.args.get('lat')
lon = request.args.get('long')
if lat == None or lon == None:
# Use Kennesaw state university latitude and longitude.
lat =33.94188717711815
lon = -84.51962762334004
spatial = Spatial(10, 10, 50, is_btree=is_btree)
center = [float(lat), float(lon)]
# Get the initial time.
initial_time = time.time()
# Get the nearby locations.
nearby_data = spatial.get_nearby_locations(conn, center, radius)
# Calculate the time.
diff = time.time() - initial_time
return render_template('index.html', nearby_data=nearby_data, center=center, radius=radius, spatial=spatial, resp_time=round(diff, 3))
if __name__ == '__main__':
app.jinja_env.auto_reload = True
app.config['TEMPLATES_AUTO_RELOAD'] = True
app.run()