diff options
| author | Stefan Hansson <steha708@edu.liu.se> | 2020-12-16 08:06:10 +0100 |
|---|---|---|
| committer | Newbyte <steha708@liu.se> | 2020-12-16 08:06:10 +0100 |
| commit | a11a7b4cde5834781aa57e7f9c9a8a3a309d6411 (patch) | |
| tree | 3de6e7616a9f2db627ad80870e68c8a77f24709e /server.py | |
| parent | 7d31854216fd893e1805c6dd40517f329ee3e886 (diff) | |
| download | tdde25-a11a7b4cde5834781aa57e7f9c9a8a3a309d6411.tar.gz | |
wip
Diffstat (limited to 'server.py')
| -rw-r--r-- | server.py | 42 |
1 files changed, 17 insertions, 25 deletions
@@ -4,17 +4,17 @@ import algorithms import store from lib import run_server, get, post, read_html -grid = None +grids = None nodes = None unconnected_nodes = None @get('/') def index(): global nodes - global grid + global grids global unconnected_nodes - nodes, grid, unconnected_nodes = store.extract_osm_nodes("university.osm") + nodes, grids, unconnected_nodes = store.extract_osm_nodes("university.osm") return read_html('templates/index.html') @@ -22,9 +22,10 @@ def index(): @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, 58.3984, 58.3990, 15.5733, - 15.576)): + 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) @@ -41,33 +42,24 @@ def favicon(): @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}) + 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) -<<<<<<< HEAD - source_id = algorithms.grid_search(grid, - store.Node(-1, body['lat1'], - body['lng1'])) - target_id = algorithms.grid_search(grid, - store.Node(-1, body['lat2'], - body['lng2'])) -======= transport_mode = body['transport_mode'] - source_id = algorithms.get_closest_node_id(nodes, - store.Node(-1, body['lat1'], - body['lng1']), - transport_mode) - target_id = algorithms.get_closest_node_id(nodes, - store.Node(-1, body['lat2'], - body['lng2']), - transport_mode) ->>>>>>> 532c0cb... wip - - path = algorithms.find_shortest_path(nodes, source_id, target_id, transport_mode) + source_id = algorithms.get_closest_node(grids[transport_mode], + store.Node(-1, body['lat1'], + body['lng1'])) + target_id = algorithms.get_closest_node(grids[transport_mode], + store.Node(-1, body['lat2'], + body['lng2'])) + + path = algorithms.find_shortest_path(nodes[transport_mode], source_id, target_id) response = {"path": [(nodes[node].lat, nodes[node].lng) for node in path]} return json.dumps(response) |
