Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more link types and make them more descriptive #399

Merged
merged 3 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/meshapi/migrations/0010_alter_link_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Generated by Django 4.2.13 on 2024-07-07 01:40

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("meshapi", "0009_member_additional_phone_numbers_and_more"),
]

operations = [
migrations.AlterField(
model_name="link",
name="type",
field=models.CharField(
blank=True,
choices=[
("5 GHz", "Five Ghz"),
("24 GHz", "Twentyfour Ghz"),
("60 GHz", "Sixty Ghz"),
("70-80 GHz", "Seventy Eighty Ghz"),
("VPN", "Vpn"),
("Fiber", "Fiber"),
("Ethernet", "Ethernet"),
],
default=None,
help_text="The technology used for this link 5Ghz, 60Ghz, fiber, etc.",
null=True,
),
),
]
7 changes: 5 additions & 2 deletions src/meshapi/models/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ class LinkStatus(models.TextChoices):
ACTIVE = "Active"

class LinkType(models.TextChoices):
STANDARD = "Standard"
FIVE_GHZ = "5 GHz"
TWENTYFOUR_GHZ = "24 GHz"
SIXTY_GHZ = "60 GHz"
SEVENTY_EIGHTY_GHZ = "70-80 GHz"
VPN = "VPN"
MMWAVE = "MMWave"
FIBER = "Fiber"
ETHERNET = "Ethernet"

from_device = models.ForeignKey(
Device,
Expand Down
6 changes: 5 additions & 1 deletion src/meshapi/serializers/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,11 @@ def convert_status_to_spreadsheet_status(self, link: Link) -> str:
return "fiber"
elif link.type == Link.LinkType.VPN:
return "vpn"
elif link.type == Link.LinkType.MMWAVE:
elif link.type in [
Link.LinkType.TWENTYFOUR_GHZ,
Link.LinkType.SIXTY_GHZ,
Link.LinkType.SEVENTY_EIGHTY_GHZ,
]:
return "60GHz"

return "active"
Expand Down
8 changes: 4 additions & 4 deletions src/meshapi/tests/test_kml_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def test_kml_data(self):
from_device=sn1_omni,
to_device=grand_omni,
status=Link.LinkStatus.ACTIVE,
type=Link.LinkType.MMWAVE,
type=Link.LinkType.SIXTY_GHZ,
)
)

Expand All @@ -109,7 +109,7 @@ def test_kml_data(self):
from_device=sn1_omni,
to_device=brian_omni,
status=Link.LinkStatus.ACTIVE,
type=Link.LinkType.STANDARD,
type=Link.LinkType.FIVE_GHZ,
)
)

Expand All @@ -127,7 +127,7 @@ def test_kml_data(self):
from_device=grand_omni,
to_device=random_omni,
status=Link.LinkStatus.PLANNED,
type=Link.LinkType.STANDARD,
type=Link.LinkType.FIVE_GHZ,
)
)

Expand All @@ -137,7 +137,7 @@ def test_kml_data(self):
from_device=dead_omni,
to_device=random_omni,
status=Link.LinkStatus.ACTIVE,
type=Link.LinkType.STANDARD,
type=Link.LinkType.FIVE_GHZ,
)
)

Expand Down
4 changes: 2 additions & 2 deletions src/meshapi/tests/test_lookups.py
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ def setUp(self):
from_device=d1,
to_device=d2,
status=Link.LinkStatus.ACTIVE,
type=Link.LinkType.STANDARD,
type=Link.LinkType.FIVE_GHZ,
uisp_id="1231",
)
l1.save()
Expand Down Expand Up @@ -1140,7 +1140,7 @@ def test_link_status_search(self):
self.assertEqual(len(response_objs), 0)

def test_link_type_search(self):
response = self.c.get("/api/v1/links/lookup/?type=Standard")
response = self.c.get("/api/v1/links/lookup/?type=5%20GHz")
code = 200
self.assertEqual(
code,
Expand Down
22 changes: 11 additions & 11 deletions src/meshapi/tests/test_map_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ def test_link_data(self):
from_device=sn1_omni,
to_device=grand_omni,
status=Link.LinkStatus.ACTIVE,
type=Link.LinkType.MMWAVE,
type=Link.LinkType.SIXTY_GHZ,
)
)

Expand All @@ -703,7 +703,7 @@ def test_link_data(self):
from_device=sn1_omni,
to_device=brian_omni,
status=Link.LinkStatus.ACTIVE,
type=Link.LinkType.STANDARD,
type=Link.LinkType.FIVE_GHZ,
)
)

Expand All @@ -721,7 +721,7 @@ def test_link_data(self):
from_device=grand_omni,
to_device=random_omni,
status=Link.LinkStatus.PLANNED,
type=Link.LinkType.STANDARD,
type=Link.LinkType.FIVE_GHZ,
)
)

Expand All @@ -730,7 +730,7 @@ def test_link_data(self):
from_device=sn1_omni,
to_device=random_omni,
status=Link.LinkStatus.INACTIVE,
type=Link.LinkType.STANDARD,
type=Link.LinkType.FIVE_GHZ,
)
)

Expand All @@ -739,7 +739,7 @@ def test_link_data(self):
from_device=sn1_omni,
to_device=inactive_omni,
status=Link.LinkStatus.ACTIVE,
type=Link.LinkType.STANDARD,
type=Link.LinkType.FIVE_GHZ,
)
)

Expand Down Expand Up @@ -900,23 +900,23 @@ def test_links_are_deduplicated(self):
from_device=sn1_omni,
to_device=grand_omni,
status=Link.LinkStatus.ACTIVE,
type=Link.LinkType.MMWAVE,
type=Link.LinkType.SIXTY_GHZ,
)
)
links.append(
Link(
from_device=sn1_additional_device,
to_device=grand_additional_device,
status=Link.LinkStatus.ACTIVE,
type=Link.LinkType.STANDARD,
type=Link.LinkType.FIVE_GHZ,
)
)
links.append(
Link(
from_device=grand2_omni,
to_device=grand_omni,
status=Link.LinkStatus.ACTIVE,
type=Link.LinkType.STANDARD,
type=Link.LinkType.FIVE_GHZ,
)
)

Expand Down Expand Up @@ -1160,7 +1160,7 @@ def test_link_install_number_resolution(self):
from_device=device_1,
to_device=device_2,
status=Link.LinkStatus.ACTIVE,
type=Link.LinkType.STANDARD,
type=Link.LinkType.FIVE_GHZ,
)
)

Expand All @@ -1169,7 +1169,7 @@ def test_link_install_number_resolution(self):
from_device=device_2,
to_device=device_3,
status=Link.LinkStatus.ACTIVE,
type=Link.LinkType.STANDARD,
type=Link.LinkType.FIVE_GHZ,
)
)

Expand All @@ -1178,7 +1178,7 @@ def test_link_install_number_resolution(self):
from_device=device_3,
to_device=device_1,
status=Link.LinkStatus.ACTIVE,
type=Link.LinkType.STANDARD,
type=Link.LinkType.FIVE_GHZ,
)
)

Expand Down
37 changes: 27 additions & 10 deletions src/meshdb/utils/spreadsheet_import/parse_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,25 @@
from meshdb.utils.spreadsheet_import.fetch_uisp import download_uisp_links


def convert_spreadsheet_link_type(status: SpreadsheetLinkStatus) -> Link.LinkType:
def convert_spreadsheet_link_type(status: SpreadsheetLinkStatus, notes: Optional[str] = None) -> Link.LinkType:
link_type = None
if status in [
SpreadsheetLinkStatus.active,
]:
link_type = models.Link.LinkType.STANDARD
link_type = models.Link.LinkType.FIVE_GHZ
elif status == SpreadsheetLinkStatus.vpn:
link_type = models.Link.LinkType.VPN
elif status == SpreadsheetLinkStatus.sixty_ghz:
link_type = models.Link.LinkType.MMWAVE
link_type = models.Link.LinkType.SIXTY_GHZ
elif status == SpreadsheetLinkStatus.fiber:
link_type = models.Link.LinkType.FIBER

if notes and "siklu" in notes.lower():
link_type = Link.LinkType.SEVENTY_EIGHTY_GHZ

if notes and "24" in notes:
link_type = Link.LinkType.TWENTYFOUR_GHZ

return link_type


Expand Down Expand Up @@ -100,11 +106,13 @@ def create_link(spreadsheet_link: SpreadsheetLink, from_node: Node, to_node: Nod
to_device = get_representative_device_for_node(to_node, spreadsheet_link.status)

link_notes = "\n".join([spreadsheet_link.notes, spreadsheet_link.comments]).strip()
link_type = convert_spreadsheet_link_type(spreadsheet_link.status, link_notes)

link = models.Link(
from_device=from_device,
to_device=to_device,
status=convert_spreadsheet_link_status(spreadsheet_link.status),
type=convert_spreadsheet_link_type(spreadsheet_link.status),
type=link_type,
install_date=spreadsheet_link.install_date,
abandon_date=spreadsheet_link.abandon_date,
description=spreadsheet_link.where_to_where if spreadsheet_link.where_to_where else None,
Expand Down Expand Up @@ -158,12 +166,19 @@ def load_links_supplement_with_uisp(spreadsheet_links: List[SpreadsheetLink]):
status = Link.LinkStatus.INACTIVE

if uisp_link["type"] == "wireless":
if uisp_link["frequency"] and uisp_link["frequency"] > 8_000:
type = Link.LinkType.MMWAVE
if uisp_link["frequency"]:
if uisp_link["frequency"] < 7_000:
type = Link.LinkType.FIVE_GHZ
elif uisp_link["frequency"] < 40_000:
type = Link.LinkType.TWENTYFOUR_GHZ
elif uisp_link["frequency"] < 70_000:
type = Link.LinkType.SIXTY_GHZ
else:
type = Link.LinkType.SEVENTY_EIGHTY_GHZ
else:
type = Link.LinkType.STANDARD
type = Link.LinkType.FIVE_GHZ
elif uisp_link["type"] == "ethernet":
type = Link.LinkType.STANDARD
type = Link.LinkType.ETHERNET
elif uisp_link["type"] == "pon":
type = Link.LinkType.FIBER
else:
Expand Down Expand Up @@ -216,10 +231,12 @@ def load_links_supplement_with_uisp(spreadsheet_links: List[SpreadsheetLink]):
for link in existing_links:
link.status = convert_spreadsheet_link_status(spreadsheet_link.status)
link.install_date = spreadsheet_link.install_date
if link.type == Link.LinkType.STANDARD:
if link.type == Link.LinkType.FIVE_GHZ:
# If UISP indicates a special type of link, keep that.
# Otherwise, defer to the spreadsheet
link.type = convert_spreadsheet_link_type(spreadsheet_link.status) or Link.LinkType.STANDARD
link.type = (
convert_spreadsheet_link_type(spreadsheet_link.status, link_notes) or Link.LinkType.FIVE_GHZ
)
link.abandon_date = spreadsheet_link.abandon_date
link.description = spreadsheet_link.where_to_where if spreadsheet_link.where_to_where else None
link.notes = link_notes if link_notes else None
Expand Down
Loading