Skip to content

Commit

Permalink
Merge pull request #3 from firefly-cpp/master
Browse files Browse the repository at this point in the history
Ascent and descent
  • Loading branch information
vkurup committed Jan 2, 2016
2 parents 35fdf17 + 07b0b2c commit 2158874
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Data extracted:
- average, max and min heart rate during workout
- average pace during workout
- average altitude during workout
- ascent and descent of workout

## Installation

Expand Down
24 changes: 23 additions & 1 deletion tcxparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,26 @@ def pace(self):
def altitude_avg(self):
"""Average altitude for the workout"""
altitude_data = self.altitude_points()
return sum(altitude_data)/len(altitude_data)
return sum(altitude_data)/len(altitude_data)

@property
def ascent(self):
"""Returns ascent of workout in meters"""
total_ascent = 0.0
altitude_data = self.altitude_points()
for i in range(len(altitude_data) - 1):
diff = altitude_data[i+1] - altitude_data[i]
if diff > 0.0:
total_ascent += diff
return total_ascent

@property
def descent(self):
"""Returns descent of workout in meters"""
total_descent = 0.0
altitude_data = self.altitude_points()
for i in range(len(altitude_data) - 1):
diff = altitude_data[i+1] - altitude_data[i]
if diff < 0.0:
total_descent += abs(diff)
return total_descent
8 changes: 7 additions & 1 deletion test_tcxparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ def test_pace(self):

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


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

def test_descent_is_correct(self):
self.assertAlmostEqual(self.tcx.descent, 166.307128903)

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

0 comments on commit 2158874

Please sign in to comment.