Private
Public Access
1
0

Basic Stats page

This commit is contained in:
Sander Roosendaal
2017-02-05 21:24:17 +01:00
parent 0b183053ba
commit 75681c1220
4 changed files with 239 additions and 27 deletions

View File

@@ -2604,6 +2604,84 @@ def workout_geeky_view(request,id=0,message="",successmessage=""):
'successmessage': successmessage,
'interactiveplot':script,
'the_div':div})
# Stats page
@login_required()
def workout_stats_view(request,id=0,message="",successmessage=""):
workstrokesonly = True
if request.method == 'POST' and 'workstrokesonly' in request.POST:
workstrokesonly = request.POST['workstrokesonly']
row = Workout.objects.get(id=id)
if (checkworkoutuser(request.user,row)==False):
message = "You are not allowed to see the stats of this workout"
url = reverse(workouts_view,args=[str(message)])
return HttpResponseRedirect(url)
columns = ['hr','spm','power','workoutstate']
datadf = dataprep.getsmallrowdata_db(columns,ids=[id])
if datadf.empty:
return HttpResponse("CSV data file not found")
workoutstateswork = [1,4,5,8,9,6,7]
workoutstatesrest = [3]
workoutstatetransition = [0,2,10,11,12,13]
if workstrokesonly=='True' or workstrokesonly==True:
try:
datadf = datadf[~datadf['workoutstate'].isin(workoutstatesrest)]
except:
pass
workstrokesonly = True
stats = {}
# SPM
spmdict = {
'mean':datadf['spm'].mean(),
'max': datadf['spm'].max(),
'min': datadf['spm'].min(),
'std': datadf['spm'].std(),
'median': datadf['spm'].median(),
'firstq':datadf['spm'].quantile(q=0.25),
'thirdq':datadf['spm'].quantile(q=0.75),
}
stats['spm'] = spmdict
# HR
hrdict = {
'mean':datadf['hr'].mean(),
'max': datadf['hr'].max(),
'min': datadf['hr'].min(),
'std': datadf['hr'].std(),
'median': datadf['hr'].median(),
'firstq':datadf['hr'].quantile(q=0.25),
'thirdq':datadf['hr'].quantile(q=0.75),
}
stats['hr'] = hrdict
# Power
powerdict = {
'mean':datadf['power'].mean(),
'max': datadf['power'].max(),
'min': datadf['power'].min(),
'std': datadf['power'].std(),
'median': datadf['power'].median(),
'firstq':datadf['power'].quantile(q=0.25),
'thirdq':datadf['power'].quantile(q=0.75),
}
stats['power'] = powerdict
return render(request,
'workoutstats.html',
{
'stats':stats,
'workout':row,
'workstrokesonly':workstrokesonly,
})
# The Advanced edit page
@login_required()