automating the stats
This commit is contained in:
@@ -26,7 +26,7 @@ from rowers.forms import SummaryStringForm,IntervalUpdateForm,StrokeDataForm
|
||||
from rowers.models import Workout, User, Rower, WorkoutForm,FavoriteChart
|
||||
from rowers.models import (
|
||||
RowerPowerForm,RowerForm,GraphImage,AdvancedWorkoutForm,
|
||||
RowerPowerZonesForm,AccountRowerForm,UserForm,
|
||||
RowerPowerZonesForm,AccountRowerForm,UserForm,StrokeData,
|
||||
)
|
||||
from rowers.models import FavoriteForm,BaseFavoriteFormSet,SiteAnnouncement
|
||||
from django.forms.formsets import formset_factory
|
||||
@@ -2611,15 +2611,15 @@ def workout_stats_view(request,id=0,message="",successmessage=""):
|
||||
workstrokesonly = True
|
||||
if request.method == 'POST' and 'workstrokesonly' in request.POST:
|
||||
workstrokesonly = request.POST['workstrokesonly']
|
||||
|
||||
|
||||
|
||||
# prepare data frame
|
||||
datadf,row = dataprep.getrowdata_db(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")
|
||||
@@ -2634,45 +2634,45 @@ def workout_stats_view(request,id=0,message="",successmessage=""):
|
||||
except:
|
||||
pass
|
||||
workstrokesonly = True
|
||||
|
||||
# Create stats
|
||||
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 = {}
|
||||
|
||||
|
||||
# Get field names and remove those that are not useful in stats
|
||||
fieldnames = StrokeData._meta.get_all_field_names()
|
||||
fieldnames.remove('workoutid')
|
||||
fieldnames.remove('ergpace')
|
||||
fieldnames.remove('hr_an')
|
||||
fieldnames.remove('hr_tr')
|
||||
fieldnames.remove('hr_at')
|
||||
fieldnames.remove('hr_ut2')
|
||||
fieldnames.remove('hr_ut1')
|
||||
fieldnames.remove('time')
|
||||
fieldnames.remove('distance')
|
||||
fieldnames.remove('nowindpace')
|
||||
fieldnames.remove('fnowindpace')
|
||||
fieldnames.remove('fergpace')
|
||||
fieldnames.remove('equivergpower')
|
||||
fieldnames.remove('workoutstate')
|
||||
fieldnames.remove('fpace')
|
||||
fieldnames.remove('id')
|
||||
fieldnames.remove('ftime')
|
||||
fieldnames.remove('x_right')
|
||||
fieldnames.remove('hr_max')
|
||||
fieldnames.remove('hr_bottom')
|
||||
fieldnames.remove('cumdist')
|
||||
|
||||
# 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),
|
||||
}
|
||||
|
||||
|
||||
for field in fieldnames:
|
||||
thedict = {
|
||||
'mean':datadf[field].mean(),
|
||||
'min': datadf[field].min(),
|
||||
'std': datadf[field].std(),
|
||||
'max': datadf[field].max(),
|
||||
'median': datadf[field].median(),
|
||||
'firstq':datadf[field].quantile(q=0.25),
|
||||
'thirdq':datadf[field].quantile(q=0.75),
|
||||
}
|
||||
stats[field] = thedict
|
||||
|
||||
|
||||
return render(request,
|
||||
|
||||
Reference in New Issue
Block a user