Skip to content

Commit

Permalink
Map endpoint audit fixes (#177)
Browse files Browse the repository at this point in the history
* Remove abandoned sectors

* Fix: map endpoint is missing entries for NNs when install != NN

* Fix: inactive installs are shown on the map as active
  • Loading branch information
Andrew-Dickinson authored Feb 14, 2024
1 parent a1027a2 commit a85142e
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 20 deletions.
2 changes: 2 additions & 0 deletions src/meshapi/serializers/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ def convert_status_to_spreadsheet_status(self, install):
return "Powered Off"
elif install.install_status == Install.InstallStatus.CLOSED:
return "Abandoned"
elif install.install_status == Install.InstallStatus.NN_REASSIGNED:
return "NN Assigned"

return install.install_status

Expand Down
68 changes: 60 additions & 8 deletions src/meshapi/tests/test_map_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,13 @@ def test_install_data(self):
longitude=-73.987881,
altitude=27,
node_name="Brian",
primary_nn=3,
)
)
installs.append(
Install(
install_number=3,
network_number=3,
install_status=Install.InstallStatus.ACTIVE,
request_date=datetime.date(2015, 3, 15),
install_date=datetime.date(2014, 10, 14),
Expand Down Expand Up @@ -129,6 +131,48 @@ def test_install_data(self):
)
)

buildings.append(
Building(
building_status=Building.BuildingStatus.ACTIVE,
address_truth_sources="",
latitude=40.6962265,
longitude=-73.9917741,
altitude=66,
)
)
installs.append(
Install(
install_number=245,
install_status=Install.InstallStatus.NN_REASSIGNED,
request_date=datetime.date(2024, 1, 27),
roof_access=True,
building=buildings[-1],
member=member,
)
)

buildings.append(
Building(
building_status=Building.BuildingStatus.ACTIVE,
address_truth_sources="",
latitude=40.6962265,
longitude=-73.9917741,
altitude=66,
primary_nn=567,
)
)
installs.append(
Install(
install_number=15657,
network_number=567,
install_status=Install.InstallStatus.ACTIVE,
request_date=datetime.date(2024, 1, 27),
roof_access=True,
building=buildings[-1],
member=member,
)
)

installs.append(
Install(
install_number=2134,
Expand Down Expand Up @@ -180,6 +224,14 @@ def test_install_data(self):
"roofAccess": False,
"panoramas": [],
},
{
"id": 567,
"status": "NN Assigned",
"coordinates": [-73.9917741, 40.6962265, 66.0],
"requestDate": 1706313600000,
"roofAccess": True,
"panoramas": [],
},
{
"id": 14956,
"status": "Interested",
Expand All @@ -188,6 +240,14 @@ def test_install_data(self):
"roofAccess": True,
"panoramas": [],
},
{
"id": 15657,
"status": "Installed",
"coordinates": [-73.9917741, 40.6962265, 66.0],
"requestDate": 1706313600000,
"roofAccess": True,
"panoramas": [],
},
],
)

Expand Down Expand Up @@ -291,14 +351,6 @@ def test_sector_data(self):
"device": "Omni",
"installDate": 1616284800000,
},
{
"nodeId": 227,
"radius": 0.75,
"azimuth": 300,
"width": 90,
"status": "abandoned",
"device": "SN1Sector2",
},
{
"nodeId": 1126,
"radius": 0.3,
Expand Down
43 changes: 31 additions & 12 deletions src/meshapi/views/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,41 @@ class MapDataInstallList(generics.ListAPIView):
def get_queryset(self):
all_installs = []

queryset = Install.objects.filter(~Q(install_status__in=[Install.InstallStatus.CLOSED]))
excluded_statuses = {
Install.InstallStatus.CLOSED,
Install.InstallStatus.NN_REASSIGNED,
}

queryset = Install.objects.filter(~Q(install_status__in=excluded_statuses))

for install in queryset:
all_installs.append(install)

for building in Building.objects.filter(primary_nn__isnull=False):
representative_install = building.installs.all()[0]
all_installs.append(
Install(
install_number=building.primary_nn,
install_status=Install.InstallStatus.NN_REASSIGNED,
building=building,
request_date=representative_install.request_date,
roof_access=representative_install.roof_access,
),
# We need to make sure there is an entry on the map for every NN, and since we excluded the
# NN assigned rows in the query above, we need to go through the building objects and
# include the nns we haven't already covered via install num
covered_nns = {
install.network_number for install in all_installs if install.install_number == install.network_number
}
for building in Building.objects.filter(
Q(
primary_nn__isnull=False,
building_status=Building.BuildingStatus.ACTIVE,
)
& Q(installs__install_status__in=set(Install.InstallStatus.values) - excluded_statuses)
):
if building.primary_nn not in covered_nns:
representative_install = building.installs.all()[0]
all_installs.append(
Install(
install_number=building.primary_nn,
install_status=Install.InstallStatus.NN_REASSIGNED,
building=building,
request_date=representative_install.request_date,
roof_access=representative_install.roof_access,
),
)
covered_nns.add(building.primary_nn)

all_installs.sort(key=lambda i: i.install_number)
return all_installs
Expand All @@ -45,4 +64,4 @@ class MapDataSectorlList(generics.ListAPIView):
permission_classes = [permissions.AllowAny]
serializer_class = MapDataSectorSerializer
pagination_class = None
queryset = Sector.objects.all()
queryset = Sector.objects.filter(~Q(status__in=[Sector.SectorStatus.ABANDONED]))

0 comments on commit a85142e

Please sign in to comment.