From 7629183d6d4bde7a60d5f102c4a9cf202aa4b76a Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Mon, 20 Jun 2022 21:48:23 +0200 Subject: [PATCH] added ranking selector --- rowers/forms.py | 3 +++ rowers/views/analysisviews.py | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/rowers/forms.py b/rowers/forms.py index 1b3793fb..fdb19df6 100644 --- a/rowers/forms.py +++ b/rowers/forms.py @@ -1120,6 +1120,9 @@ class AnalysisOptionsForm(forms.Form): label='Water Boat Type', initial=mytypes.waterboattype) + ranking = forms.BooleanField(label='Ranking Workouts Only', + initial=False,required=False) + # form to select modality and boat type for trend flex class TrendFlexModalForm(forms.Form): diff --git a/rowers/views/analysisviews.py b/rowers/views/analysisviews.py index 3f5e4729..7b46b5c9 100644 --- a/rowers/views/analysisviews.py +++ b/rowers/views/analysisviews.py @@ -19,7 +19,8 @@ defaultoptions = { 'includereststrokes': False, 'workouttypes': ['rower', 'dynamic', 'slides'], 'waterboattype': mytypes.waterboattype, - 'function': 'boxplot' + 'function': 'boxplot', + 'ranking': False, } @@ -72,6 +73,11 @@ def analysis_new(request, modalities = [m[0] for m in mytypes.workouttypes_ordered.items()] modality = 'all' + try: + ranking = options['ranking'] + except KeyError: + ranking = False + try: worldclass = options['cpoverlay'] except KeyError: @@ -109,6 +115,7 @@ def analysis_new(request, modality = optionsform.cleaned_data['modality'] waterboattype = optionsform.cleaned_data['waterboattype'] + ranking = optionsform.cleaned_data['ranking'] if modality == 'all': modalities = [m[0] for m in mytypes.workouttypes] else: # pragma: no cover @@ -118,6 +125,7 @@ def analysis_new(request, options['modalities'] = modalities options['waterboattype'] = waterboattype + options['ranking'] = ranking try: worldclass = options['cpoverlay'] except KeyError: @@ -173,17 +181,24 @@ def analysis_new(request, if b[0] not in waterboattype: # pragma: no cover negtypes.append(b[0]) + rankingtypes = [False,True] + if ranking: + rankingtypes = [True] + + if theteam is not None and (theteam.viewing == 'allmembers' or theteam.manager == request.user): # pragma: no cover workouts = Workout.objects.filter(team=theteam, startdatetime__gte=startdate, startdatetime__lte=enddate, workouttype__in=modalities, + rankingpiece__in=rankingtypes, ) elif theteam is not None and theteam.viewing == 'coachonly': # pragma: no cover workouts = Workout.objects.filter(team=theteam, user=r, startdatetime__gte=startdate, startdatetime__lte=enddate, workouttype__in=modalities, + rankingpiece__in=rankingtypes, ) elif thesession is not None: workouts = get_workouts_session(r, thesession) @@ -192,6 +207,7 @@ def analysis_new(request, startdatetime__gte=startdate, startdatetime__lte=enddate, workouttype__in=modalities, + rankingpiece__in=rankingtypes, ) if firstworkout: workouts = firstworkoutquery | workouts @@ -229,6 +245,7 @@ def analysis_new(request, optionsform = AnalysisOptionsForm(initial={ 'modality': modality, 'waterboattype': waterboattype, + 'ranking': ranking, }) if r.birthdate: