Tuesday, 13 February 2018

Fixed my indoor Strava session data with a Python program

My Garmin picked up GPS data this morning during my indoor session and that lead to Strava showing the session as outdoor even though I clicked "Indoor activity". It means I can't properly analyse the power and heart rate data. I don't know why Strava does this actually.

I exported the Strava session to a TCX file and noticed that it had position and speed data in it (even though I had been stationary the whole time)

I wrote a short Python program that modified the XML to remove the <position> tags and set the <speed> to 0.

Then I imported the modified file to Strava and it worked perfectly! Now my session was a proper indoor activity and the graphs looked perfect.

Here is the Python code that I used. Feel free to use it:

import sys

infilename = sys.argv[1]
outfilename = sys.argv[2]

with open(infilename, 'r') as infile:
    with open(outfilename, 'w') as outfile:
        line = infile.readline()
        while line:
            if line.strip().startswith("<Position>"):
                infile.readline()
                infile.readline()
                infile.readline()
            elif line.strip().startswith("<DistanceMeters>"):
                outfile.write("    <DistanceMeters>0</DistanceMeters>\n")
            elif line.strip().startswith("<Speed>"):
                outfile.write("        <Speed>0</Speed>\n")
            elif line.strip().startswith("<MaximumSpeed>"):
                outfile.write("    <MaximumSpeed>0</MaximumSpeed>\n")
            else:
                outfile.write(line)
            line = infile.readline()

No comments:

Post a Comment