When out for a long run on Saturday it struck me that, for the same perceived effort, it feels like I'm getting faster in terms of how long each kilometer takes me to run. As Greg Lemond once said "it doesn't get any easier, you just go faster". Hence, when running, I formed a plan to look at the pace stats from my ~2 years worth of Garmin gathered Strava data to see how my pace is changing.
For a previous post I described how to get Strava activity data from the Strava API. After registering for a key, a HTTP GET to an example URL such as:
...returns a bunch of JSON documents, each of which describes a Strava activity and each of which has a unique ID. Then, as described in this post, you can get "lap" data for a particular activity with a HTTP GET to a URL like this:
So what is a "lap"? In it's simplest form, you get a lap logged every time you press "Lap" on your stopwatch. So for an old skool runner, every time you pass a km or mile marker in a race you pressed lap and looked at your watch to see if you were running at your target pace.
These days a modern smartwatch will log every lap for post-analysis and can also be set up to auto-lap on time or distance. For the vast majority of my runs I have my watch configured to auto-lap every km so I have a large set of data ready-available to me!
As all good data is, there is also some messiness in it; specifically for some runs where I've chosen to manually log laps, have had the lap function turned off (so the whole run is a single lap) or have a small sub-km distance at the end of the run that is logged as a lap.
So to analyse the data. I chose to write a Python script on my Raspberry Pi 2 that would:
- Extract activity data from the Strava API. It has a limit of 200 activities per page so I had so request multiple pages.
- Then for each activity, if it was a run, extract lap data from the Strava API.
- Then log all the lap data, taking into account any anomalies (specifically missing heart rate data), into a file for further analysis.
So this created a log file that looked like this:
pi@raspberrypi:~/Strava $ tail lap_log_1.txt
2014-06-16T16:23:19Z|Run|HQ to VW. Strava was naughty and only caught part of it|154234567|1|2014-06-16T17:23:19Z|640|640|2169.9|39.2|-1|-1
2014-06-10T11:13:31Z|Run|Sunny squelchy Smelsmore|151234567|1|2014-06-10T12:13:31Z|2439|2429|8235.2|83.4|-1|-1
2014-06-03T10:57:58Z|Run|Lost in Donnington|148234567|1|2014-06-03T11:57:58Z|1933|1874|6266.7|86.0|-1|-1
2014-05-24T07:43:52Z|Run|Calf rehab run|144234567|1|2014-05-24T08:43:52Z|2992|2964|9977.4|170.7|-1|-1
Time to analyse the data in R!
First import the data into a data frame:
On the graph you can also see a nice even spread of runs from spring 2014 to early summer 2015. There was then a gap when I was injured until Sep 2015 when I returned from injury and then Dec 2015 when I started training in earnest.
The regression line is interesting, reaching it's min point by Autumn 2015 (when I started doing short, fast 5km runs at ~4m10s per km) and then starting to increase again as my distance increased (to ~4m30s per km).
So it was interesting to just look at the most recent data. To find the start point I scanned back in the data to the point I started running again after my injury. This was derived by doing the following command to just extract the first rows of the data frame into a new data frame:
>StravaLaps2 <- StravaLaps1[c(1:423),]
Where "Cheeky HQ Run" was a short tentative run I did as the first of my "comeback". A plot using this data and a regression line is shown below:
Best to look at this by delving into the data even more and just taking Feb and March data:
Taking the run (vertical set of points) on the far right and moving left we see:
- Long 21k run at a consistent pace so lots of points clustered together.
- Shorter hillier run so less points and similar pace.
- Intervals session so some very fast laps (sub 4 min km) and some slow jogging
- Long 18k run at a consistent pace but not so nicely packed together as the 21k run
...and so on back in time with each type of run (long, short and intervals) having it's own telltale "finger print". For example the second run from the right is a 5k fast (for me) Parkrun so has a small number of laps at a pretty good (for me) pace.
Overall I really like this data and what Strava, Raspberry Pi, Python and R lets me do with it. First of all it tells me I'm getting faster which is always good. Second it has an interesting pattern and each type of run is easily distinguishable which is nice. Finally it's MY data; I'm playing with and learning about this stuff with my own data which is somehow more fun than using pre-prepared sample data.