summaryrefslogtreecommitdiffstats
path: root/server.py
diff options
context:
space:
mode:
authorStefan Hansson <steha708@student.liu.se>2021-01-09 11:27:26 +0100
committerStefan Hansson <steha708@student.liu.se>2021-01-09 11:27:26 +0100
commit978fed58df8322d4195ae112d33a4da193deccc2 (patch)
tree0723e8b92e34371b130b1e1a579a872fad1bad6a /server.py
parentff702dfc656b289223e3700e66872c371e365a25 (diff)
parenta526d6b7ce8c2e506dfc0a6356e9e2ce470bc3e4 (diff)
downloadtdde25-978fed58df8322d4195ae112d33a4da193deccc2.tar.gz
Merge branch 'small-fixes' into 'master'
Small fixes See merge request tdde25-2020/tdde25-2020-projekt-sg3-maps-05!18
Diffstat (limited to 'server.py')
-rw-r--r--server.py46
1 files changed, 14 insertions, 32 deletions
diff --git a/server.py b/server.py
index 8055e63..33372ba 100644
--- a/server.py
+++ b/server.py
@@ -8,28 +8,17 @@ grids = None
nodes = None
unconnected_nodes = None
+
@get('/')
def index():
global nodes
global grids
global unconnected_nodes
-
nodes, grids, unconnected_nodes = store.extract_osm_nodes("linkoping.osm")
return read_html('templates/index.html')
-@get('/show-area')
-def show_area():
- rect = dict()
- # FIXME: Don't hardcode bikes maybe? Maybe just remove this altogether
- for (k, node) in enumerate(
- store.select_nodes_in_rectangle(nodes['bike'], 58.3984, 58.3990,
- 15.5733, 15.576)):
- rect[node.id] = node.coord_tuple()
- return json.dumps(rect)
-
-
@get('/favicon.ico')
def favicon():
with open("data/favicon.ico", "rb") as image:
@@ -39,34 +28,27 @@ def favicon():
return image_bytes
-@get('/show-unconnected-nodes')
-def show_unconnected_nodes():
- print(f"Showing {len(unconnected_nodes)} unconnected nodes")
- return json.dumps({
- node.id: node.coord_tuple() for node in unconnected_nodes['bike']
- })
-
-
@post('/shortest-path')
def shortest_path(body):
body = json.loads(body)
- transport_mode = body['transport_mode']
+ transport_mode = body['transport_mode']
relevant_grid = grids[transport_mode]
+ relevant_nodes = nodes[transport_mode]
source_id = algorithms.grid_search(relevant_grid,
- store.Node(-1, body['lat1'],
- body['lng1']))
+ body['lat1'],
+ body['lng1'])
target_id = algorithms.grid_search(relevant_grid,
- store.Node(-1, body['lat2'],
- body['lng2']))
-
- relevant_nodes = nodes[transport_mode]
-
- path = algorithms.find_shortest_path(nodes[transport_mode], source_id, target_id)
- response = {"path": [(relevant_nodes[node].lat, relevant_nodes[node].lng) for node in path]}
-
- return json.dumps(response)
+ body['lat2'],
+ body['lng2'])
+
+ path = algorithms.find_shortest_path(nodes[transport_mode],
+ source_id,
+ target_id)
+ return json.dumps({"path": [(relevant_nodes[node].lat,
+ relevant_nodes[node].lng)
+ for node in path]})
run_server()