rsyvarth/dsrc-radar-collision-avoidance

LOGGER - Write log parser

Closed this issue · 1 comments

I think it would be wise to implement some basic log parsing code. I imagine that what we want the logs to look like are just a bunch of timestamped json blobs of arbitrary format. Then when we enable the parser it will decode the blobs one by one and when it is "time" for that data to enter the system it will call a function that is passed upon the class's construction with the relevant data.

The following is how I kinda imagine it will work. One of the keys will be to do all of the heavy lifting for logs on startup (aka read the entire file and parse out all of the data on startup) so we aren't wasting too much time during program execution.

Note that json looks almost identical to python dict / list syntax, sorry if that is confusing. Only showing json in the output file line.

Logging

data = {"hi": 1, "test_list": [1, 4, 6]}
logger.log(data)
data = {"hi": 2, "test_list": [1, 5, 6]}
logger.log(data)

Output file

2/9/2016 8:58.053: {"hi": 1, "test_list": [1, 4, 6]}
2/9/2016 8:58.067: {"hi": 2, "test_list": [1, 5, 6]}

Log parser (might want to use something like this? https://docs.python.org/2/library/threading.html#timer-objects, or maybe we run this on a separate thread with sleeps?)

logs = read_and_parse_logs('filename.txt') #read log file into memory & parse the json
# logs looks like this
# {"2/9/2016 8:58.053": {"hi": 1, "test_list": [1, 4, 6]},
# "2/9/2016 8:58.067": {"hi": 2, "test_list": [1, 5, 6]}}
# Note: this is now a python object, no longer a string
for log_time in logs:
  callback_functin(logs[log_time])
  sleep(time_until_next_log(logs, log_time)

I implemented a rough demo-esque version of what I described here today. It still needs a ton of work in order to make it work with actual log files (currently it just has an array in-memory).