Skip to content

Commit 9d579f2

Browse files
author
James Boulton
committed
Added logs to dashio_data_exporter
1 parent 092ff9b commit 9d579f2

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,5 @@ scratch.py
148148
*_text.py
149149
*_test.py
150150
ttn.py
151-
a
151+
*.raw
152+
*.cvs

utilities/dashio_data_exporter

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import time
66
import ssl
77
import socket
88
import datetime
9+
import json
910
from dataclasses import dataclass
1011
import shortuuid
1112
import sys
@@ -122,11 +123,41 @@ def parse_line_data(rx_username: str, rx_device_id: str, line_data: list[str]) -
122123
elif rx_control_type == 'MAP':
123124
pass
124125
elif rx_control_type == 'LOG':
125-
pass
126+
parse_log_data(control_data)
127+
128+
129+
def format_log_json(log: str):
130+
log_dict = json.loads(log)
131+
log_str = "{time}, {color}, ".format_map(log_dict)
132+
log_str += ", ".join(log_dict["lines"])
133+
return log_str
134+
135+
136+
def parse_log_data(control_data: ControlData):
137+
"""parse the LOG data."""
138+
line = ""
139+
if file_format == 'raw':
140+
line = f"\t{control_data.device_id}\tLOG\t{control_data.control_id}\t"
141+
line += "\t".join(control_data.data)
142+
line += '\n'
143+
if screen:
144+
print(line)
145+
elif file_format == 'cvs':
146+
line = f"# {control_data.device_id}, TGRPH, {control_data.control_id}"
147+
line += "\nTimestamp, color, lines\n"
148+
line += "\n".join(format_log_json(l_str) for l_str in control_data.data)
149+
if screen:
150+
print(line)
151+
if out_to_file:
152+
filename = f"{control_data.device_id}_{control_data.control_type}_{control_data.control_id}_{control_data.data[0]}.{file_format}"
153+
print("Writing to file: " + filename)
154+
with open(filename, "w", encoding='utf-8') as writer:
155+
writer.write(line)
126156

127157

128158
def parse_tgrph_data(control_data: ControlData):
129159
"""parse the TGRPH line"""
160+
line = ""
130161
if file_format == 'raw':
131162
line = f"\t{control_data.device_id}\tTGRPH\t{control_data.control_id}\t"
132163
line += "\t".join(control_data.data)

0 commit comments

Comments
 (0)