Changeset 04c882d in OpenWorkouts-current


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.
Location:
ow
Files:
5 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
  • ow/static/css/main.css

    raa6dcaf r04c882d  
    14901490  color: #151515;
    14911491}
     1492.profile-data li a {
     1493  color: #EE4056;
     1494  text-decoration: none;
     1495}
     1496.profile-data li a:hover {
     1497  color: #151515;
     1498}
     1499.profile-data li a:active,
     1500.profile-data li a:focus {
     1501  outline: 0;
     1502  border: none;
     1503  -moz-outline-style: none;
     1504}
    14921505.profile-bio {
    14931506  margin: 0.5em 0;
  • ow/static/less/pages/profile.less

    raa6dcaf r04c882d  
    9090                        color: @color-main;
    9191                }
     92                a {
     93                    color: @color-app;
     94                    text-decoration: none;
     95                    &:hover {
     96                        color: @color-main;
     97                    }
     98                    &:active, &:focus {
     99                        outline: 0;
     100                        border: none;
     101                        -moz-outline-style: none;
     102                    }
     103                }
    92104        }
    93105}
  • ow/templates/profile.pt

    raa6dcaf r04c882d  
    253253                        <tal:t i18n:translate="">m</tal:t>
    254254                      </li>
     255                      <li><span i18n:translate="">Single workout records:</span></li>
     256                      <li>
     257                        <span>
     258                          <tal:t i18n:translate="">Farthest distance</tal:t>
     259                        </span>
     260                        <a href="" tal:attributes="href request.resource_url(context[sport_totals['max_distance_wid']])">
     261                          <tal:w tal:replace="round(sport_totals['max_distance'])"></tal:w>
     262                          <tal:t i18n:translate="">km</tal:t>
     263                        </a>
     264                      </li>
     265                      <li>
     266                        <span>
     267                          <tal:t i18n:translate="">Longer workout</tal:t>
     268                        </span>
     269                        <a href="" tal:attributes="href request.resource_url(context[sport_totals['max_time_wid']])">
     270                          <tal:hms tal:define="hms timedelta_to_hms(sport_totals['max_time'])">
     271                            <tal:h tal:content="str(hms[0]).zfill(2)"></tal:h>
     272                            <tal:t i18n:translate="">hours</tal:t>,
     273                            <tal:h tal:content="str(hms[1]).zfill(2)"></tal:h>
     274                            <tal:t i18n:translate="">min.</tal:t>
     275                          </tal:hms>
     276                        </a>
     277                      </li>
     278                      <li>
     279                        <span>
     280                          <tal:t i18n:translate="">Higher elevation gain</tal:t>
     281                        </span>
     282                        <a href="" tal:attributes="href request.resource_url(context[sport_totals['max_elevation_wid']])">
     283                          <tal:w tal:replace="round(sport_totals['max_elevation'])"></tal:w>
     284                          <tal:t i18n:translate="">m</tal:t>
     285                        </a>
     286                      </li>
    255287                    </ul>
    256288                  </div>
     
    290322                    <tal:w tal:replace="round(sport_totals['elevation'])"></tal:w>
    291323                    <tal:t i18n:translate="">m</tal:t>
     324                  </li>
     325                  <li><span i18n:translate="">Single workout records:</span></li>
     326                  <li>
     327                    <span>
     328                      <tal:t i18n:translate="">Farthest distance</tal:t>
     329                    </span>
     330                    <a href="" tal:attributes="href request.resource_url(context[sport_totals['max_distance_wid']])">
     331                      <tal:w tal:replace="round(sport_totals['max_distance'])"></tal:w>
     332                      <tal:t i18n:translate="">km</tal:t>
     333                    </a>
     334                  </li>
     335                  <li>
     336                    <span>
     337                      <tal:t i18n:translate="">Longer workout</tal:t>
     338                    </span>
     339                    <a href="" tal:attributes="href request.resource_url(context[sport_totals['max_time_wid']])">
     340                      <tal:hms tal:define="hms timedelta_to_hms(sport_totals['max_time'])">
     341                        <tal:h tal:content="str(hms[0]).zfill(2)"></tal:h>
     342                        <tal:t i18n:translate="">hours</tal:t>,
     343                        <tal:h tal:content="str(hms[1]).zfill(2)"></tal:h>
     344                        <tal:t i18n:translate="">min.</tal:t>
     345                      </tal:hms>
     346                    </a>
     347                  </li>
     348                  <li>
     349                    <span>
     350                      <tal:t i18n:translate="">Higher elevation gain</tal:t>
     351                    </span>
     352                    <a href="" tal:attributes="href request.resource_url(context[sport_totals['max_elevation_wid']])">
     353                      <tal:w tal:replace="round(sport_totals['max_elevation'])"></tal:w>
     354                      <tal:t i18n:translate="">m</tal:t>
     355                    </a>
    292356                  </li>
    293357                </ul>
  • ow/tests/models/test_user.py

    raa6dcaf r04c882d  
    659659            'distance': Decimal(0),
    660660            'elevation': Decimal(0),
     661            'max_time': timedelta(0),
     662            'max_time_wid': None,
     663            'max_distance': Decimal(0),
     664            'max_distance_wid': None,
     665            'max_elevation': Decimal(0),
     666            'max_elevation_wid': None
    661667        }
    662668        # add a cycling workout happening now
     
    665671            start=datetime.now(timezone.utc),
    666672            duration=timedelta(minutes=120),
    667             distance=66,
    668         )
    669         root['john'].add_workout(workout)
     673            distance=Decimal(66),
     674        )
     675        root['john'].add_workout(workout)
     676        cycling_wid = workout.workout_id
    670677        # only one workout, one sport, so the default will show totals
    671678        # for that sport
     
    675682            'distance': Decimal(66),
    676683            'elevation': Decimal(0),
     684            'max_time': timedelta(minutes=120),
     685            'max_time_wid': cycling_wid,
     686            'max_distance': Decimal(66),
     687            'max_distance_wid': cycling_wid,
     688            'max_elevation': Decimal(0),
     689            'max_elevation_wid': None
    677690        }
    678691        # Add a running workout
     
    681694            start=datetime(2018, 11, 25, 10, 00, tzinfo=timezone.utc),
    682695            duration=timedelta(minutes=45),
    683             distance=5,
    684         )
    685         root['john'].add_workout(workout)
     696            distance=Decimal(5),
     697        )
     698        root['john'].add_workout(workout)
     699        running_wid = workout.workout_id
    686700        # the favorite sport is running now
    687701        assert root['john'].sport_totals() == {
     
    690704            'distance': Decimal(5),
    691705            'elevation': Decimal(0),
     706            'max_time': timedelta(minutes=45),
     707            'max_time_wid': running_wid,
     708            'max_distance': Decimal(5),
     709            'max_distance_wid': running_wid,
     710            'max_elevation': Decimal(0),
     711            'max_elevation_wid': None,
    692712        }
    693713        # but we can get the totals for cycling too
     
    697717            'distance': Decimal(66),
    698718            'elevation': Decimal(0),
     719            'max_time': timedelta(minutes=120),
     720            'max_time_wid': cycling_wid,
     721            'max_distance': Decimal(66),
     722            'max_distance_wid': cycling_wid,
     723            'max_elevation': Decimal(0),
     724            'max_elevation_wid': None
    699725        }
    700726        # adding a new cycling workout, in a different year
     
    703729            start=datetime(2017, 11, 25, 10, 00, tzinfo=timezone.utc),
    704730            duration=timedelta(minutes=60),
    705             distance=32,
    706         )
    707         root['john'].add_workout(workout)
     731            distance=Decimal(32),
     732            uphill=Decimal(430)
     733        )
     734        root['john'].add_workout(workout)
     735        second_cycling_wid = workout.workout_id
    708736        # now cycling is the favorite sport
    709737        assert root['john'].sport_totals() == {
     
    711739            'time': timedelta(minutes=180),
    712740            'distance': Decimal(98),
    713             'elevation': Decimal(0),
     741            'elevation': Decimal(430),
     742            'max_time': timedelta(minutes=120),
     743            'max_time_wid': cycling_wid,
     744            'max_distance': Decimal(66),
     745            'max_distance_wid': cycling_wid,
     746            'max_elevation': Decimal(430),
     747            'max_elevation_wid': second_cycling_wid
    714748        }
    715749        # but we can get running stats too
     
    719753            'distance': Decimal(5),
    720754            'elevation': Decimal(0),
     755            'max_time': timedelta(minutes=45),
     756            'max_time_wid': running_wid,
     757            'max_distance': Decimal(5),
     758            'max_distance_wid': running_wid,
     759            'max_elevation': Decimal(0),
     760            'max_elevation_wid': None,
    721761        }
    722762        # there are no running activities for 2016
     
    726766            'distance': Decimal(0),
    727767            'elevation': Decimal(0),
     768            'max_time': timedelta(0),
     769            'max_time_wid': None,
     770            'max_distance': Decimal(0),
     771            'max_distance_wid': None,
     772            'max_elevation': Decimal(0),
     773            'max_elevation_wid': None
    728774        }
    729775        # and not activities for cycling in 2016 neither
     
    733779            'distance': Decimal(0),
    734780            'elevation': Decimal(0),
     781            'max_time': timedelta(0),
     782            'max_time_wid': None,
     783            'max_distance': Decimal(0),
     784            'max_distance_wid': None,
     785            'max_elevation': Decimal(0),
     786            'max_elevation_wid': None
    735787        }
    736788        # and we can get the separate totals for cycling in different years
     
    741793            'distance': Decimal(66),
    742794            'elevation': Decimal(0),
     795            'max_time': timedelta(minutes=120),
     796            'max_time_wid': cycling_wid,
     797            'max_distance': Decimal(66),
     798            'max_distance_wid': cycling_wid,
     799            'max_elevation': Decimal(0),
     800            'max_elevation_wid': None
    743801        }
    744802        assert root['john'].sport_totals('cycling', 2017) == {
     
    746804            'time': timedelta(minutes=60),
    747805            'distance': Decimal(32),
    748             'elevation': Decimal(0),
    749         }
     806            'elevation': Decimal(430),
     807            'max_time': timedelta(minutes=60),
     808            'max_time_wid': second_cycling_wid,
     809            'max_distance': Decimal(32),
     810            'max_distance_wid': second_cycling_wid,
     811            'max_elevation': Decimal(430),
     812            'max_elevation_wid': second_cycling_wid
     813        }
Note: See TracChangeset for help on using the changeset viewer.