From 33010215d3999af2db324ecb8e6ca3850ef9cdc8 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Mon, 10 Dec 2018 11:03:10 +0100 Subject: [PATCH] added totals to planned sessions view --- rowers/templates/plannedsessions.html | 78 ++++++++++++++++++++++++++- rowers/views.py | 53 ++++++++++++++++++ 2 files changed, 130 insertions(+), 1 deletion(-) diff --git a/rowers/templates/plannedsessions.html b/rowers/templates/plannedsessions.html index e50c938e..e59befdd 100644 --- a/rowers/templates/plannedsessions.html +++ b/rowers/templates/plannedsessions.html @@ -9,7 +9,7 @@

Planned Sessions for {{ rower.user.first_name }} {{ rower.user.last_name }}

    -
  • +
  • @@ -172,6 +172,82 @@ {% endif %}

    +
  • +

    +

  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
     DistanceTime (minutes)rScoreTRIMP
    + Total + + {{ totals|lookup:'distance' }} + + {{ totals|lookup:'time' }} + + {{ totals|lookup:'rscore' }} + + {{ totals|lookup:'trimp' }} +
    + Planned + + {{ totals|lookup:'planneddistance' }} + + {{ totals|lookup:'plannedtime' }} + + {{ totals|lookup:'plannedrscore' }} + + {{ totals|lookup:'plannedtrimp' }} +
    + Actual + + {{ totals|lookup:'actualdistance' }} + + {{ totals|lookup:'actualtime' }} + + {{ totals|lookup:'actualrscore' }} + + {{ totals|lookup:'actualtrimp' }} +
    +

    +

    + Total is the total minutes, meters, rScore, TRIMP of all workouts in this + time period. + Planned time is the total time for sessions planned for time. + Actual time is the total time of workouts linked to sessions + planned for time. + Similarly for distance, rScore and TRIMP. +

    +
diff --git a/rowers/views.py b/rowers/views.py index 22b9e651..e0600810 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -15297,6 +15297,46 @@ def plannedsessions_view(request, completiondate = {} sessioncolor = {} + totals = { + 'trimp':0, + 'rscore':0, + 'distance':0, + 'time':0, + 'plannedtime':0, + 'planneddistance':0, + 'plannedtrimp':0, + 'plannedrscore':0, + 'actualtime':0, + 'actualdistance':0, + 'actualtrimp':0, + 'actualrscore':0, + } + + ws = Workout.objects.filter( + user=r, + date__gte=startdate,date__lte=enddate) + + for w in ws: + thetrimp,hrtss = dataprep.workout_trimp(w) + totals['trimp'] += thetrimp + tss = dataprep.workout_rscore(w)[0] + if not np.isnan(tss) and tss != 0: + totals['rscore'] += tss + elif tss == 0: + totals['rscore'] += hrtss + tss = hrtss + totals['distance'] += w.distance + totals['time'] += timefield_to_seconds_duration(w.duration) + if w.plannedsession: + if w.plannedsession.sessionmode == 'distance': + totals['actualdistance'] += w.distance + elif w.plannedsession.sessionmode == 'time': + totals['actualtime'] += timefield_to_seconds_duration(w.duration) + elif w.plannedsession.sessionmode == 'rScore': + totals['actualrscore'] += tss + elif w.plannedsession.sessionmode == 'TRIMP': + totals['actualtrimp'] += thetrimp + if not sps and request.user.rower.rowerplan == 'basic': messages.error(request, "You must purchase Coach or Self-coach plans or be part of a team to get planned sessions") @@ -15308,7 +15348,19 @@ def plannedsessions_view(request, sessioncolor[ps.id] = cratiocolors[status] ws = Workout.objects.filter(user=r,plannedsession=ps) completiondate[ps.id] = cdate + if ps.sessionmode == 'distance': + totals['planneddistance'] += ps.sessionvalue + elif ps.sessionmode == 'time': + totals['plannedtime'] += ps.sessionvalue + elif ps.sessionmode == 'rScore': + totals['plannedrscore'] += ps.sessionvalue + elif ps.sessionmode == 'TRIMP': + totals['plannedtrimp'] += ps.sessionvalue + totals['time'] = int(totals['time']/60.) + totals['actualtime'] = int(totals['actualtime']/60.) + totals['plannedtime'] = int(totals['plannedtime']/60.) + unmatchedworkouts = Workout.objects.filter( user=r, plannedsession=None, @@ -15338,6 +15390,7 @@ def plannedsessions_view(request, 'plan':trainingplan, 'active': 'nav-plan', 'dateform':dateform, + 'totals':totals, 'rower':r, 'timeperiod':timeperiod, 'completeness':completeness,