Catch stale data from its own timestamps
Task
Write a freshness check that fails when a file's newest reading is too old, run it at two moments, and find the gap in the sensor data that no error ever reported.
Steps
- Write
lab/fresh/fresh.pytaking a CSV file with atimestampcolumn, a current time and a maximum age in hours. If the newest timestamp is within the maximum age it printsfreshand exits 0; otherwise it printsSTALE by N hours, the age in whole hours, and exits 1. - Run it on
data/sensor.csvwith the times 2025-08-30T01:00:00 and 2025-08-31T12:00:00, each with a maximum age of 6 hours. - Find every gap of more than an hour between consecutive readings, and record each in
lab/fresh/gaps.txtasgap: START to END (N hours).
Verify
These checks run in a POSIX shell with Python 3: Terminal on macOS or Linux, and on Windows Git Bash (it comes with Git for Windows) or WSL. On Windows, python3 is often a Microsoft Store placeholder that prints “Python was not found”; run alias python3=py in Git Bash first.
python3 lab/fresh/fresh.py data/sensor.csv 2025-08-30T01:00:00 6; echo "exit $?"
python3 lab/fresh/fresh.py data/sensor.csv 2025-08-31T12:00:00 6; echo "exit $?"
cat lab/fresh/gaps.txt
The first run prints fresh and exits 0; the second prints STALE by 37 hours and exits 1, which a scheduler can alert on. There is one gap: from 2025-07-21T19:00:00 to 2025-07-22T08:00:00, 13 hours, so 12 readings are missing. A line chart would draw straight across it, and nothing would say the data had stopped.
This is an independent study companion for CompTIA Data+ DA0-002 and is not produced by or endorsed by CompTIA.