Search code examples
regexxmlvimgarmin

Find entries with zero distance variance and recorded watts


I'm a cyclist and a programmer. During my rides, I'm recording data to xml files using a phone based gps tracker and a power meter. After the ride, I use the power meter software to merge the data and then upload to a web site. On the website, the resulting data is showing highly inaccurate data for WR Watts (It is a weighted average, also known as normalized power, which by definition is higher than average power and lower than my maximum recorded watts. See http://ridewithgps.com/trips/4834566 (Export TCX History to get the file I'm referring to). /<Watts>\d{4,} returns no results.

Calories:   1809
Max Watts:  676
Avg. Watts: 213 (170 with 0s)
WR Power    23487
Work    1681 kJ
Max Speed:  26.2 mph
Avg. Speed: 16.6 mph

Here are two sample readings from the tcx history file.

      <Trackpoint>
        <Time>2015-05-30T11:35:50Z</Time>
        <Position>
          <LatitudeDegrees>41.96306</LatitudeDegrees>
          <LongitudeDegrees>-87.645939</LongitudeDegrees>
        </Position>
        <AltitudeMeters>177.7</AltitudeMeters>
        <DistanceMeters>71.5</DistanceMeters>
        <Cadence>67</Cadence>
        <Extensions>
          <TPX xmlns="http://www.garmin.com/xmlschemas/ActivityExtension/v2">
            <Watts>104</Watts>
          </TPX>
        </Extensions>
      </Trackpoint>
      <Trackpoint>
        <Time>2015-05-30T11:35:51Z</Time>
        <Position>
          <LatitudeDegrees>41.963076</LatitudeDegrees>
          <LongitudeDegrees>-87.646094</LongitudeDegrees>
        </Position>
        <AltitudeMeters>178.0</AltitudeMeters>
        <DistanceMeters>75.7</DistanceMeters>
        <Cadence>67</Cadence>
        <Extensions>
          <TPX xmlns="http://www.garmin.com/xmlschemas/ActivityExtension/v2">
            <Watts>156</Watts>
          </TPX>
        </Extensions>
      </Trackpoint>

I've reviewed every entry for <Watts>\d*</Watts> where the corresponding Cadence was zero (if I'm not pedaling, watts should be zero).

:g/<Cadence>0/.,+3s/<Watts>[1-9]\d*/<Watts>0/c

But that did not resolve the issue. My next step is to find entries where the distance between tracepoints does not change and which contains a wattage greater than zero. This returns E65: Illegal back reference

:g/<DistanceMeters>\(\d*\)/+1,+15s/<DistanceMeters>\1/

CLARIFICATION:

I'm looking for locations where Watts must be zero and are not. These would be where I am not pedaling (Cadence = 0) and also when I am not moving (Consecutive distance nodes that are identical). I've already corrected the Wattage for cadence = 0, but don't know how to find consecutive <DistanceMeters>N</DistanceMeters> nodes where N is unchanged.


Solution

  • Given enough determination, it can be done:

    :%s/\m<DistanceMeters>\([0-9.]\+\)<\/DistanceMeters>\n\(.*\n\)\{1,15}\s\+<DistanceMeters>\1<\/DistanceMeters>\n\(.*\n\)\{3}\s\+<Watts>\zs[1-9]\d*\ze<\/Watts>/0/gc
    

    However, why on Earth would you want to do that in Vim?