From 9bc107f427d3015befd7a7360fea1add92dd6597 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Wed, 3 Apr 2024 22:16:32 +0200 Subject: [PATCH] next version interactive plot --- rowers/forms.py | 12 ++++++++++-- rowers/interactiveplots.py | 16 ++-------------- rowers/models.py | 2 ++ rowers/templates/forcecurve_single.html | 10 +++++++++- rowers/views/workoutviews.py | 24 ++++++++++++++---------- 5 files changed, 37 insertions(+), 27 deletions(-) diff --git a/rowers/forms.py b/rowers/forms.py index c69e3720..f28ed65d 100644 --- a/rowers/forms.py +++ b/rowers/forms.py @@ -1859,12 +1859,13 @@ class FlexOptionsForm(forms.Form): class ForceCurveOptionsForm(forms.Form): includereststrokes = forms.BooleanField(initial=False, required=False, - label='Include Rest Strokes') + label='Include Rest Strokes', + widget=forms.CheckboxInput(attrs={'class':'hidden'})) spm_min = forms.FloatField(initial=15.0,label='SPM Min',widget=HiddenInput,required=False) spm_max = forms.FloatField(initial=55.0,label='SPM Max',widget=HiddenInput,required=False) dist_min = forms.IntegerField(initial=0,label='Dist Min',widget=HiddenInput,required=False) - dist_max = forms.IntegerField(initial=0,label='Dist Max',widget=HiddenInput,required=False) + dist_max = forms.IntegerField(initial=150000,label='Dist Max',widget=HiddenInput,required=False) work_min = forms.IntegerField(initial=0,label='Work Min',widget=HiddenInput,required=False) work_max = forms.IntegerField(initial=1500,label='Work Max',widget=HiddenInput,required=False) @@ -1872,6 +1873,13 @@ class ForceCurveOptionsForm(forms.Form): name = forms.CharField(initial="", label='Name',required=False) + plotcircles = forms.BooleanField(initial=False, + widget=forms.CheckboxInput(attrs={'class':'hidden'}), + required=False) + plotlines = forms.BooleanField(initial=False, + widget=forms.CheckboxInput(attrs={'class':'hidden'}), + required=False) + axchoices = list( (ax[0], ax[1]) for ax in axes if ax[0] not in ['cumdist', 'None'] diff --git a/rowers/interactiveplots.py b/rowers/interactiveplots.py index f8f8a5e0..54ce2b5b 100644 --- a/rowers/interactiveplots.py +++ b/rowers/interactiveplots.py @@ -521,11 +521,7 @@ def interactive_activitychart2(workouts, startdate, enddate, stack='type', return script, div -def interactive_forcecurve(theworkouts, workstrokesonly=True, plottype='scatter', - spm_min=15, spm_max=45, - notes='', - dist_min=0,dist_max=0, - work_min=0,work_max=1500): +def interactive_forcecurve(theworkouts): TOOLS = 'save,pan,box_zoom,wheel_zoom,reset,tap,hover,crosshair' ids = [int(w.id) for w in theworkouts] @@ -537,19 +533,11 @@ def interactive_forcecurve(theworkouts, workstrokesonly=True, plottype='scatter' 'workoutstate', 'driveenergy', 'cumdist'] rowdata = dataprep.getsmallrowdata_db(columns, ids=ids, - workstrokesonly=workstrokesonly) + workstrokesonly=False) rowdata.dropna(axis=1, how='all', inplace=True) rowdata.dropna(axis=0, how='any', inplace=True) - workoutstatesrest = [3] - - if workstrokesonly: - try: - rowdata = rowdata[~rowdata['workoutstate'].isin(workoutstatesrest)] - except KeyError: # pragma: no cover - pass - if rowdata.empty: return "", "No Valid Data Available", "", "" diff --git a/rowers/models.py b/rowers/models.py index 28fce46e..b8cfeda2 100644 --- a/rowers/models.py +++ b/rowers/models.py @@ -5249,6 +5249,8 @@ class ForceCurveAnalysis(models.Model): average_spm = models.FloatField(default=23) average_boatspeed = models.FloatField(default=4.0) include_rest_strokes = models.BooleanField(default=False) + plotcircles = models.BooleanField(default=False) + plotlines = models.BooleanField(default=False) def __str__(self): s = 'Force Curve Analysis {name} ({date})'.format(name = self.name, diff --git a/rowers/templates/forcecurve_single.html b/rowers/templates/forcecurve_single.html index f3251dba..1d95d9a9 100644 --- a/rowers/templates/forcecurve_single.html +++ b/rowers/templates/forcecurve_single.html @@ -14,6 +14,7 @@

Empower Force Curve

    +
  • {{ the_div|safe }} @@ -44,7 +45,14 @@ diff --git a/rowers/views/workoutviews.py b/rowers/views/workoutviews.py index 20c40276..2d871868 100644 --- a/rowers/views/workoutviews.py +++ b/rowers/views/workoutviews.py @@ -426,12 +426,14 @@ def workout_forcecurve_view(request, id=0, analysis=0, userid=0, workstrokesonly work_max = forceanalysis.work_max notes = forceanalysis.notes name = forceanalysis.name + plotcircles = forceanalysis.plotcircles + plotlines = forceanalysis.plotlines includereststrokes = forceanalysis.include_rest_strokes except (ForceCurveAnalysis.DoesNotExist, ValueError): pass else: dist_min = 0 - dist_max = 0 + dist_max = row.distance spm_min = 15 spm_max = 55 work_min = 0 @@ -439,6 +441,8 @@ def workout_forcecurve_view(request, id=0, analysis=0, userid=0, workstrokesonly notes = '' includereststrokes = False name = '' + plotcircles = True + plotlines = False form = ForceCurveOptionsForm(initial={ 'spm_min': spm_min, @@ -449,6 +453,8 @@ def workout_forcecurve_view(request, id=0, analysis=0, userid=0, workstrokesonly 'work_max': work_max, 'notes': notes, 'name': name, + 'plotcircles': plotcircles, + 'plotlines': plotlines, }) @@ -463,6 +469,8 @@ def workout_forcecurve_view(request, id=0, analysis=0, userid=0, workstrokesonly work_max = form.cleaned_data['work_max'] notes = form.cleaned_data['notes'] name = form.cleaned_data['name'] + plotlines = form.cleaned_data['plotlines'] + plotcircles = form.cleaned_data['plotcircles'] if not name: name = row.name includereststrokes = form.cleaned_data['includereststrokes'] @@ -482,6 +490,8 @@ def workout_forcecurve_view(request, id=0, analysis=0, userid=0, workstrokesonly spm_min = spm_min, spm_max = spm_max, rower=row.user, + plotlines = plotlines, + plotcircles = plotcircles, include_rest_strokes = includereststrokes, ) else: @@ -495,6 +505,8 @@ def workout_forcecurve_view(request, id=0, analysis=0, userid=0, workstrokesonly forceanalysis.work_max = work_max forceanalysis.spm_min = spm_min forceanalysis.spm_max = spm_max + forceanalysis.plotcircles = plotcircles + forceanalysis.plotlines = plotlines forceanalysis.include_rest_strokes = includereststrokes forceanalysis.save() dosave = True @@ -523,15 +535,7 @@ def workout_forcecurve_view(request, id=0, analysis=0, userid=0, workstrokesonly script, div = interactive_forcecurve( - [row], - workstrokesonly=workstrokesonly, - dist_min = dist_min, - dist_max = dist_max, - spm_min = spm_min, - spm_max = spm_max, - work_min = work_min, - work_max = work_max, - notes=notes, + [row] ) breadcrumbs = [