Changeset 04c882d in OpenWorkouts-current for ow/models/user.py


Ignore:
Timestamp:
Mar 6, 2019, 11:25:01 AM (5 years ago)
Author:
Borja Lopez <borja@…>
Branches:
current
Children:
8d726ec
Parents:
aa6dcaf
Message:

(#7) Improvements on the workout totals/stats in the user profile page:

  • Fixed styles for the sport/year dropdowns
  • Added "per workout records" for each year (and all time totals), including maximum distance, time and elevation in a single workout.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • ow/models/user.py

    raa6dcaf r04c882d  
    405405            'distance': Decimal(0),
    406406            'elevation': Decimal(0),
     407            'max_time': timedelta(0),
     408            'max_time_wid': None,
     409            'max_distance': Decimal(0),
     410            'max_distance_wid': None,
     411            'max_elevation': Decimal(0),
     412            'max_elevation_wid': None
    407413        }
     414
    408415        if self.activity_sports:
    409416            sport = sport or self.favorite_sport
     
    411418                if workout.sport == sport:
    412419                    if year is None or workout.start.year == year:
     420                        wid = str(workout.workout_id)
     421                        time = workout.duration or timedelta(0)
     422                        distance = workout.distance or Decimal(0)
     423                        elevation = workout.uphill or Decimal(0)
    413424                        totals['workouts'] += 1
    414                         totals['time'] += workout.duration or timedelta(0)
    415                         totals['distance'] += workout.distance or Decimal(0)
    416                         totals['elevation'] += workout.uphill or Decimal(0)
     425                        totals['time'] += time
     426                        totals['distance'] += distance
     427                        totals['elevation'] += elevation
     428                        if time > totals['max_time']:
     429                            totals['max_time'] = time
     430                            totals['max_time_wid'] = wid
     431                        if distance > totals['max_distance']:
     432                            totals['max_distance'] = distance
     433                            totals['max_distance_wid'] = wid
     434                        if elevation > totals['max_elevation']:
     435                            totals['max_elevation'] = elevation
     436                            totals['max_elevation_wid'] = wid
     437
    417438        return totals
Note: See TracChangeset for help on using the changeset viewer.