Refactor TraceCommand to improve hop labeling logic

- Updated the TraceCommand class to enhance the labeling of hops in the trace output.
- Replaced direct hash retrieval with a conditional approach to determine the source label for each hop, improving clarity in the output format.
- Ensured consistent labeling for the first and last hops, enhancing the readability of the trace results.
This commit is contained in:
agessaman committed 2026-03-09 15:56:07 -07:00
1 parent d084c6bd29
commit 5a96dec558
1 file changed
+10 -6
+10 -6
View File
@@ -156,19 +156,23 @@ class TraceCommand(BaseCommand):
nodes = result.path_nodes
for i, node in enumerate(nodes):
s = node.get("snr")
h = node.get("hash")
label = h if h else self.bot_label
# Left label = source of this hop: bot for first hop, else previous node's hash
if i == 0:
from_label = self.bot_label
else:
prev_h = nodes[i - 1].get("hash")
from_label = prev_h if prev_h else "—"
if i == 0:
# First hop: bot → SNR db →
snr_str = f"{s:.1f} db" if s is not None else "—"
lines.append(f"{label} → {snr_str} →")
lines.append(f"{from_label} → {snr_str} →")
elif i == len(nodes) - 1:
# Last hop: node → SNR → bot
# Last hop: from_node → SNR → bot
snr_str = f"{s:.1f}" if s is not None else "—"
lines.append(f"{label} → {snr_str} → {self.bot_label}")
lines.append(f"{from_label} → {snr_str} → {self.bot_label}")
else:
snr_str = f"{s:.1f}" if s is not None else "—"
lines.append(f"{label} → {snr_str} →")
lines.append(f"{from_label} → {snr_str} →")
return "\n".join(lines)
async def execute(self, message: MeshMessage) -> bool: