Private
Public Access
1
0

added totals to planned sessions view

This commit is contained in:
Sander Roosendaal
2018-12-10 11:03:10 +01:00
parent 00154596a7
commit 33010215d3
2 changed files with 130 additions and 1 deletions

View File

@@ -9,7 +9,7 @@
<h1>Planned Sessions for {{ rower.user.first_name }} {{ rower.user.last_name }}</h1>
<ul class="main-content">
<li>
<li class="grid_2">
<p>
<form enctype="multipart/form-data" method="get">
<table>
@@ -172,6 +172,82 @@
{% endif %}
</p>
</li>
<li class="grid_2">
<p>
<table width="90%" class="listtable shortpadded">
<thead>
<tr>
<th>&nbsp;</th>
<th>Distance</th>
<th>Time (minutes)</th>
<th>rScore</th>
<th>TRIMP</th>
</tr>
</thead>
<tbody>
<tr>
<td>
Total
</td>
<td>
{{ totals|lookup:'distance' }}
</td>
<td>
{{ totals|lookup:'time' }}
</td>
<td>
{{ totals|lookup:'rscore' }}
</td>
<td>
{{ totals|lookup:'trimp' }}
</td>
</tr>
<tr>
<td>
Planned
</td>
<td>
{{ totals|lookup:'planneddistance' }}
</td>
<td>
{{ totals|lookup:'plannedtime' }}
</td>
<td>
{{ totals|lookup:'plannedrscore' }}
</td>
<td>
{{ totals|lookup:'plannedtrimp' }}
</td>
</tr>
<tr>
<td>
Actual
</td>
<td>
{{ totals|lookup:'actualdistance' }}
</td>
<td>
{{ totals|lookup:'actualtime' }}
</td>
<td>
{{ totals|lookup:'actualrscore' }}
</td>
<td>
{{ totals|lookup:'actualtrimp' }}
</td>
</tr>
</tbody>
</table>
</p>
<p>
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.
</p>
</li>
</ul>

View File

@@ -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,6 +15348,18 @@ 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,
@@ -15338,6 +15390,7 @@ def plannedsessions_view(request,
'plan':trainingplan,
'active': 'nav-plan',
'dateform':dateform,
'totals':totals,
'rower':r,
'timeperiod':timeperiod,
'completeness':completeness,