Skip to content

Commit

Permalink
Fix gpx file generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Adam committed Jan 2, 2018
1 parent 6a43b92 commit e2bea0b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 5 additions & 5 deletions activities/extras/activityfile/ActivityFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ def to_gpx(self):
try:
with open(self.track.trackfile.path + ".gpx", 'w') as gpx_file:
logging.debug("Opened gpx file %s for write" % self.track.trackfile.path + ".gpx")
gpx = libs.gpxpy.gpxpy.gpx.GPX()
gpx_track = libs.gpxpy.gpxpy.gpx.GPXTrack()
gpx = gpxpy.gpx.GPX()
gpx_track = gpxpy.gpx.GPXTrack()
gpx.tracks.append(gpx_track)
gpx_segment = libs.gpxpy.gpxpy.gpx.GPXTrackSegment()
gpx_segment = gpxpy.gpx.GPXTrackSegment()
gpx_track.segments.append(gpx_segment)

for p in self.get_pos():
Expand All @@ -84,12 +84,12 @@ def to_gpx(self):
continue
else:
gps_fixes += 1
gpx_segment.points.append(libs.gpxpy.gpxpy.gpx.GPXTrackPoint(lat, lon))
gpx_segment.points.append(gpxpy.gpx.GPXTrackPoint(lat, lon))

gpx_file.write(gpx.to_xml())

except Exception, msg:
logging.debug("Exception occured in convert: %s" % msg)
logging.error("Exception occured in convert: %s" % msg)

def set_weather(self):
try:
Expand Down
2 changes: 2 additions & 0 deletions activities/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def test_tcx_bike(self):

act = Activity.objects.get(pk=1)
self.assertTrue(os.path.isfile(act.track.trackfile.path + ".gpx"))
self.assertGreater(os.stat(act.track.trackfile.path + ".gpx").st_size, 0)

self.assertEqual(act.time_elapsed, 7723)
self.assertEqual(act.time, 4857)
Expand Down Expand Up @@ -203,6 +204,7 @@ def test_fit_bike(self):
self.assertEqual(response.status_code, 302)
act = Activity.objects.get(pk=1)
self.assertTrue(os.path.isfile(act.track.trackfile.path + ".gpx"))
self.assertGreater(os.stat(act.track.trackfile.path + ".gpx").st_size, 0)

laps = Lap.objects.filter(activity=act)
self.assertEqual(len(laps), 5)
Expand Down

0 comments on commit e2bea0b

Please sign in to comment.