Private
Public Access
1
0

added ranking only options

This commit is contained in:
Sander Roosendaal
2018-06-08 13:55:38 +02:00
parent 85ebdd3ba0
commit a6a564559c
2 changed files with 111 additions and 45 deletions

View File

@@ -522,30 +522,30 @@ class TrendFlexModalForm(forms.Form):
waterboattype = forms.MultipleChoiceField(choices=boattypes, waterboattype = forms.MultipleChoiceField(choices=boattypes,
label='Water Boat Type', label='Water Boat Type',
initial = types.waterboattype) initial = types.waterboattype)
rankingonly = forms.BooleanField(initial=False,
label='Only Ranking Pieces',
required=True)
# This form sets options for the summary stats page # This form sets options for the summary stats page
class StatsOptionsForm(forms.Form): class StatsOptionsForm(forms.Form):
includereststrokes = forms.BooleanField(initial=False,label='Include Rest Strokes',required=False) includereststrokes = forms.BooleanField(initial=False,label='Include Rest Strokes',required=False)
rankingonly = forms.BooleanField(initial=False,
label='Only Ranking Pieces',required=True)
water = forms.BooleanField(initial=False,required=False) water = forms.BooleanField(initial=False,required=False)
waterboattype = forms.MultipleChoiceField(choices=boattypes, waterboattype = forms.MultipleChoiceField(choices=boattypes,
label='Water Boat Type', label='Water Boat Type',
widget=forms.CheckboxSelectMultiple(), widget=forms.CheckboxSelectMultiple(),
initial = types.waterboattype) initial = types.waterboattype)
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(StatsOptionsForm, self).__init__(*args,**kwargs) super(StatsOptionsForm, self).__init__(*args,**kwargs)
for type in types.checktypes: for type in types.checktypes:
self.fields[type] = forms.BooleanField(initial=True,required=False) self.fields[type] = forms.BooleanField(initial=True,required=False)
# rower = forms.BooleanField(initial=True,required=False)
# dynamic = forms.BooleanField(initial=True,required=False)
# slides = forms.BooleanField(initial=True,required=False)
# skierg = forms.BooleanField(initial=False,required=False)
# paddle = forms.BooleanField(initial=False,required=False)
# snow = forms.BooleanField(initial=False,required=False)
# coastal = forms.BooleanField(initial=False,required=False)
# other = forms.BooleanField(initial=False,required=False)
class CourseSelectForm(forms.Form): class CourseSelectForm(forms.Form):
course = forms.ModelChoiceField(queryset=GeoCourse.objects.all()) course = forms.ModelChoiceField(queryset=GeoCourse.objects.all())

View File

@@ -2969,6 +2969,7 @@ def cum_flex_data(
request, request,
options={ options={
'includereststrokes':False, 'includereststrokes':False,
'rankingonly':False,
'workouttypes':[i[0] for i in types.workouttypes], 'workouttypes':[i[0] for i in types.workouttypes],
'waterboattype':types.waterboattype, 'waterboattype':types.waterboattype,
'theuser':0, 'theuser':0,
@@ -2984,6 +2985,7 @@ def cum_flex_data(
options = request.session['options'] options = request.session['options']
workouttypes = options['workouttypes'] workouttypes = options['workouttypes']
rankingonly = options['rankingonly']
includereststrokes = options['includereststrokes'] includereststrokes = options['includereststrokes']
waterboattype = options['waterboattype'] waterboattype = options['waterboattype']
workstrokesonly = not includereststrokes workstrokesonly = not includereststrokes
@@ -3026,23 +3028,31 @@ def cum_flex_data(
promember=1 promember=1
r2 = getrower(theuser) r2 = getrower(theuser)
if rankingonly:
rankingpiece = [True,]
else:
rankingpiece = [True,False]
allworkouts = Workout.objects.filter(user=r2, allworkouts = Workout.objects.filter(user=r2,
workouttype__in=workouttypes, workouttype__in=workouttypes,
boattype__in=waterboattype, boattype__in=waterboattype,
startdatetime__gte=startdate, startdatetime__gte=startdate,
startdatetime__lte=enddate) startdatetime__lte=enddate,
rankingpiece__in=rankingpiece)
if allworkouts: if allworkouts:
res = interactive_cum_flex_chart2(allworkouts,xparam=xparam, res = interactive_cum_flex_chart2(allworkouts,xparam=xparam,
yparam1=yparam1, yparam1=yparam1,
yparam2=yparam2, yparam2=yparam2,
promember=promember, promember=promember,
workstrokesonly=workstrokesonly) workstrokesonly=workstrokesonly,
rankingpiece__in=rankingpiece)
script = res[0] script = res[0]
div = res[1] div = res[1]
else: else:
script = '' script = ''
div = '<p>No erg pieces uploaded for this date range.</p>' div = '<p>No pieces uploaded for this date range.</p>'
scripta = script.split('\n')[2:-1] scripta = script.split('\n')[2:-1]
script = ''.join(scripta) script = ''.join(scripta)
@@ -3070,7 +3080,8 @@ def cum_flex(request,theuser=0,
options={ options={
'includereststrokes':False, 'includereststrokes':False,
'workouttypes':[i[0] for i in types.workouttypes], 'workouttypes':[i[0] for i in types.workouttypes],
'waterboattype':types.waterboattype 'waterboattype':types.waterboattype,
'rankingonly':False,
}): }):
if 'options' in request.session: if 'options' in request.session:
@@ -3086,6 +3097,11 @@ def cum_flex(request,theuser=0,
except KeyError: except KeyError:
includereststrokes = False includereststrokes = False
try:
rankingonly = options['rankingonly']
except KeyError:
rankingonly = False
try: try:
waterboattype = options['waterboattype'] waterboattype = options['waterboattype']
except KeyError: except KeyError:
@@ -3093,10 +3109,6 @@ def cum_flex(request,theuser=0,
workstrokesonly = not includereststrokes workstrokesonly = not includereststrokes
# checktypes = ['water','rower','dynamic','slides','skierg',
# 'paddle','snow','coastal','other']
if deltadays>0: if deltadays>0:
startdate = enddate-datetime.timedelta(days=int(deltadays)) startdate = enddate-datetime.timedelta(days=int(deltadays))
@@ -3130,8 +3142,6 @@ def cum_flex(request,theuser=0,
if result: if result:
promember=1 promember=1
#if not promember:
#return HttpResponseRedirect("/rowers/about/")
# get all indoor rows of in date range # get all indoor rows of in date range
@@ -3170,6 +3180,7 @@ def cum_flex(request,theuser=0,
optionsform = StatsOptionsForm(request.POST) optionsform = StatsOptionsForm(request.POST)
if optionsform.is_valid(): if optionsform.is_valid():
includereststrokes = optionsform.cleaned_data['includereststrokes'] includereststrokes = optionsform.cleaned_data['includereststrokes']
rankingonly = optionsform.cleaned_data['rankingonly']
workstrokesonly = not includereststrokes workstrokesonly = not includereststrokes
waterboattype = optionsform.cleaned_data['waterboattype'] waterboattype = optionsform.cleaned_data['waterboattype']
workouttypes = [] workouttypes = []
@@ -3182,6 +3193,7 @@ def cum_flex(request,theuser=0,
'includereststrokes':includereststrokes, 'includereststrokes':includereststrokes,
'workouttypes':workouttypes, 'workouttypes':workouttypes,
'waterboattype':waterboattype, 'waterboattype':waterboattype,
'rankingonly':rankingonly,
} }
request.session['options'] = options request.session['options'] = options
form = DateRangeForm(initial={ form = DateRangeForm(initial={
@@ -3216,7 +3228,7 @@ def cum_flex(request,theuser=0,
# set options form correctly # set options form correctly
initial = {} initial = {}
initial['includereststrokes'] = includereststrokes initial['includereststrokes'] = includereststrokes
initial['rankingonly'] = rankingonly
initial['waterboattype'] = waterboattype initial['waterboattype'] = waterboattype
for wtype in types.checktypes: for wtype in types.checktypes:
@@ -3235,6 +3247,7 @@ def cum_flex(request,theuser=0,
options['includereststrokes'] = includereststrokes options['includereststrokes'] = includereststrokes
options['rankingonly'] = includereststrokes
options['workouttypes'] =workouttypes options['workouttypes'] =workouttypes
options['waterboattype'] =waterboattype options['waterboattype'] =waterboattype
options['theuser'] =theuser options['theuser'] =theuser
@@ -5730,6 +5743,11 @@ def user_multiflex_select(request,
else: else:
waterboattype = types.waterboattype waterboattype = types.waterboattype
if 'rankingonly' in request.session:
rankingonly = request.session['rankingonly']
else:
rankingonly = False
if 'modalities' in request.session: if 'modalities' in request.session:
modalities = request.session['modalities'] modalities = request.session['modalities']
@@ -5761,6 +5779,7 @@ def user_multiflex_select(request,
if modalityform.is_valid(): if modalityform.is_valid():
modality = modalityform.cleaned_data['modality'] modality = modalityform.cleaned_data['modality']
waterboattype = modalityform.cleaned_data['waterboattype'] waterboattype = modalityform.cleaned_data['waterboattype']
rankingonly = modalityform.cleaned_data['rankingonly']
if modality == 'all': if modality == 'all':
modalities = [m[0] for m in types.workouttypes] modalities = [m[0] for m in types.workouttypes]
else: else:
@@ -5772,7 +5791,7 @@ def user_multiflex_select(request,
request.session['modalities'] = modalities request.session['modalities'] = modalities
request.session['waterboattype'] = waterboattype request.session['waterboattype'] = waterboattype
request.session['rankingonly'] = rankingonly
startdate = datetime.datetime.combine(startdate,datetime.time()) startdate = datetime.datetime.combine(startdate,datetime.time())
enddate = datetime.datetime.combine(enddate,datetime.time(23,59,59)) enddate = datetime.datetime.combine(enddate,datetime.time(23,59,59))
@@ -5793,11 +5812,23 @@ def user_multiflex_select(request,
for b in types.boattypes: for b in types.boattypes:
if b[0] not in waterboattype: if b[0] not in waterboattype:
negtypes.append(b[0]) negtypes.append(b[0])
workouts = Workout.objects.filter(user=r, if rankingonly:
startdatetime__gte=startdate, rankingpiece = [True]
startdatetime__lte=enddate, else:
workouttype__in=modalities).order_by("-date", "-starttime").exclude(boattype__in=negtypes) rankingpiece = [True,False]
workouts = Workout.objects.filter(
user=r,
startdatetime__gte=startdate,
startdatetime__lte=enddate,
workouttype__in=modalities,
rankingpiece__in=rankingpiece
).order_by(
"-date", "-starttime"
).exclude(
boattype__in=negtypes
)
query = request.GET.get('q') query = request.GET.get('q')
if query: if query:
@@ -6222,7 +6253,8 @@ def user_boxplot_select(request,
options={ options={
'includereststrokes':False, 'includereststrokes':False,
'workouttypes':['rower','dynamic','slides'], 'workouttypes':['rower','dynamic','slides'],
'waterboattype':types.waterboattype 'waterboattype':types.waterboattype,
'rankingonly':False,
}, },
userid=0): userid=0):
@@ -6238,6 +6270,11 @@ def user_boxplot_select(request,
except KeyError: except KeyError:
workouttypes = ['rower','dynamic','slides'] workouttypes = ['rower','dynamic','slides']
try:
rankingonly = options['rankingonly']
except KeyError:
rankingonly = False
try: try:
includereststrokes = options['includereststrokes'] includereststrokes = options['includereststrokes']
except KeyError: except KeyError:
@@ -6246,8 +6283,6 @@ def user_boxplot_select(request,
workstrokesonly = not includereststrokes workstrokesonly = not includereststrokes
# checktypes = ['water','rower','dynamic','slides','skierg',
# 'paddle','snow','other','coastal']
waterboattype = types.waterboattype waterboattype = types.waterboattype
if 'startdate' in request.session: if 'startdate' in request.session:
@@ -6295,6 +6330,7 @@ def user_boxplot_select(request,
if optionsform.is_valid(): if optionsform.is_valid():
workouttypes = [] workouttypes = []
waterboattype = optionsform.cleaned_data['waterboattype'] waterboattype = optionsform.cleaned_data['waterboattype']
rankingonly = optionsform.cleaned_data['rankingonly']
for type in types.checktypes: for type in types.checktypes:
if optionsform.cleaned_data[type]: if optionsform.cleaned_data[type]:
workouttypes.append(type) workouttypes.append(type)
@@ -6302,6 +6338,7 @@ def user_boxplot_select(request,
options = { options = {
'workouttypes':workouttypes, 'workouttypes':workouttypes,
'waterboattype':waterboattype, 'waterboattype':waterboattype,
'rankingonly':rankingonly,
} }
request.session['options'] = options request.session['options'] = options
@@ -6325,20 +6362,31 @@ def user_boxplot_select(request,
if b[0] not in waterboattype: if b[0] not in waterboattype:
negtypes.append(b[0]) negtypes.append(b[0])
if rankingonly:
rankingpiece = [True]
else:
rankingpiece = [True,False]
waterinclude = False waterinclude = False
if 'water' in workouttypes:
waterinclude = True for ttype in types.otwtypes:
if ttype in workouttypes:
waterinclude = True
if waterinclude:
workoutsw = Workout.objects.filter(user=r, workoutsw = Workout.objects.filter(user=r,
startdatetime__gte=startdate, startdatetime__gte=startdate,
startdatetime__lte=enddate, startdatetime__lte=enddate,
workouttype='water', workouttype__in=types.otwtypes,
rankingpiece__in=rankingpiece,
).exclude(boattype__in=negtypes) ).exclude(boattype__in=negtypes)
workouttypes = [w for w in workouttypes if w != 'water'] workouttypes = [w for w in workouttypes if w not in types.otwtypes]
workoutse = Workout.objects.filter(user=r, workoutse = Workout.objects.filter(user=r,
startdatetime__gte=startdate, startdatetime__gte=startdate,
startdatetime__lte=enddate, startdatetime__lte=enddate,
workouttype__in=workouttypes) workouttype__in=workouttypes,
rankingpiece__in=rankingpiece)
if waterinclude: if waterinclude:
workouts = workoutse | workoutsw workouts = workoutse | workoutsw
@@ -6347,9 +6395,8 @@ def user_boxplot_select(request,
workouts = workoutse.order_by("-date","-starttime") workouts = workoutse.order_by("-date","-starttime")
if waterinclude: if waterinclude:
workouttypes.append('water') for ttype in types.otwtypes:
workouttypes.append(ttype)
query = request.GET.get('q') query = request.GET.get('q')
if query: if query:
@@ -7710,7 +7757,8 @@ def cumstats(request,theuser=0,
options={ options={
'includereststrokes':False, 'includereststrokes':False,
'workouttypes':['rower','dynamic','slides'], 'workouttypes':['rower','dynamic','slides'],
'waterboattype':types.waterboattype 'waterboattype':types.waterboattype,
'rankingonly':False,
}): }):
if 'options' in request.session: if 'options' in request.session:
@@ -7728,10 +7776,13 @@ def cumstats(request,theuser=0,
includereststrokes = False includereststrokes = False
try:
rankingonly = options['rankingonly']
except KeyError:
rankingonly = False
workstrokesonly = not includereststrokes workstrokesonly = not includereststrokes
# checktypes = ['water','rower','dynamic','slides','skierg',
# 'paddle','snow','other','coastal']
waterboattype = types.waterboattype waterboattype = types.waterboattype
if deltadays>0: if deltadays>0:
@@ -7807,6 +7858,7 @@ def cumstats(request,theuser=0,
includereststrokes = optionsform.cleaned_data['includereststrokes'] includereststrokes = optionsform.cleaned_data['includereststrokes']
workstrokesonly = not includereststrokes workstrokesonly = not includereststrokes
workouttypes = [] workouttypes = []
rankingonly = optionsform.cleaned_data['rankingonly']
waterboattype = optionsform.cleaned_data['waterboattype'] waterboattype = optionsform.cleaned_data['waterboattype']
for type in types.checktypes: for type in types.checktypes:
if optionsform.cleaned_data[type]: if optionsform.cleaned_data[type]:
@@ -7816,6 +7868,7 @@ def cumstats(request,theuser=0,
'includereststrokes':includereststrokes, 'includereststrokes':includereststrokes,
'workouttypes':workouttypes, 'workouttypes':workouttypes,
'waterboattype':waterboattype, 'waterboattype':waterboattype,
'rankingonly':rankingonly,
} }
request.session['options'] = options request.session['options'] = options
form = DateRangeForm() form = DateRangeForm()
@@ -7833,21 +7886,32 @@ def cumstats(request,theuser=0,
try: try:
r2 = getrower(theuser) r2 = getrower(theuser)
if rankingonly:
rankingpiece = [True]
else:
rankingpiece = [True,False]
waterinclude = False waterinclude = False
if 'water' in workouttypes:
waterinclude = True for ttype in types.otwtypes:
if ttype in workouttypes:
waterinclude = True
if waterinclude:
workoutsw = Workout.objects.filter(user=r2, workoutsw = Workout.objects.filter(user=r2,
startdatetime__gte=startdate, startdatetime__gte=startdate,
startdatetime__lte=enddate, startdatetime__lte=enddate,
workouttype='water', workouttype='water',
boattype__in='waterboattype' boattype__in='waterboattype',
rankingpiece__in=rankingpiece,
) )
workouttypes = [w for w in workouttypes if w != 'water'] workouttypes = [w for w in workouttypes if w != 'water']
workoutse = Workout.objects.filter(user=r2, workoutse = Workout.objects.filter(user=r2,
startdatetime__gte=startdate, startdatetime__gte=startdate,
startdatetime__lte=enddate, startdatetime__lte=enddate,
workouttype__in=workouttypes) workouttype__in=workouttypes,
rankingpiece__in=rankingpiece)
if waterinclude: if waterinclude:
allergworkouts = workoutse | workoutsw allergworkouts = workoutse | workoutsw
@@ -7856,7 +7920,9 @@ def cumstats(request,theuser=0,
allergworkouts = workoutse.order_by("-date","-starttime") allergworkouts = workoutse.order_by("-date","-starttime")
if waterinclude: if waterinclude:
workouttypes.append('water') for ttype in types.otwtypes:
workouttypes.append(ttype)
except Rower.DoesNotExist: except Rower.DoesNotExist: