I decided I wanted a means of tracking progress toward my 1,000 miles of cycling by September 1st. So this weekend I threw together a C++ library and tool to read a fairly simple JSON data file and emit chart.js plots and a table.
The JSON file is pretty straightforward. All I need to do after each rides is add a new entry to the “rides” array. I split the lines in the display below, but in reality I have a single line per “ride” entry. It’s easy to add an entry since I just copy one and edit as needed. The order of the “rides” entries doesn’t matter since my library will sort them by the “odometer” field as needed. So I always add my latest ride as the first “rides” entry just because it’s the fastest (no scrolling).
Note that the “odometer” field for each ride is my bike odometer reading at the end of the given ride. This lets me compute the miles for the given ride by subtracting the odometer reading for the previous ride. In the case of the first ride, I subtract the “startMiles” which represents the odometer reading when the goal is created.
{
"rides": [
{ "time": "6/29/2024 21:30", "odometer": 538.6,
"minutes": 42, "calories": 481 },
{ "time": "6/28/2024 15:45", "odometer": 529.1,
"minutes": 40, "calories": 476 },
{ "time": "6/27/2024 20:30", "odometer": 519.5,
"minutes": 40, "calories": 168 },
{ "time": "6/27/2024 15:00", "odometer": 515.0,
"minutes": 53, "calories": 578 },
{ "time": "6/26/2024 19:25", "odometer": 504.6,
"minutes": 15, "calories": 121 },
{ "time": "6/26/2024 15:22", "odometer": 500.6,
"minutes": 34, "calories": 317 },
{ "time": "6/25/2024 20:40", "odometer": 491.4,
"minutes": 35, "calories": 430 },
{ "time": "6/24/2024 23:50", "odometer": 482.6,
"minutes": 35, "calories": 410 },
{ "time": "6/24/2024 14:00", "odometer": 473.8,
"minutes": 60, "calories": 830 }
],
"startTime": "6/24/2024 00:00",
"goalTime": "9/1/2024 00:00",
"startMiles": 461.0,
"goalMiles": 1000
}
From this simple file I can generate useful charts and a table. I wrote a CGI program that utilizes the C++ library and can emit charts.js graphs and and HTML table. I can embed these with iframes in a web page. That’s exactly what I’m doing to track my progress. You can see these at https://www.rfdm.com/Daniel/Cycling/Goals/20240901.php. And I can of course embed them here too!
One of the things that’s cool about this is that it’s really easy to create a new goal file and just update it after each ride. I can create shorter goals in new files. I can easily change the goal miles or goal time as desired.
I’ll probably create a command line utility to allow me to add rides without editing the file directly. Mainly because I can use it to sanity check input (say an incorrect date/time), and of course can make it a secure client/server application. And at some point I might make an iOS app that can grab the relevant data via HealthKit APIs so I don’t have to type at all.
