Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Data extracted:
- average pace during workout
- average altitude during workout
- ascent and descent of workout
- max and min altitude

## Installation

Expand Down
12 changes: 12 additions & 0 deletions tcxparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ def altitude_avg(self):
"""Average altitude for the workout"""
altitude_data = self.altitude_points()
return sum(altitude_data)/len(altitude_data)

@property
def altitude_max(self):
"""Max altitude for the workout"""
altitude_data = self.altitude_points()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's a question that I don't know the answer to... Is every TCX file guaranteed to have ns:AltitudeMeters? If not, or if the list can possibly be empty, then taking the max of an empty list will fail (and dividing by len(altitude) in altitude_avg will also fail).

Do you know what the spec says? It might be best to just assume that altitude_points can be empty, in which case we should check for that and return zero in these 2 methods and altitude_avg.

return max(altitude_data)

@property
def altitude_min(self):
"""Min altitude for the workout"""
altitude_data = self.altitude_points()
return min(altitude_data)

@property
def ascent(self):
Expand Down
6 changes: 6 additions & 0 deletions test_tcxparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@ def test_pace(self):

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

def test_altitude_max_is_correct(self):
self.assertAlmostEqual(self.tcx.altitude_max, 215.95324707)

def test_altitude_min_is_correct(self):
self.assertAlmostEqual(self.tcx.altitude_min, 157.793579102)

def test_ascent_is_correct(self):
self.assertAlmostEqual(self.tcx.ascent, 153.80981445)

Expand Down