Changeset 2d2eb0d in OpenWorkouts-current for ow/models/workout.py
- Timestamp:
- Jan 23, 2019, 2:07:26 PM (5 years ago)
- Branches:
- current, feature/docs, master
- Children:
- 4dcf28d
- Parents:
- 5cbc4a0 (diff), c6219ed (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ow/models/workout.py
r5cbc4a0 r2d2eb0d 1 1 import os 2 2 from datetime import datetime, timedelta, timezone 3 3 from decimal import Decimal … … 12 12 copy_blob, 13 13 create_blob, 14 mps_to_kmph, 15 save_map_screenshot 14 16 ) 15 17 … … 50 52 self.duration = kw.get('duration', None) # a timedelta object 51 53 self.distance = kw.get('distance', None) # kilometers, Decimal 54 self.speed = kw.get('speed', {}) 52 55 self.hr_min = kw.get('hr_min', None) # bpm, Decimal 53 56 self.hr_max = kw.get('hr_max', None) # bpm, Decimal … … 211 214 path = None 212 215 if self.tracking_file: 213 path = self.tracking_file._ p_blob_uncommitted216 path = self.tracking_file._uncommitted() 214 217 if path is None: 215 path = self.tracking_file. _p_blob_committed218 path = self.tracking_file.committed() 216 219 return path 217 220 … … 228 231 path = None 229 232 if self.fit_file: 230 path = self.fit_file._ p_blob_uncommitted233 path = self.fit_file._uncommitted() 231 234 if path is None: 232 path = self.fit_file. _p_blob_committed235 path = self.fit_file.committed() 233 236 return path 234 237 … … 348 351 4. Grab some basic info from the fit file and store it in the Workout 349 352 """ 350 # backup the fit file 351 self.fit_file = copy_blob(self.tracking_file) 353 354 # we can call load_from_fit afterwards for updates. In such case, check 355 # if the tracking file is a fit file uploaded to override the previous 356 # one. If not, just reuse the existing fit file 357 if self.tracking_filetype == 'fit': 358 # backup the fit file 359 self.fit_file = copy_blob(self.tracking_file) 352 360 353 361 # create an instance of our Fit class … … 378 386 self.title = fit.name 379 387 388 if fit.data['max_speed']: 389 self.speed['max'] = mps_to_kmph(fit.data['max_speed']) 390 391 if fit.data['avg_speed']: 392 self.speed['avg'] = mps_to_kmph(fit.data['avg_speed']) 393 380 394 if fit.data['avg_hr']: 381 395 self.hr_avg = Decimal(fit.data['avg_hr']) … … 406 420 def has_fit(self): 407 421 return self.fit_file is not None 422 423 @property 424 def map_screenshot(self): 425 """ 426 Return the static path to the screenshot image of the map for 427 this workout (works only for workouts with gps tracking) 428 """ 429 if not self.has_gpx: 430 return None 431 432 current_path = os.path.abspath(os.path.dirname(__file__)) 433 screenshot_path = os.path.join( 434 current_path, '../static/maps', 435 str(self.owner.uid), str(self.workout_id)) + '.png' 436 437 if not os.path.exists(screenshot_path): 438 # screenshot does not exist, generate it 439 save_map_screenshot(self) 440 441 # the value returned is relative to the static files served 442 # by the app, so we can use request.static_url() with it 443 static_path = os.path.join('static/maps', str(self.owner.uid), 444 str(self.workout_id)) 445 return 'ow:' + static_path + '.png'
Note: See TracChangeset
for help on using the changeset viewer.