This Code Was Written as part of the Treex Robotics home assignment. This code reads a robot telemetry log file by streaming and prints a per-sensor report (count, min, max, mean and gap count).
cmake -S . -B build
cmake --build build
./build/sensor_log_processor <log_file> [gap_threshold_ms]
gap_threshold_msis optional and defaults to 500ms.
Example:
./build/sensor_log_processor sample_log.txt
./build/sensor_log_processor sample_log.txt 1000
- The file is processed one line at a time, so memory use stays constant regardless of log size. (as request)
- Per-sensor stats (min/max/mean/gap count) are kept in a running
SensorInfoaccumulator per sensor id, updated incrementally rather than storing every reading. - A
Recordobject is used to parse ea lines in to log file into the relevant details. - A line is malformed if it doesn't split into exactly 3 whitespace-separated tokens, or if the timestamp/value fields aren't parseable as a number. Malformed lines are counted and skipped rather than stopping the run. (as requested)
- Gap detection compares each reading's timestamp to that sensor's previous timestamp;
the first reading for a sensor has no previous timestamp, so it's never counted as a
gap (tracked with a
-1sentinel rather than0, since0is a valid timestamp).
- Validate each line regarding (range, type, continuous etc..)
- for example timestamps are in ascending order per sensor
- list of validate sensors
- sensor range (non negative values)
- Handle missing file / unable to open file error
- Log malformed lines