diff options
Diffstat (limited to 'server.py')
| -rw-r--r-- | server.py | 32 |
1 files changed, 25 insertions, 7 deletions
@@ -4,15 +4,17 @@ import algorithms import store from lib import run_server, get, post, read_html - +grid = None nodes = None - +unconnected_nodes = None @get('/') def index(): global nodes + global grid global unconnected_nodes - nodes, unconnected_nodes = store.extract_osm_nodes("university.osm") + + nodes, grid, unconnected_nodes = store.extract_osm_nodes("university.osm") return read_html('templates/index.html') @@ -20,11 +22,22 @@ def index(): @get('/show-area') def show_area(): rect = dict() - for (k, node) in enumerate(store.select_nodes_in_rectangle(nodes, 58.3984, 58.3990, 15.5733, 15.576)): + for (k, node) in enumerate( + store.select_nodes_in_rectangle(nodes, 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: + read_image = image.read() + image_bytes = bytearray(read_image) + + return image_bytes + + @get('/show-unconnected-nodes') def show_unconnected_nodes(): print(f"Showing {len(unconnected_nodes)} unconnected nodes") @@ -34,12 +47,17 @@ def show_unconnected_nodes(): @post('/shortest-path') def shortest_path(body): body = json.loads(body) - source_id = algorithms.get_closest_node_id(nodes, store.Node(-1, body['lat1'], body['lng1'])) - target_id = algorithms.get_closest_node_id(nodes, store.Node(-1, body['lat2'], body['lng2'])) + 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'])) path = algorithms.find_shortest_path(nodes, source_id, target_id) print(path) - response = {"path": [(nodes[node].lat, nodes[node].lng) for node in path]} + response = { + "path": [(nodes[node].lat, nodes[node].lng) for node in path]} return json.dumps(response) |
