diff --git a/rowers/templates/user_boxplot_select.html b/rowers/templates/user_boxplot_select.html index 9dc758b9..64960688 100644 --- a/rowers/templates/user_boxplot_select.html +++ b/rowers/templates/user_boxplot_select.html @@ -18,7 +18,7 @@ $(function() { // Get the form fields and hidden div - var modality = $("#id_modality"); + var checkbox = $("#id_water"); var hidden = $("#id_waterboattype"); @@ -28,16 +28,14 @@ hidden.hide(); - // Setup an event listener for when the state of the // checkbox changes. - modality.change(function() { + checkbox.change(function() { // Check to see if the checkbox is checked. // If it is, show the fields and populate the input. - // If not, hide the fields. - var Value = modality.val(); - if (Value=='water') { + // If not, hide the fields. + if (checkbox.is(':checked')) { // Show the hidden fields. hidden.show(); } else { @@ -55,12 +53,7 @@ // $("#hidden_field").val(""); } }); - - - }); - - - +}); @@ -119,12 +112,12 @@
- {{ modalityform.as_table }} + {{ optionsform.as_table }}
{% csrf_token %}
- +
diff --git a/rowers/views.py b/rowers/views.py index ef5f6f6e..a129d29b 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -5945,6 +5945,11 @@ def user_boxplot_select(request, successmessage='', startdate=timezone.now()-datetime.timedelta(days=30), enddate=timezone.now()+datetime.timedelta(days=1), + options={ + 'includereststrokes':False, + 'workouttypes':['rower','dynamic','slides'], + 'waterboattype':['1x','2x','2-','4x','4-','8+'] + }, userid=0): if userid == 0: @@ -5955,6 +5960,27 @@ def user_boxplot_select(request, r = getrower(user) + if 'options' in request.session: + options = request.session['options'] + + + try: + workouttypes = options['workouttypes'] + except KeyError: + workouttypes = ['rower','dynamic','slides'] + + try: + includereststrokes = options['includereststrokes'] + except KeyError: + includereststrokes = False + + + workstrokesonly = not includereststrokes + + checktypes = ['water','rower','dynamic','slides','skierg', + 'paddle','snow','other','coastal'] + waterboattype = ['1x','2x','2-','4x','4-','8+'] + if 'startdate' in request.session: startdate = iso8601.parse_date(request.session['startdate']) @@ -5962,22 +5988,23 @@ def user_boxplot_select(request, if 'enddate' in request.session: enddate = iso8601.parse_date(request.session['enddate']) + if startdatestring != "": + startdate = iso8601.parse_date(startdatestring) - if 'waterboattype' in request.session: - waterboattype = request.session['waterboattype'] - else: - waterboattype = ['1x','2x','2-','4x','4-','8+'] + if enddatestring != "": + enddate = iso8601.parse_date(enddatestring) - - if 'modalities' in request.session: - modalities = request.session['modalities'] - if len(modalities) > 1: - modality = 'all' - else: - modality = modalities[0] - else: - modalities = [m[0] for m in types.workouttypes] - modality = 'all' + if enddate < startdate: + s = enddate + enddate = startdate + startdate = s + + if 'startdate' in request.session: + startdate = iso8601.parse_date(request.session['startdate']) + + + if 'enddate' in request.session: + enddate = iso8601.parse_date(request.session['enddate']) if request.method == 'POST' and 'daterange' in request.POST: dateform = DateRangeForm(request.POST) @@ -5994,22 +6021,22 @@ def user_boxplot_select(request, 'enddate':enddate, }) - if request.method == 'POST' and 'modality' in request.POST: - modalityform = TrendFlexModalForm(request.POST) - if modalityform.is_valid(): - modality = modalityform.cleaned_data['modality'] - waterboattype = modalityform.cleaned_data['waterboattype'] - if modality == 'all': - modalities = [m[0] for m in types.workouttypes] - else: - modalities = [modality] + if request.method == 'POST' and 'optionsform' in request.POST: + optionsform = StatsOptionsForm(request.POST) + if optionsform.is_valid(): + workouttypes = [] + waterboattype = optionsform.cleaned_data['waterboattype'] + for type in checktypes: + if optionsform.cleaned_data[type]: + workouttypes.append(type) - if modality != 'water': - waterboattype = [b[0] for b in types.boattypes] + options = { + 'workouttypes':workouttypes, + 'waterboattype':waterboattype, + } + request.session['options'] = options + print options - - request.session['modalities'] = modalities - request.session['waterboattype'] = waterboattype startdate = datetime.datetime.combine(startdate,datetime.time()) enddate = datetime.datetime.combine(enddate,datetime.time(23,59,59)) @@ -6030,10 +6057,31 @@ def user_boxplot_select(request, if b[0] not in waterboattype: negtypes.append(b[0]) - workouts = Workout.objects.filter(user=r, - startdatetime__gte=startdate, - startdatetime__lte=enddate, - workouttype__in=modalities).order_by("-date", "-starttime").exclude(boattype__in=negtypes) + waterinclude = False + if 'water' in workouttypes: + waterinclude = True + workoutsw = Workout.objects.filter(user=r, + startdatetime__gte=startdate, + startdatetime__lte=enddate, + workouttype='water', + ).exclude(boattype__in=negtypes) + workouttypes = [w for w in workouttypes if w != 'water'] + + workoutse = Workout.objects.filter(user=r, + startdatetime__gte=startdate, + startdatetime__lte=enddate, + workouttype__in=workouttypes) + + if waterinclude: + workouts = workoutse | workoutsw + workouts = workouts.distinct().order_by("-date", "-starttime") + else: + workouts = workoutse.order_by("-date","-starttime") + + if waterinclude: + workouttypes.append('water') + + query = request.GET.get('q') if query: @@ -6049,11 +6097,18 @@ def user_boxplot_select(request, form.fields["workouts"].queryset = workouts chartform = BoxPlotChoiceForm() - modalityform = TrendFlexModalForm(initial={ - 'modality':modality, - 'waterboattype':waterboattype - }) + # set options form correctly + initial = {} + initial['waterboattype'] = waterboattype + for wtype in checktypes: + if wtype in workouttypes: + initial[wtype] = True + else: + initial[wtype] = False + + optionsform = StatsOptionsForm(initial=initial) + messages.info(request,successmessage) messages.error(request,message) @@ -6070,7 +6125,7 @@ def user_boxplot_select(request, 'theuser':user, 'form':form, 'chartform':chartform, - 'modalityform':modalityform, + 'optionsform':optionsform, 'teams':get_my_teams(request.user), }) @@ -7388,6 +7443,7 @@ def cumstats(request,theuser=0, if 'options' in request.session: options = request.session['options'] + try: workouttypes = options['workouttypes'] @@ -7497,11 +7553,31 @@ def cumstats(request,theuser=0, try: r2 = getrower(theuser) - allergworkouts = Workout.objects.filter(user=r2, - workouttype__in=workouttypes, - boattype__in=waterboattype, - startdatetime__gte=startdate, - startdatetime__lte=enddate) + waterinclude = False + if 'water' in workouttypes: + waterinclude = True + workoutsw = Workout.objects.filter(user=r2, + startdatetime__gte=startdate, + startdatetime__lte=enddate, + workouttype='water', + boattype__in='waterboattype' + ) + workouttypes = [w for w in workouttypes if w != 'water'] + + workoutse = Workout.objects.filter(user=r2, + startdatetime__gte=startdate, + startdatetime__lte=enddate, + workouttype__in=workouttypes) + + if waterinclude: + allergworkouts = workoutse | workoutsw + allergworkouts = workouts.distinct().order_by("-date", "-starttime") + else: + allergworkouts = workoutse.order_by("-date","-starttime") + + if waterinclude: + workouttypes.append('water') + except Rower.DoesNotExist: allergworkouts = []