Commit 3cfcd1c6 authored by Tommi Penttinen's avatar Tommi Penttinen
Browse files

Add support for a hearbeat log

parent c8fde335
Pipeline #41904 passed with stage
in 41 seconds
......@@ -10,4 +10,4 @@ COPY . /usr/src/app
# For Django
EXPOSE 8080
CMD ["websocketd", "--port", "8080", "python3", "/usr/src/app/websocketd_server.py", "/opt/persist/data.csv"]
CMD ["websocketd", "--port", "8080", "python3", "/usr/src/app/websocketd_server.py", "/opt/persist/data", "/opt/persist/hearbeat.log"]
#!/usr/bin/env python3
import datetime
import json
import sys
def main():
output_file = sys.argv[1]
print("Saving output to %s" % output_file)
data_prefix, heartbeat_file = sys.argv[1:]
print("Using file prefix %s for data" % data_prefix)
print("Using heartbeat file %s" % heartbeat_file)
for line in sys.stdin:
entry = line.strip() + ',' + datetime.datetime.now().isoformat()
with open(output_file, 'a') as f:
f.write(entry + '\n')
print(entry)
line = line.strip()
if line.startswith('PING'):
# Let's not care about the possible simultaneous writes. It's just a heart beat.
with open(heartbeat_file, 'a') as f:
f.write(line + '\n')
continue
entry = line + ',' + datetime.datetime.now().isoformat()
tms, direction, vehicle_class, *rest = line.split(',')
print(json.dumps({'tmsNumber': int(tms), 'direction': int(direction), 'vehicle_class': int(vehicle_class)}))
sys.stdout.flush()
data_file = '%s_%d.csv' % (data_prefix, int(tms))
with open(data_file, 'a') as f:
f.write(entry + '\n')
if __name__ == '__main__':
main()
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment