Skip to content
Snippets Groups Projects
Commit eb810f7c authored by René Schöne's avatar René Schöne
Browse files

more log formatting

parent 5882c973
No related branches found
No related tags found
No related merge requests found
...@@ -59,26 +59,15 @@ complex_commands = { ...@@ -59,26 +59,15 @@ complex_commands = {
('place-b/reachability/arm2', 'place-b-reachability-2-json', cgv_connector_pb2.Reachability()), ('place-b/reachability/arm2', 'place-b-reachability-2-json', cgv_connector_pb2.Reachability()),
} }
def format_scene(scene: cgv_connector_pb2.Scene):
result = ""
for obj in scene.objects:
if obj.type == cgv_connector_pb2.Object.Type.BOX:
pos = obj.pos
result += f"\n<obj {obj.id:15} at ({pos.x:6.2} {pos.y:6.2} {pos.z:6.2})>"
return result
conversion_topics = { conversion_topics = {
'place-a/scene/update': (cgv_connector_pb2.Scene(), format_scene), 'place-a/scene/update': (cgv_connector_pb2.Scene(), utils.format_scene),
'place-b/scene/update': (cgv_connector_pb2.Scene(), format_scene), 'place-b/scene/update': (cgv_connector_pb2.Scene(), utils.format_scene),
'place-b/command': (cgv_connector_pb2.MergedSelection(), utils.format_command),
'place-b/reachability/arm1': (cgv_connector_pb2.Reachability(), utils.format_reachability),
'place-b/reachability/arm2': (cgv_connector_pb2.Reachability(), utils.format_reachability),
} }
bytes_topics = [ bytes_topics = [
'place-a/scene/update',
'place-b/scene/update',
'place-b/reachability/arm1',
'place-b/reachability/arm2',
'place-b/command',
] ]
button_style_normal = {"marginRight": "15px"} button_style_normal = {"marginRight": "15px"}
...@@ -292,10 +281,15 @@ def append_to_mqtt_log(_n_intervals, clear_n_clicks, value, should_scroll): ...@@ -292,10 +281,15 @@ def append_to_mqtt_log(_n_intervals, clear_n_clicks, value, should_scroll):
:param should_scroll: checkbox value whether to scroll to the end after update :param should_scroll: checkbox value whether to scroll to the end after update
:return: new content of mqtt log :return: new content of mqtt log
""" """
global last_clear_n_clicks ctx = dash.callback_context
if clear_n_clicks and clear_n_clicks > last_clear_n_clicks: if not ctx.triggered:
value = "" return dash.no_update
last_clear_n_clicks = clear_n_clicks
trigger_id = ctx.triggered[0]['prop_id'].split('.')[0]
if trigger_id == 'clear-mqtt-log':
return "", ""
# assume trigger_id == 'every-1-second'
local_messages = [] local_messages = []
while not message_queue.empty(): while not message_queue.empty():
local_messages.append(message_queue.get_nowait()) local_messages.append(message_queue.get_nowait())
......
import threading import threading
from datetime import datetime from datetime import datetime
from google.protobuf import json_format
import cgv_connector_pb2
class MaxTopicLength: class MaxTopicLength:
...@@ -10,7 +12,7 @@ class MaxTopicLength: ...@@ -10,7 +12,7 @@ class MaxTopicLength:
def process_topic(self, topic): def process_topic(self, topic):
if len(topic) > self.max_mqtt_topic_length: if len(topic) > self.max_mqtt_topic_length:
self.max_mqtt_topic_length = len(topic) self.max_mqtt_topic_length = len(topic)
print(f'new long topic length: {self.max_mqtt_topic_length}') print(f"new long topic length: {self.max_mqtt_topic_length}")
self.mqtt_log_reformat_event.set() self.mqtt_log_reformat_event.set()
return self.max_mqtt_topic_length return self.max_mqtt_topic_length
...@@ -30,5 +32,26 @@ def format_log_msg(topic: str, max_mqtt_topic_length: int, message: str, timesta ...@@ -30,5 +32,26 @@ def format_log_msg(topic: str, max_mqtt_topic_length: int, message: str, timesta
def parse_log_msg(entry: str): def parse_log_msg(entry: str):
print("Parsing >", entry, "<") print("Parsing >", entry, "<")
at_index = entry.index('@') at_index = entry.index('@')
closing_bracket_index = entry.index(']') bracket_index = entry.index(']')
return entry[1:at_index].strip(), entry[at_index + 1:closing_bracket_index].strip(), entry[closing_bracket_index+2:] return entry[1:at_index].strip(), entry[at_index + 1:bracket_index].strip(), entry[bracket_index + 2:]
def format_scene(scene: cgv_connector_pb2.Scene):
result = ""
for obj in scene.objects:
if obj.type == cgv_connector_pb2.Object.Type.BOX:
pos = obj.pos
result += f"\n<obj {obj.id:15} at ({pos.x:6.2} {pos.y:6.2} {pos.z:6.2})>"
return result
def format_command(command: cgv_connector_pb2.MergedSelection):
return f"<cmd by {command.idRobot} of {command.idPick} to {command.idPlace}"
def _get_reach_objects(r):
return [objReach.idObject + ' ' + ('' if objReach.reachable else '') for objReach in r.objects]
def format_reachability(r: cgv_connector_pb2.Reachability):
return f"<reach of {r.idRobot}: [{', '.join(_get_reach_objects(r))}]>"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment