Skip to content

Commit

Permalink
refactor the way the number of devices are calculated, and use direct…
Browse files Browse the repository at this point in the history
…ly this way when preparing the dimension for matomo (#1798)
  • Loading branch information
pipiche38 authored Nov 28, 2024
1 parent 7afd0ca commit ce05264
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 47 deletions.
37 changes: 12 additions & 25 deletions Modules/matomo_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
import os
import platform
import re
import sys
import time

from Modules.tools import how_many_devices
import distro
import requests

Expand Down Expand Up @@ -71,9 +70,7 @@ def populate_custom_dimmensions(self):
_custom_dimensions[ "dimension4"] = clean_custom_dimension_value( _coordinator_version)

# Network Size
total, router, end_devices = get_network_size_items(self.pluginParameters.get("NetworkSize"))
if total:
_custom_dimensions[ "dimension5"] = clean_custom_dimension_value(total)
_custom_dimensions[ "dimension5"] = clean_custom_dimension_value(get_network_size_items(self))

# Certified Db Version
certified_db_version = self.pluginParameters.get("CertifiedDbVersion")
Expand Down Expand Up @@ -273,28 +270,18 @@ def get_uptime_category(start_time):
return classify_uptime(uptime_seconds)


def get_network_size_items(networksize):

if not networksize:
return None, None, None

# Split the string by " | " to separate each category
parts = networksize.split(" | ")

# Extract individual values using string splitting
try:
networkTotalsize = int(parts[0].split(":")[1].strip()) # Extract the number after "Total: "
networkRoutersize = int(parts[1].split(":")[1].strip()) # Extract the number after "Routers: "
networkEndDevicesize = int(parts[2].split(":")[1].strip()) # Extract the number after "End Devices: "

except IndexError:
print("Error: The string format doesn't match the expected pattern.")
return None, None, None
def get_network_size_items(self):

return classify_nwk_size(networkTotalsize), classify_nwk_size(networkRoutersize), classify_nwk_size(networkEndDevicesize)
routers, end_devices = how_many_devices(self)
networkTotalsize = routers + end_devices

return classify_nwk_size(networkTotalsize)


def classify_nwk_size(value):
if value == 0:
return "unknown"

if value < 5:
return "Micro"
elif 5 <= value < 10:
Expand All @@ -305,8 +292,8 @@ def classify_nwk_size(value):
return "Large"
elif 50 <= value < 75:
return "Very Large"
else:
return "Xtra Large"

return "Xtra Large"


def get_distribution(self):
Expand Down
28 changes: 6 additions & 22 deletions Modules/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1429,34 +1429,18 @@ def extract_info_from_8085(MsgData):

return (step_mod, up_down, step_size, transition)


def how_many_devices(self):
routers = enddevices = 0

for x in self.ListOfDevices:
if "DeviceType" in self.ListOfDevices[x] and self.ListOfDevices[x]["DeviceType"] == "FFD":
routers += 1
continue

if "LogicalType" in self.ListOfDevices[x] and self.ListOfDevices[x]["LogicalType"] == "Router":
routers += 1
continue

if "LogicalType" in self.ListOfDevices[x] and self.ListOfDevices[x]["LogicalType"] == "End Device":
enddevices += 1
continue

if "DeviceType" in self.ListOfDevices[x] and self.ListOfDevices[x]["DeviceType"] == "RFD":
enddevices += 1
continue
for device in self.ListOfDevices.values():
device_type = device.get("DeviceType")
logical_type = device.get("LogicalType")
mac_capa = device.get("MacCapa")

if "MacCapa" in self.ListOfDevices[x] and self.ListOfDevices[x]["MacCapa"] == "8e":
if device_type == "FFD" or logical_type == "Router" or mac_capa == "8e":
routers += 1
continue

if "MacCapa" in self.ListOfDevices[x] and self.ListOfDevices[x]["MacCapa"] == "80":
elif device_type == "RFD" or logical_type == "End Device" or mac_capa == "80":
enddevices += 1
continue

return routers, enddevices

Expand Down

0 comments on commit ce05264

Please sign in to comment.