Skip to content

Commit

Permalink
Add support for node-level telemetry graphs
Browse files Browse the repository at this point in the history
  • Loading branch information
berticus2016 committed May 20, 2023
1 parent cc7c885 commit 640113d
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions plugins/telemetry_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,14 @@ async def handle_room_message(self, room, event, full_message):
if not self.matches(full_message):
return False

match = re.match(r"^.*: !(batteryLevel|voltage|airUtilTx)$", full_message)
match = re.search(
r":\s+!(batteryLevel|voltage|airUtilTx)(?:\s+(.+))?$", full_message
)
if not match:
return False

telemetry_option = match.group(1)
node = match.group(2)

hourly_intervals = self._generate_timeperiods()
from matrix_utils import connect_matrix
Expand All @@ -93,9 +96,7 @@ async def handle_room_message(self, room, event, full_message):
# Compute the hourly averages for each node
hourly_averages = {}

for node_data_json in self.get_data():
node_data_rows = json.loads(node_data_json[0])

def calculate_averages(node_data_rows):
for record in node_data_rows:
record_time = datetime.fromtimestamp(
record["time"]
Expand All @@ -110,6 +111,14 @@ async def handle_room_message(self, room, event, full_message):
hourly_averages[i].append(telemetry_value)
break

if node:
node_data_rows = self.get_node_data(node)
calculate_averages(node_data_rows)
else:
for node_data_json in self.get_data():
node_data_rows = json.loads(node_data_json[0])
calculate_averages(node_data_rows)

# Compute the final hourly averages
final_averages = {}
for i, interval in enumerate(hourly_intervals[:-1]):
Expand All @@ -132,7 +141,11 @@ async def handle_room_message(self, room, event, full_message):
ax.plot(hourly_strings, average_values)

# Set the plot title and axis labels
ax.set_title(f"Hourly {telemetry_option} Averages")
if node:
title = f"{node} Hourly {telemetry_option} Averages"
else:
title = f"Network Hourly {telemetry_option} Averages"
ax.set_title(title)
ax.set_xlabel("Hour")
ax.set_ylabel(f"{telemetry_option}")

Expand Down

0 comments on commit 640113d

Please sign in to comment.