From 2bab16843eb19c242d2e16b5d16eefaa7c800e2d Mon Sep 17 00:00:00 2001 From: Silvester Date: Wed, 30 Dec 2015 22:21:54 +0100 Subject: [PATCH 1/2] Average elevation added --- tcxparser.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tcxparser.py b/tcxparser.py index 84cb0d2..ee15323 100644 --- a/tcxparser.py +++ b/tcxparser.py @@ -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 @@ -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)) - \ No newline at end of file + + @property + def altitude_avg(self): + """Average altitude for the workout""" + altitude_data = self.altitude_points() + return sum(altitude_data)/len(altitude_data) \ No newline at end of file From 0a84f5bb0de988595f0f02150303b7180d110879 Mon Sep 17 00:00:00 2001 From: Silvester Date: Fri, 1 Jan 2016 17:48:36 +0100 Subject: [PATCH 2/2] README file updated and test added --- README.md | 1 + test_tcxparser.py | 3 +++ 2 files changed, 4 insertions(+) diff --git a/README.md b/README.md index 4df517f..139ff1f 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/test_tcxparser.py b/test_tcxparser.py index 913fe9f..987a0d3 100644 --- a/test_tcxparser.py +++ b/test_tcxparser.py @@ -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()