I have a love/hate relationship with running. I’ve always enjoyed it because it’s an activity that you can do whenever you want, for however long you want, with minimal equipment or transportation. You just step out the door, and start running. And you burn a lot of calories in the process!
The hate part originates from the toll it takes on your body. A bad running form can cause injuries, and my past running experience has thought me that my knees are my weak point. Over the last couple of years, I have started running, got too excited and didn’t give my body enough time to steadily increase the mileage and get used to it. After a couple of months, my running habit went back to zero due to injuries.
This is why it’s important to measure your running activities. If you’re too stubborn to listen to your body, or if you haven’t been trained on how to do so, measuring your activity can provide you insight in the strain you’re building up, and how you’re progressing towards your running goals.
I’m tracking everything on Strava. It’s a beautiful service that is able to track all your fitness activities from multiple devices, and has a nice social network component to it as well. If you’re a premium member, you get access to more insights on your data and performance, but you’re limited to the insights that Strava offers.
As an example, the Strava website provides the overview below on weekly distance for the last year. You can select other years or select monthly distance, time or elevation gain, but you can’t select a custom period of your choosing.
As a true data-driven IT guy, this is not enough. So I went searching for a way to get my Strava data in Power BI, so that I can create my own insights, metrics and dashboards. Luckily, someone already provided a way to do this.
Strava Power BI data connector
When searching around for existing ways to import Strava activity data in Power BI, there is one article and implementation that consistently kept popping up: Building the Power BI strava data connector by Kasper on BI. I’ll link to that article and GitHub repo:
The article dates back from 2017 and does not seem to be maintained anymore, but its content is still valuable. I won’t rehash the entire instructions that are explained in the article to get the code, build it, connect it to your Strava Application and its keys. I’ll just highlight a couple of findings I made when trying to fetch my Strava activity data:
- The project and the required Visual Studio Power Query SDK are not compatible with Visual Studio 2022, but you can use Visual Studio 2019 Community Edition.
- You need to pay attention to the client_id and client_secret files to not include any spaces in the file when you copy in the keys. If you build the application with spaces, you’ll encounter the following exception when connecting to the connector in Power BI:
Microsoft.Mashup.Engine.Interface.ResourceAccessAuthorizationException
- Power BI versions before the October 2021 release use the Microsoft Internet Explorer 11 embedded control browser for OAuth authentication, which is unsupported by Strava. Therefor make sure that you have a more recent version of Power BI: October 2021 or later. I did notice that trying to authenticate to Strava using a Google account didn’t work, because Google is still complaining about browser incompatibility, but a regular username/password login does work.
The Power BI connector connects to the Strava API. This API is documented on the Strava developer site. It calls 2 endpoints:
- /athlete: Fetches the athlete data of the currently logged in user. It contains the name, city, country, sex information of the user, together with its photo and even the type of shoes. It’s general information that can be used to describe the context of the currently logged in user.
- /athlete/activities: This is the interesting one. It fetches the full list of activities of the user. In my case, this went back all the way to 2011 and pulled in 455 activities! For each activity, you get the type (run, bike, etc.), the distance, the elapsed time, the start time and date and much more. Based on this information you can generate a lot of insights about your activities.
So this is a great starting point. You have the raw data available in Power Bi and can start analysis.
Some insights
Over the year 2021, I trained to run a marathon. Due to my weak knees, I needed to steadily build up mileage. A good practice is the 10% rule: every week, you increase your weekly distance by 10%. I tried to adhere to this rule, but let’s see what the data says.
So let’s say I started off too ambitious! After 8 weeks, I was running 40 kilometers in a week. After that it highly fluctuated between a high of 61 km and a low of 8.2 km. And the data shows that I overdid it. In the last quarter of the chart, the average dropped due to injury. I was still training for a marathon so overdid it again in week 40, but had to dial it back again the weeks after. So was there really no structure in my training plan? There was…
It seems I did not steadily build up the weekly distance, but I did nicely build up my long runs each week. The peaks in the chart show the weekly long run. This is linearly increasing from 5km to 42km.
As a last insight, I wanted to see if there is a correlation between the start time in a day and the distance of the activity. I’m mostly a morning runner, and started my long runs in the weekend very early. Let’s see if the data shows this:
The average distance of all activities was 9.62 km. The activities in the morning before 7 AM are well above that, with nearly all activities of 20 km or more starting before 7 AM. The highest peak in the chart, at 10 AM, was the marathon race, which started at 10 AM. In the evening, most activities were around 10 km, and the same is valid for runs during the day, which was usually on a workday.
Conclusion
The connector provided by Kasper on BI really enabled me to dig deeper into my activity data. It’s not a production ready component but does a perfect job on getting the basic job done. It allowed me to go much further than Strava itself provides, in terms of activity analysis.
This is just the discovery phase. I’m experimenting with the connector, with the Strava API and with Power BI to see what is possible. Some ideas that’ll be coming up in the near future:
- The connector does not cover the entire scope of the Strava API and is only focused on activities. The API itself also offers information about clubs, segments and routes. I want to build on the work of Kasper on BI and extend the connector to cover more information.
- The activities currently do not contain map information. I’d like to see if it’s possible to use Power BI to visualize a route.
[…] is a follow-up post on Strava: Analyse your fitness using Power BI. Go read that post to understand the basics of the PowerBI connector for Strava and how to use […]