From d84226dc5cb4b7ff21d169f5cc2e29b2742bff32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laura=20Kl=C3=BCnder?= Date: Thu, 23 Nov 2023 15:02:21 +0100 Subject: [PATCH] fix get_locator_beacon --- src/c3nav/mesh/models.py | 4 ++-- src/c3nav/mesh/templates/mesh/node_detail.html | 10 +++++----- src/c3nav/routing/rangelocator.py | 7 +++++++ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/c3nav/mesh/models.py b/src/c3nav/mesh/models.py index 0a501589..e278d45b 100644 --- a/src/c3nav/mesh/models.py +++ b/src/c3nav/mesh/models.py @@ -284,9 +284,9 @@ class MeshNode(models.Model): return False return dst_node.get_uplink() - def get_locator_beacon(self): + def get_locator_xyz(self): locator = RangeLocator.load() - return locator.beacons.get(self.address, None) + return locator.get_xyz(self.address) class MeshUplink(models.Model): diff --git a/src/c3nav/mesh/templates/mesh/node_detail.html b/src/c3nav/mesh/templates/mesh/node_detail.html index 16a7cad5..764440b1 100644 --- a/src/c3nav/mesh/templates/mesh/node_detail.html +++ b/src/c3nav/mesh/templates/mesh/node_detail.html @@ -110,13 +110,13 @@ Y={{ node.last_messages.CONFIG_POSITION.parsed.y_pos | cm_to_m }} Z={{ node.last_messages.CONFIG_POSITION.parsed.z_pos | cm_to_m }}

- {% with locator_beacon=node.get_locator_beacon %} - {% if locator_beacon %} + {% with locator_xyz=node.get_locator_xyz %} + {% if locator_xyz %}

In Map: - X={{ locator_beacon.x | cm_to_m }} - Y={{ locator_beacon.y | cm_to_m }} - Z={{ locator_beacon.z | cm_to_m }} + X={{ locator_xyz.0 | cm_to_m }} + Y={{ locator_xyz.1 | cm_to_m }} + Z={{ locator_xyz.2 | cm_to_m }}

{% else %}

diff --git a/src/c3nav/routing/rangelocator.py b/src/c3nav/routing/rangelocator.py index 6163e0d0..5aeefb8b 100644 --- a/src/c3nav/routing/rangelocator.py +++ b/src/c3nav/routing/rangelocator.py @@ -50,6 +50,13 @@ class RangeLocator: def load_nocache(cls, update): return pickle.load(open(cls.build_filename(update), 'rb')) + def get_xyz(self, address) -> tuple[int, int, int] | None: + try: + i = self.beacon_lookup[address] + except KeyError: + return None + return tuple(self.beacon_positions[i]) + cached = None cache_update = None cache_lock = threading.Lock()