added totals to planned sessions view
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user