diff options
| author | Gustav Sörnäs <gusso230@student.liu.se> | 2020-11-20 13:37:01 +0100 |
|---|---|---|
| committer | Gustav Sörnäs <gusso230@student.liu.se> | 2020-11-20 17:36:48 +0100 |
| commit | 86bca81e753786e0b4e9e9d49e88f0f2a579ebba (patch) | |
| tree | 960d72104b1347b5a2133d5483251181b6ed87f2 | |
| parent | 11e50657c900543856f3a1f56a96d6c861f55b6e (diff) | |
| download | tdde25-86bca81e753786e0b4e9e9d49e88f0f2a579ebba.tar.gz | |
initial debug drawdebug-draw
| -rw-r--r-- | algorithms.py | 4 | ||||
| -rw-r--r-- | debug_draw.py | 15 | ||||
| -rw-r--r-- | server.py | 7 | ||||
| -rw-r--r-- | store.py | 4 | ||||
| -rw-r--r-- | util.py | 9 |
5 files changed, 36 insertions, 3 deletions
diff --git a/algorithms.py b/algorithms.py index 6e01287..7126fb6 100644 --- a/algorithms.py +++ b/algorithms.py @@ -1,5 +1,7 @@ import heapq import math +import util +from debug_draw import DebugDraw def length_haversine(p1, p2): @@ -28,6 +30,8 @@ def get_closest_node_id(nodes, source_node): min_node = node_id min_value = length + grid_p = nodes[min_node].coord_tuple() + DebugDraw.add_square(util.to_grid(grid_p), util.to_grid(grid_p, +1)) return min_node diff --git a/debug_draw.py b/debug_draw.py new file mode 100644 index 0000000..a47e921 --- /dev/null +++ b/debug_draw.py @@ -0,0 +1,15 @@ +class DebugDraw(): + squares = dict() + + @classmethod + def clear(cls): + cls.squares.clear() + + @classmethod + def add_square(cls, p1, p2, color="#000000"): + cls.squares[(p1, p2)] = color + + @classmethod + def get_squares(cls): + return [{"bounds": corners, "color": color} + for corners, color in cls.squares.items()] @@ -2,6 +2,7 @@ import json import algorithms import store +from debug_draw import DebugDraw from lib import run_server, get, post, read_html @@ -31,8 +32,10 @@ def shortest_path(body): 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], + "squares": DebugDraw.get_squares()} + print(DebugDraw.get_squares()) + DebugDraw.clear() return json.dumps(response) @@ -8,10 +8,12 @@ class Node: self.lng = float(lng) self.neighbours = [] - def coord_tuple(self): return self.lat, self.lng + def __repr__(self): + return f"({self.lat}, {self.lng})" + parser = None # Have a global reusable parser object @@ -0,0 +1,9 @@ +import math + + +def floor_f(f, decimals): + return math.floor(f * 10**decimals) / 10**decimals + + +def to_grid(point, delta=0): + return tuple((floor_f(val, 3) + delta/1000 for val in point)) |
