Sunday 11 December 2016

Strava Data Analysis - A PC Based Visual C# Solution


See latest version here: link

Note - I am keen for people to test the code I have written whilst I continue to develop it. I will release the source code later (when I work out how this can be done), so for now I have built an application for installation.

Thus this post will continue to change and evolve to capture document this application fully

The application looks like this:



Currently it only does one thing - connect to Strava, download all rides between to user definable dates and allow this to be exported as a Tab Separated file. "Ride Data" means the averaged/final data for a ride (description, average speed, duration etc.). (I have development version that can download the second by second GPS data but this needs more work).

So what do you need to do to use this tool?
  • Create your own Strava Application
  • Install this DotNet application and run it
The reason you need to create your own application is you need a "Strava Token" which you receive when you create an application that ties the data to your account. I think it can access other peoples data as well but I don't understand the documentation for this.

Creating your own Strava Application
On Your Account page you will find a link to create an application. You need to enter 4 pieces of information to get an application. Here is my information (that I can change my existing application): 


You need to enter an Application Name, a website (I have used this Blog as a link at the moment), a description and finally an "Authorisation Callback Domain". This is where I failed but some Googling the problem suggested that "localhost" would get you through, which it did. These settings don't support an online solution but I don't want that - I wanted to be able to connect and get my data using a PC offline tool only

With these entries you can actually create an application and you'll get the following tokens/data:



You will need the "Access Token" to use the application. You can copy and paste from the web page into the application. Don't share your token with others. The Access Token is a 40 character hexadecimal number.

Next you need to get the application. I have put it on my Google Drive and it should be shared with anyone with this link here. Extract it from the .zip file and run setup. All should be OK.

Note that this application uses the DotNet framework so this must be installed. Most Windows PCs will already have this. I am not sure the minimum version required - refining the installer and updates is on the list of things to do!

Once its started you'll need to paste in your Strava Access token in the box and then press the Start Button. 

All being well after a period of time your data should appear in the application. There is currently no progress indicator - so please wait. The longer the data window and the more activities you have to download the longer it takes to get the data - as much as 30 seconds or more. 

Once its complete you can then export the data.

Closing the programme should save your Strava token which will be read next time you run the application.

This is a very short introduction. More details will follow as quickly as I can update this page. Please report all issues via the comments section of this post

Detailed Narrative
Some time ago (2013) I wrote a small tool that downloaded your Strava data using Excel and the wget utility. I documented it here (link) and made it available for download.

However this was thwarted when Strava withdrew support for the API that I was using so my tool stopped working. I gave up looking for alternative solutions at the time as I could download similar data using the great Veloviewer. However this solution was a bit flaky (not sure if it was my browser or what) but it was inconsistent.

I occasionally looked at the Strava Blog and saw that support for external applications was supported but it looked complicated - for example it looked like you needed to call from a web server and use JSON - whatever that is. (see bottom of page for a summary of JSON). However intermittent and continued reading showed that there were also libraries

Language Libraries

The Strava API is implemented using RESTful HTTP JSON patterns. A number of 3rd party language specific libraries exists to wrap this functionality and make usage seemless.

Alongside this were a set of links (replicated below) of all the different libraries implemented by individuals:

 The one that was attractive to me was the .NET library. I have previously written a number of applications in old fashioned C and Delphi, as well as dabbled in VB (the latter because I use Microsoft products a lot at work and have needed to add VBA processing to Excel). I have also played with various versions of Microsoft Visual Studio so was familiar. So I decided to have another go, and chose C# this time (I don't really know why)

There were several steps required (not necessarily in this order:
  • Get Visual Studio
  • Get the Stravadotnet packages
  • Create a Strava Application
  • Read some documentation
  • Try the examples
  • Understand a bit better using Visual Studio
  • Get the examples to work
  • Try various things
  • Work on an example
  • Test and trial the example
  • Get a working piece of code
  • Share with the world
JSON (JavaScript Object Notation is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language, Standard ECMA-262 3rd Edition - December 1999.

2 comments:

  1. Hi Julyan,

    I would like to write some tools based on you guidelines, but I'm a bit stuck with the C# basics (I have very basic programming exerience with VBA only).
    Could you please share some code from your program to see, how can I use the commands properly.

    ReplyDelete
  2. Yes I will provide some of the source code but not for a few days as my PC is out of use at the moment (21 March)

    ReplyDelete