Skip to content

Commit

Permalink
very naive support for fitness exts
Browse files Browse the repository at this point in the history
  • Loading branch information
podusowski committed Aug 9, 2016
1 parent 34ab1ee commit e9b73b1
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
13 changes: 12 additions & 1 deletion gpxpy/gpxfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,19 @@ def from_xml(self, parser, node, version):
if children is None:
return result

def drop_tag(s):
parts = s.split(':')
return ''.join(parts[1:]) if len(parts) > 1 else s

for child in children:
result[parser.get_node_name(child)] = parser.get_node_data(child)
sub_children = parser.get_children(child)
print(sub_children)
try:
for sub_child in sub_children:
name = drop_tag(parser.get_node_name(sub_child))
result[name] = parser.get_node_data(sub_child)
except:
result[parser.get_node_name(child)] = parser.get_node_data(child)

return result

Expand Down
4 changes: 4 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2790,6 +2790,10 @@ def test_zero_latlng(self):
self.assertEquals(0, gpx2.tracks[0].segments[0].points[0].longitude)
self.assertEquals(0, gpx2.tracks[0].segments[0].points[0].elevation)

def test_fitness_extension(self):
gpx = self.parse('3p_hr_cad.gpx')
self.assertEquals('100', gpx.tracks[0].segments[0].points[0].extensions['hr'])

class LxmlTests(mod_unittest.TestCase, AbstractTests):
def get_parser_type(self):
return 'lxml'
Expand Down
38 changes: 38 additions & 0 deletions test_files/3p_hr_cad.gpx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<gpx version="1.1" creator="Endomondo.com" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://www.garmin.com/xmlschemas/GpxExtensions/v3 http://www.garmin.com/xmlschemas/GpxExtensionsv3.xsd http://www.garmin.com/xmlschemas/TrackPointExtension/v1 http://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd" xmlns="http://www.topografix.com/GPX/1/1" xmlns:gpxtpx="http://www.garmin.com/xmlschemas/TrackPointExtension/v1" xmlns:gpxx="http://www.garmin.com/xmlschemas/GpxExtensions/v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<trk>
<type>RUNNING</type>
<trkseg>
<trkpt lat="51.05772622860968" lon="16.998099563643336">
<ele>100</ele>
<time>2016-07-30T06:22:05Z</time>
<extensions>
<gpxtpx:TrackPointExtension>
<gpxtpx:hr>100</gpxtpx:hr>
<gpxtpx:cad>60</gpxtpx:cad>
</gpxtpx:TrackPointExtension>
</extensions>
</trkpt>
<trkpt lat="51.05773385614157" lon="16.998072154819965">
<ele>105</ele>
<time>2016-07-30T06:22:06Z</time>
<extensions>
<gpxtpx:TrackPointExtension>
<gpxtpx:hr>110</gpxtpx:hr>
<gpxtpx:cad>70</gpxtpx:cad>
</gpxtpx:TrackPointExtension>
</extensions>
</trkpt>
<trkpt lat="51.05774031020701" lon="16.998041979968548">
<ele>110</ele>
<time>2016-07-30T06:22:07Z</time>
<extensions>
<gpxtpx:TrackPointExtension>
<gpxtpx:hr>120</gpxtpx:hr>
<gpxtpx:cad>80</gpxtpx:cad>
</gpxtpx:TrackPointExtension>
</extensions>
</trkpt>
</trkseg>
</trk>
</gpx>

0 comments on commit e9b73b1

Please sign in to comment.