diff options
| author | Max Bringemo <maxbr167@student.liu.se> | 2020-11-12 16:27:59 +0100 |
|---|---|---|
| committer | Max Bringemo <maxbr167@student.liu.se> | 2020-11-12 16:27:59 +0100 |
| commit | 25fbaaef8f7e5bc261039fd9952d072676721f8f (patch) | |
| tree | adea85a0a826a226fbec9bc0d908b56838a8fa16 /server.py | |
| parent | d429f09e7e3bc8173e765aba8a91f2440c99a324 (diff) | |
| parent | 606c3eebe19114bcd2d07546a7c7d800ca84973f (diff) | |
| download | tdde25-25fbaaef8f7e5bc261039fd9952d072676721f8f.tar.gz | |
Merge branch 'dijkstra' into 'master'
Dijkstra
See merge request tdde25-2020/tdde25-2020-projekt-sg3-maps-05!2
Diffstat (limited to 'server.py')
| -rw-r--r-- | server.py | 27 |
1 files changed, 16 insertions, 11 deletions
@@ -5,29 +5,34 @@ import store from lib import run_server, get, post, read_html +nodes = None + + @get('/') def index(): + global nodes + nodes = store.extract_osm_nodes("university.osm") return read_html('templates/index.html') @get('/show-area') def show_area(): - all = dict() - for (k, node) in enumerate(store.select_nodes_in_rectangle(store.extract_osm_nodes("university.osm"), 58.3984, 58.3990, 15.5733, 15.576)): - all[node.id] = node.coord_tuple() - return json.dumps(all) + rect = dict() + 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) @post('/shortest-path') def shortest_path(body): body = json.loads(body) - source_id = algorithms.get_closest_node_id(store.nodes, store.Node(-1, body['lat1'], body['lng1'])) - target_id = algorithms.get_closest_node_id(store.nodes, store.Node(-1, body['lat2'], body['lng2'])) - print(source_id, target_id) - source_node = store.nodes[source_id] - target_node = store.nodes[target_id] - path = [(source_node.lat, source_node.lng), (target_node.lat, target_node.lng)] - response = {'path': path} + 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'])) + + path = algorithms.find_shortest_path(nodes, source_id, target_id) + print(path) + response = {"path": [(nodes[node].lat, nodes[node].lng) for node in path]} + return json.dumps(response) |
