mirror of
https://github.com/okalachev/flix.git
synced 2025-08-16 16:46:11 +00:00
Improve log download: remove empty records, sort by timestamp
To make Plotjuggler not to warn about unsorted records everytime
This commit is contained in:
@@ -9,8 +9,7 @@ PORT = os.environ['PORT']
|
||||
DIR = os.path.dirname(os.path.realpath(__file__))
|
||||
|
||||
dev = serial.Serial(port=PORT, baudrate=115200, timeout=0.5)
|
||||
|
||||
log = open(f'{DIR}/log/{datetime.datetime.now().isoformat()}.csv', 'wb')
|
||||
lines = []
|
||||
|
||||
print('Downloading log...')
|
||||
count = 0
|
||||
@@ -19,8 +18,14 @@ while True:
|
||||
line = dev.readline()
|
||||
if not line:
|
||||
break
|
||||
log.write(line)
|
||||
lines.append(line)
|
||||
count += 1
|
||||
print(f'\r{count} lines', end='')
|
||||
|
||||
# sort by timestamp
|
||||
header = lines.pop(0)
|
||||
lines.sort(key=lambda line: float(line.split(b',')[0]))
|
||||
|
||||
log = open(f'{DIR}/log/{datetime.datetime.now().isoformat()}.csv', 'wb')
|
||||
log.writelines([header] + lines)
|
||||
print(f'\nWritten {os.path.relpath(log.name, os.curdir)}')
|
||||
|
Reference in New Issue
Block a user