diff --git a/src/meshapi/tests/test_kml_endpoint.py b/src/meshapi/tests/test_kml_endpoint.py index 022dac18..bedb5a12 100644 --- a/src/meshapi/tests/test_kml_endpoint.py +++ b/src/meshapi/tests/test_kml_endpoint.py @@ -81,6 +81,9 @@ def test_kml_data(self): s3_building, sn3_install, sn3, sn3_omni = create_building_install_node_and_device(fake_member, 713) brian_building, brian_install, brian, brian_omni = create_building_install_node_and_device(fake_member, 3) random_building, random_install, random, random_omni = create_building_install_node_and_device(fake_member, 123) + dead_building, dead_install, dead, dead_omni = create_building_install_node_and_device(fake_member, 888) + dead_omni.status = Device.DeviceStatus.INACTIVE + dead_omni.save() links.append( Link( @@ -128,6 +131,16 @@ def test_kml_data(self): ) ) + # Should show up as inactive because dead_omni is inactive + links.append( + Link( + from_device=dead_omni, + to_device=random_omni, + status=Link.LinkStatus.ACTIVE, + type=Link.LinkType.STANDARD, + ) + ) + for link in links: link.save() @@ -141,7 +154,7 @@ def test_kml_data(self): assert len(kml_tree[0]) == 6 # 4 styles and 2 folders assert len(kml_tree[0][4]) == 3 # "Active" and "Inactive" node folders + 1 for "name" tag assert len(kml_tree[0][4][1]) == 7 # 5 borough folders and "Other" + 1 for "name" tag - assert len(kml_tree[0][4][1][6]) == 13 # 6 installs and 6 NNs, all in the "Other" folder + 1 for "name" tag + assert len(kml_tree[0][4][1][6]) == 15 # 7 installs and 7 NNs, all in the "Other" folder + 1 for "name" tag assert len(kml_tree[0][5]) == 3 # "Active" and "Inactive" link folders + 1 for "name" tag assert len(kml_tree[0][5][1]) == 5 # 4 active links + 1 for "name" tag - assert len(kml_tree[0][5][2]) == 2 # 1 inactive links + 1 for "name" tag + assert len(kml_tree[0][5][2]) == 3 # 1 inactive links + 1 for "name" tag diff --git a/src/meshapi/views/geography.py b/src/meshapi/views/geography.py index 95c659b3..91804fee 100644 --- a/src/meshapi/views/geography.py +++ b/src/meshapi/views/geography.py @@ -13,6 +13,8 @@ from rest_framework.views import APIView from meshapi.models import Install, Link +from meshapi.models.devices.device import Device +from meshapi.models.node import Node KML_CONTENT_TYPE = "application/vnd.google-earth.kml+xml" KML_CONTENT_TYPE_WITH_CHARSET = f"{KML_CONTENT_TYPE}; charset=utf-8" @@ -208,9 +210,21 @@ def get(self, request: HttpRequest) -> HttpResponse: .annotate(highest_altitude=Greatest("from_device__altitude", "to_device__altitude")) .order_by(F("highest_altitude").asc(nulls_first=True)) ): + # Logic to decide if this link should show up as active or not + mark_active: bool = ( + # Link must be active + link.status == Link.LinkStatus.ACTIVE + # And the devices + and link.from_device.status == Device.DeviceStatus.ACTIVE + and link.to_device.status == Device.DeviceStatus.ACTIVE + # And the device's nodes + and link.from_device.node.status == Node.NodeStatus.ACTIVE + and link.to_device.node.status == Node.NodeStatus.ACTIVE + ) + node_label: str = f"{str(link.from_device.node)}-{str(link.to_device.node)}" placemark = kml.Placemark( name=f"Links-{link.id}", - style_url=styles.StyleUrl(url="#red_line" if link.status == Link.LinkStatus.ACTIVE else "#grey_line"), + style_url=styles.StyleUrl(url="#red_line" if mark_active else "#grey_line"), kml_geometry=geometry.LineString( geometry=LineString( [ @@ -235,8 +249,8 @@ def get(self, request: HttpRequest) -> HttpResponse: to_identifier = link.to_device.node.network_number extended_data = { - "name": f"Links-{link.id}", - "stroke": ACTIVE_COLOR if link.status == Link.LinkStatus.ACTIVE else INACTIVE_COLOR, + "name": f"Links-{link.id}-{node_label}", + "stroke": ACTIVE_COLOR if mark_active else INACTIVE_COLOR, "fill": "#000000", "fill-opacity": "0", "from": str(from_identifier), @@ -249,7 +263,7 @@ def get(self, request: HttpRequest) -> HttpResponse: elements=[Data(name=key, value=val) for key, val in extended_data.items()] ) - if link.status == Link.LinkStatus.ACTIVE: + if mark_active: active_links_folder.append(placemark) else: inactive_links_folder.append(placemark)