Skip to content

Commit

Permalink
Merge pull request #2 from firefly-cpp/master
Browse files Browse the repository at this point in the history
Average altitude added
  • Loading branch information
vkurup committed Jan 1, 2016
2 parents 4c0aeec + 0a84f5b commit 3b1cb90
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Data extracted:
- calories burned during workout (as estimated by device)
- average, max and min heart rate during workout
- average pace during workout
- average altitude during workout

## Installation

Expand Down
10 changes: 9 additions & 1 deletion tcxparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ def __init__(self, tcx_file):
def hr_values(self):
return [int(x.text) for x in self.root.xpath('//ns:HeartRateBpm/ns:Value', namespaces={'ns': namespace})]

def altitude_points(self):
return [float(x.text) for x in self.root.xpath('//ns:AltitudeMeters', namespaces={'ns': namespace})]

@property
def latitude(self):
return self.activity.Lap.Track.Trackpoint.Position.LatitudeDegrees.pyval
Expand Down Expand Up @@ -69,4 +72,9 @@ def pace(self):
"""Average pace (mm:ss/km for the workout"""
secs_per_km = self.duration/(self.distance/1000)
return time.strftime('%M:%S', time.gmtime(secs_per_km))


@property
def altitude_avg(self):
"""Average altitude for the workout"""
altitude_data = self.altitude_points()
return sum(altitude_data)/len(altitude_data)
3 changes: 3 additions & 0 deletions test_tcxparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ def test_hr_avg(self):

def test_pace(self):
self.assertEquals(self.tcx.pace, '07:05')

def test_altitude_avg_is_correct(self):
self.assertAlmostEqual(self.tcx.altitude_avg, 172.020056184)

if __name__ == '__main__':
unittest.main()

0 comments on commit 3b1cb90

Please sign in to comment.