diff options
| author | Stefan Hansson <steha708@edu.liu.se> | 2020-11-05 15:10:55 +0100 |
|---|---|---|
| committer | Newbyte <steha708@liu.se> | 2020-11-05 15:10:55 +0100 |
| commit | d429f09e7e3bc8173e765aba8a91f2440c99a324 (patch) | |
| tree | df0d6466bad2fabc4412b0e352fc197f97a343fa /server.py | |
| parent | 6054b37c778ba6ea9d816bb9885513c19917a372 (diff) | |
| download | tdde25-d429f09e7e3bc8173e765aba8a91f2440c99a324.tar.gz | |
Implement finding nearest nodes to start and end positions
Diffstat (limited to 'server.py')
| -rw-r--r-- | server.py | 16 |
1 files changed, 15 insertions, 1 deletions
@@ -1,7 +1,8 @@ import json +import algorithms import store -from lib import run_server, get, read_html +from lib import run_server, get, post, read_html @get('/') @@ -17,4 +18,17 @@ def show_area(): return json.dumps(all) +@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} + return json.dumps(response) + + run_server() |
