Changeset 3ac70ca in OpenWorkouts-current for ow/views/user.py


Ignore:
Timestamp:
Mar 12, 2019, 9:29:22 PM (5 years ago)
Author:
Borja Lopez <borja@…>
Branches:
current
Children:
39dc0a6
Parents:
f2c9e20
Message:

(#7) Improved tooltip that shows per-day workout stats when hovering a day
on the calendar heatmap chart in the user profile page.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ow/views/user.py

    rf2c9e20 r3ac70ca  
    466466                'distance': 0,  # kilometers
    467467                'elevation': 0,  # meters
     468                'workouts': 0,
     469                'sports': {},
    468470            }
    469471        duration = getattr(workout, 'duration', None) or timedelta(0)
     
    473475        elevation = getattr(workout, 'uphill', None) or 0
    474476        stats[start]['elevation'] += int(elevation)
     477        stats[start]['workouts'] += 1
     478        if workout.sport not in stats[start]['sports'].keys():
     479            stats[start]['sports'][workout.sport] = 0
     480        stats[start]['sports'][workout.sport] += 1
    475481
    476482    json_stats = []
     
    484490            str(hms[1]).zfill(2), localizer.translate(_('min.'))
    485491        ])
     492        distance_formatted = str(round(stats[day]['distance'])) + ' km'
     493        elevation_formatted = str(round(stats[day]['elevation'])) + ' m'
    486494        json_stats.append({
    487495            'day': day,
     
    489497            'time_formatted': time_formatted,
    490498            'distance': stats[day]['distance'],
    491             'elevation': stats[day]['elevation']
     499            'distance_formatted': distance_formatted,
     500            'elevation': stats[day]['elevation'],
     501            'elevation_formatted': elevation_formatted,
     502            'workouts': stats[day]['workouts'],
     503            'sports': stats[day]['sports']
    492504        })
    493505
Note: See TracChangeset for help on using the changeset viewer.