Changeset c555386 in OpenWorkouts-current


Ignore:
Timestamp:
Jan 11, 2019, 11:56:20 AM (5 years ago)
Author:
borja <borja@…>
Branches:
current, feature/docs, master
Children:
d17dffe
Parents:
b73ae09
Message:

(#26) Several bugfixes when loading data from fit, then generating gpx code

from it:

  • Ensure track points are added to a generated gpx (from a fit file) if they exist.
  • Ensure ascent (uphill), descent (downhill) and distance data is added to the Workout object if there is any in the fit file (fixes loading fit files for indoor training without gps data on them)
  • Load the "sport" property from the fit file when loading data from fit into a Workout object
Location:
ow
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • ow/fit.py

    rb73ae09 rc555386  
    116116        # The schema namespaces info is very important, in order to support
    117117        # all the data we will extract from the fit file.
     118
    118119        gpx = gpxpy.gpx.GPX()
    119120        gpx.creator = 'OpenWorkouts'
     
    202203                    latitude=semicircles_to_degrees(values['position_lat']),
    203204                    longitude=semicircles_to_degrees(values['position_long']),
    204                     elevation=values['enhanced_altitude'],
    205                     speed=values['enhanced_speed'],
    206205                    time=values['timestamp']
    207206                )
    208207
    209             track_point.extensions.append(extensions_root)
    210 
    211             gpx_segment.points.append(track_point)
     208                if 'enhanced_altitude' in values.keys():
     209                    track_point.elevation = values['enhanced_altitude']
     210
     211                if 'enhanced_speed' in values.keys():
     212                    track_point.speed = values['enhanced_speed']
     213
     214                track_point.extensions.append(extensions_root)
     215
     216                gpx_segment.points.append(track_point)
    212217
    213218        # if the fit file has temperature data, calculate the avg
  • ow/models/workout.py

    rb73ae09 rc555386  
    360360
    361361        # grab the needed data from the fit file, update the workout
     362        self.sport = fit.data['sport']
    362363        self.start = fit.data['start']
    363364        # ensure this datetime start object is timezone-aware
     
    365366        # duration comes in seconds, store a timedelta
    366367        self.duration = timedelta(seconds=fit.data['duration'])
    367         # distance comes in meters
    368         self.distance = Decimal(fit.data['distance']) / Decimal(1000.00)
    369         self.uphill = Decimal(fit.data['uphill'])
    370         self.downhill = Decimal(fit.data['downhill'])
     368        if fit.data['distance']:
     369            # distance comes in meters
     370            self.distance = Decimal(fit.data['distance']) / Decimal(1000.00)
     371        if fit.data['uphill']:
     372            self.uphill = Decimal(fit.data['uphill'])
     373        if fit.data['downhill']:
     374            self.downhill = Decimal(fit.data['downhill'])
    371375        # If the user did not provide us with a title, build one from the
    372376        # info in the fit file
  • ow/tests/fixtures/20181230_101115.gpx

    rb73ae09 rc555386  
    5826958269            <gpxtpx:cad>0</gpxtpx:cad>
    5827058270          </gpxtpx:TrackPointExtension>
    58271           <gpxtpx:TrackPointExtension>
    58272             <gpxtpx:atemp>3</gpxtpx:atemp>
    58273             <gpxtpx:hr>139</gpxtpx:hr>
    58274             <gpxtpx:cad>0</gpxtpx:cad>
    58275           </gpxtpx:TrackPointExtension>
    58276         </extensions>
    58277       </trkpt>
    58278       <trkpt lat="43.02351839840412" lon="-7.338556135073304">
    58279         <ele>726.0</ele>
    58280         <time>2018-12-30T11:48:21Z</time>
    58281         <extensions>
    58282           <gpxtpx:TrackPointExtension>
    58283             <gpxtpx:atemp>3</gpxtpx:atemp>
    58284             <gpxtpx:hr>140</gpxtpx:hr>
    58285             <gpxtpx:cad>0</gpxtpx:cad>
    58286           </gpxtpx:TrackPointExtension>
    58287           <gpxtpx:TrackPointExtension>
    58288             <gpxtpx:atemp>3</gpxtpx:atemp>
    58289             <gpxtpx:hr>139</gpxtpx:hr>
    58290             <gpxtpx:cad>0</gpxtpx:cad>
    58291           </gpxtpx:TrackPointExtension>
    5829258271        </extensions>
    5829358272      </trkpt>
Note: See TracChangeset for help on using the changeset viewer.