Sunday, 12 March 2017

Star Hill and Rowdow Lane

A sunny ride saw me attempt for the 3rd time the climbs of Star Hill, near Dunton Green, Kent and Rowdow Lane, near Otford.

I have done these twice before but earlier in the year when it was colder and I was on a heavier bike. The warmer weather meant  was on my much lighter Scott and partly as a result set PB on both climbs

I also had my Garmin Virb running so here's a couple of videos of the ascents:

Star Hill:


Rowdow Lane:


Both climbs feature in the Cycling Climbs of the South East, part of Simon Warrens' 100 Greatest Cycling Climbs series of books

Saturday, 11 February 2017

Strava Data Analysis - A PC Based Visual C# Solution - V1.1.0.8 - Updates Feb 1017

Updates of Note Dec 2017

Please see the latest version here: http://midlandscyclist.blogspot.co.uk/2017/12/strava-data-analysis-pc-based-visual-c.html


This post has some useful information but refer to the latest version above

Updates of Note Feb 11 2017
  • Detailed instructions on how to read data that was collected in your privacy zone (if you have set one)
  • Now reads power, temperature and smoothed gradient values in the stream data
  • Small other changes
Version 1.1.0.8 can be downloaded here: link

See other posts here: Post 1 and here: Post 2

After several internal versions and having got to the point to being able to extract and export "stream data" which I then viewed in Excel I realised that I was always missing the beginning and end of the data when I was looking at rides when recorded starting from home. It took a a while to realise that this was because I have set a privacy zone and the default Access Token only gives access to my public data. A lot of research and coding has so far failed to address this in any meaningful way. However I now understand the process and and have been able to get a method to give an Access Token for the full stream data. Its quite involved and is laid out as follows.

The first step is to go the the Authorisation page of your application:



In my case I have set the Authorisation Callback Domain as "localhost":


When I select the Authorise button Strava tries to open a  web page on localhost. This however causes an "404 - Not Found" error page to be opened as there is no server/application to respond:


However you do get back the interim token you need. This is shown in the page address bar of your browser:


You need to copy and keep this code - all the text after "&code=".

Next we need to send this code, together with the application ID and the"Client Secret" Token to Strava to get another Access Token which will be the one that we need.

The Strava API help pages describe this method using techniques I am not familiar with. It seem to use "CURL" which appears to be a means of sending web requests without a browser. I failed to achieve this with many iterations and trials.

I then found another method which was to create a small web page (local file) and open this page in your browser.

This is the code for the webpage:

<html>
<body>
<form action="https://www.strava.com/oauth/token" method="POST">
Client Id
<input type="text" name="client_id" value="YOUR_CLIENT_ID">
<br><br>
Client Secret
<input type="text" name="client_secret" value="YOUR_CLIENT_SECRET">
<br><br>
Code
<input type="text" name="code" value="CODE_FROM_PREVIOUS_STEP">
<br><br>
<input type="submit" value="Submit"></form>
</body>
</html>
 
You can dowload it from here: link

You then enter your client ID, Client Secret and the interim token above (I have obscured my private data in the screen shot below. Also as I iterated several times and then created the screen shots for this Blog later, the access token below is not the same as the screen shot above - but normally it would be)
   
 Paste in the access token and press Submit:
  
You'll then get a file back from Strava - save this file and then open it. In this instance it opened in Visual Studio so I assume that the ".json" extension is associated with this application:



The first response is a new access token (obscured in the screen shot above) which is for this user and allows access to their private data - its persistent so there's no need to repeat the process more than once as long as you keep the key (and in fact my application will store this in an .ini file). Copy and paste in to my application next time you run it.

I am looking at how to do this programmatically as this method is pretty user unfriendly.

Once I had the stream data I also found that 3 of the data streams for power, temperature and smoothed  gradient were not being acquired. Further analysis between the Strava documentation and the StravaDotNet packaqe suggested that Strava had altered the descriptive names of these 3 streams, namely from Watts to watts (power), from Temperature to temp and from GradientSmooth to gradient_smooth. I was using StravaDotNet as a "package" so it was a "black box" and I could not edit the code.

Whilst the source for StravaDotNet is supplied I did not know how to rebuild it as a package.

Some considerable iterations later I have worked out how to stop using it as a package and use the source files "as is". Once I had worked this out I could run through the source files and rename "Watts" to "watts" etc. Once I had made these relatively small changes (although a lot of work was required to get to that point) I could then get this previously missing data into the application. 

In this case I had written the code relatively well (I used a few classes) so extending the code to process 3 more streams was actually quite quick. Whether its well written code or could be better is a different matter of course

Further work:
Get the application to authorise directly without needing to do all the above
Filter data by activity type
Error checking
Some graphics
Get segments from an activity and segment data

Saturday, 7 January 2017

Strava Data Analysis - A PC Based Visual C# Solution - V1.0.0.6

See latest version here: link

Updated Version - V1.0.0.6

Please read this first post for instructions. This is needed to understand what the application does and how it works

The update is from my Google Drive here: V1.0.0.6

This version sees a number of updates:
  1. internally modified as to how the  data grid views are filled and managed. Later versions will use this further and provide additional functionality. For example exporting data is improved
  2. Added the ability to extract the raw time based data from a particular activity. This is the data that is collected during an activity. V1.0.0.1 generated a list of activities and the overall data from that activity
  3. Uses the activity data and generated a simple set of statistics
To set up and use the Application see the link above


To use the new activity data feature load in the activities in the date range required as before.
Select the activity that you want the data for
Double-click in the left most column of that activity and wait for a while. The tab "Activity Data" will contain the time based data and the tab "Activity Stats" will contain basic statistical data.


The Main Window

The Activity Data
Note here that for this ride I was not in my privacy zone so the data does start at 0 seconds. Also I started to ride then stopped and restarted. The Garmin will not log 0 speed so there is a minute "gap" in the time based data.

This exported data can the be plotted or processed in your favourite analysis tool. Here is an Excel version of the data:




The Basic Activity Statistics


Issues to be aware of:
  1. There's minimal error trapping at the moment.
  2. There's no progress indication so it might look like its hung - getting the activities over a wide date range can take quite a long time (depends on the number, connection speed etc.). This needs some improvement
  3. Your data will be exported in TAB separated format. This allows the application to retain commas if used in the activity name - i.e. "First Ride of the year, muddy" for example.
  4. If the activity name includes the " character this is replaced by the ' character -
    i.e. "First Ride of the year, to the "Big Mountain"" for example will be replaced by
    "First Ride of the year, to the 'Big Mountain'"
  5. When you export your activity data, if you have a privacy zones set up any data in this zone is not currently available.
  6.  The .Net Strava API I am using seems a little out of date. For example the official Strava API includes temperature, power etc in the streams. In the Strava API these are "watts" and "temp" but the .Net API refers to these as "Watts" and "Temperature", so even though the data stream contains the data it cannot be accessed. All the source code is provided so I suspect that I'll need to use it differently and modify the code to make it work. This looks "difficult" for someone of my current knowledge level, but is possible
Further Planned Improvements
  1. More fully test the deployment of the application and the installation process. I think the free version of Visual Studio is more limited in the respect
  2. Look for a better way to authenticate the application. Having to create your own application and paste in the token is pretty un-user friendly
  3. Using #2 get access to the private data to get a full data set irrespective of privacy zones
  4. Add simple graphs of activity data
  5. Add simple statistics and graphs of activities data
  6. Enable a means to filter activity types - i.e. Cycling, running etc, and where appropriate filter these further - i.e. for cycling split out rides and turbo trainers for example, or by year for activities
  7. Ability to delete data points where the data is redundant or un-representative
  8. Get more of the data available - so segments etc
  9. Bulk export of all activities or within a date range

Monday, 2 January 2017

WInter Riding

Here's a short video of climbing Rose Hill (almost the top of the Lickey Hills) near Birmingham

Starting in Barnt Green it climbs to the foot of the Hill and then in the mist drops back down the Old Birmingham Road

As with all my rides at the moment, slow and hard work:


My 2016 Year on Strava

Here's my 2016 Year according to Strava:

Click on the Hyperlink not the picture!



 And here is my Veloviewer infographic:

 

Wednesday, 21 December 2016

How does a simple Turbo Trainer Work?

My job in the real world is to support the development of Engine Test Facilities for Jaguar LandRover (JLR) in the UK. Specifically I have a team that support and develop software systems for data delivery, although I know a lot about the non-computer systems. I have developed and deliver a training pack for new employees joining the business as Engine Test Bed Operators that covers a wide range of material.

One of the topics is the dynamometers we use, these being a mix of Eddy Current machines and AC motors. During the discussion I mention my turbo trainer as a type of Eddy current dyno, but with permanent magnets rather than electro-magnets.

Wikipedia has a page about what Eddy Currents dynamometers are here: link.

This image shows the principle. Basically the disk passing through the magnetic field causes currents to be induced in the disk. These currents (eddy) generate an opposing force to the direction of motion and hence this resistance is how power is absorbed. The force is function of the velocity (and of course the magnetic strength and resistance of the disk). Basically for a given design doubling the speed means doubling the power dissipated. the resistance dissipated as heat by the currents flowing through the resistance of the metal.

 

I had not really given the exact mode of operation of my turbo trainer a lot of thought but a couple of things coincided recently and I partially disassembled it to fix an issue.

Firstly I was in my garage to re-build my Giant Defy as a turbo (only) bike after it was possibly damaged when I got knocked off in Nov 2015. Secondly, as I was in the garage I partially disassembled my turbo trainer to try and sort out why it was stuck on a quite high load setting - in some respects training at a higher load makes it a little easier when actually riding on the road but at the same time the load can be just too high and make the turbo sessions unpleasant.

I took the cover off and this was the view of the end of the roller:



It is possible to see the disk and a small cooling fan. I think the disk has holes to aid cooling.

The end cover has 6 magnets in a fixed position:



I had assumed that the cable adjuster moved some magnets radially - low load was with the magnets further out and high load with the magnets fully covering the disk. This was clearly not the way this works. I removed the 3 screws and pulled the fan and the disk off the shaft to find  second set of magnets:



These magnets are mounted on an adjustable plate that rotates about 30deg. This rotation moves these magnets into full alignment or out of alignment, this increasing or decreasing the effective magnetic field and hence the eddy currents and hence resistance. This is a really simple and effective design. Here is a schematic:

 

What's also interesting is that this simple set of magnets and metal disk is capable of absorbing around 400W+ (I don't know what my trainer is rated at but I know that I can't get any where near the limit).

Some minor fettling of the assembly and lubrication of the cable adjuster seemed to sort eveything out and I can now easily adjust the load (via magnet positions).

So one better working turbo trainer later I can "train" better.

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.