diff --git a/rowers/forms.py b/rowers/forms.py index 37e6c7aa..cf29f328 100644 --- a/rowers/forms.py +++ b/rowers/forms.py @@ -256,3 +256,13 @@ class StatsOptionsForm(forms.Form): class WorkoutMultipleCompareForm(forms.Form): workouts = forms.ModelMultipleChoiceField(queryset=Workout.objects.all(), widget=forms.CheckboxSelectMultiple()) + +from rowers.interactiveplots import axlabels + +axlabels.pop('None') +axlabels = list(axlabels.items()) + + +class ChartParamChoiceForm(forms.Form): + xparam = forms.ChoiceField(choices=axlabels,initial='distance') + yparam = forms.ChoiceField(choices=axlabels,initial='hr') diff --git a/rowers/interactiveplots.py b/rowers/interactiveplots.py index c59b4124..8987651c 100644 --- a/rowers/interactiveplots.py +++ b/rowers/interactiveplots.py @@ -52,7 +52,7 @@ import rowers.dataprep as dataprep axlabels = { 'time': 'Time', 'distance': 'Distance (m)', - 'cumdist': 'Distance (m)', + 'cumdist': 'Cumulative Distance (m)', 'hr': 'Heart Rate (bpm)', 'spm': 'Stroke Rate (spm)', 'pace': 'Pace (/500m)', @@ -1579,6 +1579,61 @@ def interactive_bar_chart(id=0,promember=0): return [script,div] +def interactive_multiple_compare_chart(ids,xparam,yparam,plottype='line'): + columns = [xparam,yparam, + 'ftime','distance','fpace', + 'power','hr','spm', + 'time','pace','workoutstate', + 'workoutid'] + + datadf = dataprep.getsmallrowdata_db(columns,ids=ids) + + yparamname = axlabels[yparam] + + datadf = datadf[datadf[yparam] > 0] + + datadf = datadf[datadf[xparam] > 0] + + # check if dataframe not empty + if datadf.empty: + return ['','

No non-zero data in selection

','',''] + + + + if xparam=='distance': + xaxmax = datadf['distance'].max() + xaxmin = datadf['distance'].min() + else: + xaxmax = yaxmaxima[xparam] + xaxmin = yaxminima[xparam] + + + x_axis_type = 'linear' + y_axis_type = 'linear' + + # Add hover to this comma-separated string and see what changes + if (promember==1): + TOOLS = 'save,pan,box_zoom,wheel_zoom,reset,tap,resize,crosshair' + else: + TOOLS = 'pan,box_zoom,wheel_zoom,reset,tap,crosshair' + + plot = Figure(x_axis_type=x_axis_type,y_axis_type=y_axis_type, + tools=TOOLS, + toolbar_location="above", + toolbar_sticky=False) + + + for key,grp in datadf.groupby(['workoutid']): + print key + + script, div = components(plot) + + + + return [script,div] + + + def interactive_comparison_chart(id1=0,id2=0,xparam='distance',yparam='spm', promember=0,plottype='line'): diff --git a/rowers/models.py b/rowers/models.py index d43d28c6..b78740e6 100644 --- a/rowers/models.py +++ b/rowers/models.py @@ -407,7 +407,7 @@ class Workout(models.Model): ownerlast = self.user.user.last_name duration = self.duration - stri = u'{d}_{n}_{dist}m_{duration:%H:%M:%S}_{ownerfirst}_{ownerlast}'.format( + stri = u'{d} {n} {dist}m {duration:%H:%M:%S} {ownerfirst} {ownerlast}'.format( d = date.strftime('%Y-%m-%d'), n = name, dist = distance, diff --git a/rowers/templates/team_compare_select.html b/rowers/templates/team_compare_select.html index 67988ec9..3908fb47 100644 --- a/rowers/templates/team_compare_select.html +++ b/rowers/templates/team_compare_select.html @@ -51,14 +51,17 @@ -
- {% if team %} -

{{ team.name }} Team Workouts

- {% else %} -

Team Workouts

- {% endif %} +
+

{{ team.name }} Team Workouts

+
+ +
+
+ {% if workouts %} + + {{ form.as_table }}
@@ -66,30 +69,14 @@

No workouts found

{% endif %}
+
+ {% csrf_token %} + + {{ chartform.as_table }} +
+ +
+
- -
- - {% if workouts.has_previous %} - {% if request.GET.q %} - < - {% else %} - < - {% endif %} - {% endif %} - - - Page {{ workouts.number }} of {{ workouts.paginator.num_pages }}. - - - {% if workouts.has_next %} - {% if request.GET.q %} - > - {% else %} - > - {% endif %} - {% endif %} - - {% endblock %} diff --git a/rowers/urls.py b/rowers/urls.py index fb71fa02..0b1f90c8 100644 --- a/rowers/urls.py +++ b/rowers/urls.py @@ -211,6 +211,7 @@ urlpatterns = [ url(r'^workout/(\d+)/stravauploadw/$',views.workout_strava_upload_view), url(r'^workout/(\d+)/recalcsummary/$',views.workout_recalcsummary_view), url(r'^workout/(\d+)/sporttracksuploadw/$',views.workout_sporttracks_upload_view), + url(r'^multi-compare$',views.multi_compare_view), url(r'^me/teams/c/(?P\w+.*)/s/(?P\w+.*)$',views.rower_teams_view), url(r'^me/teams/s/(?P\w+.*)$',views.rower_teams_view), url(r'^me/teams/c/(?P\w+.*)$',views.rower_teams_view), diff --git a/rowers/views.py b/rowers/views.py index 4e717cbd..0efd134c 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -26,7 +26,7 @@ from rowers.forms import ( StatsOptionsForm,PredictedPieceForm,DateRangeForm,DeltaDaysForm, EmailForm, RegistrationForm, RegistrationFormTermsOfService, RegistrationFormUniqueEmail,CNsummaryForm,UpdateWindForm, - UpdateStreamForm,WorkoutMultipleCompareForm, + UpdateStreamForm,WorkoutMultipleCompareForm,ChartParamChoiceForm ) from rowers.models import Workout, User, Rower, WorkoutForm,FavoriteChart from rowers.models import ( @@ -2027,12 +2027,10 @@ def team_comparison_select(request, (Q(notes__icontains=q) for q in query_list)) ) - workouts1 = workouts - - - form = WorkoutMultipleCompareForm() - form.fields["workouts"].queryset = workouts1 + form.fields["workouts"].queryset = workouts + + chartform = ChartParamChoiceForm() return render(request, 'team_compare_select.html', {'workouts': workouts, @@ -2043,9 +2041,28 @@ def team_comparison_select(request, 'enddate':enddate, 'team':theteam, 'form':form, + 'chartform':chartform, }) - +@login_required() +def multi_compare_view(request): + if request.method == 'POST': + form = WorkoutMultipleCompareForm(request.POST) + chartform = ChartParamChoiceForm(request.POST) + if form.is_valid() and chartform.is_valid(): + cd = form.cleaned_data + workouts = cd['workouts'] + xparam = chartform.cleaned_data['xparam'] + yparam = chartform.cleaned_data['yparam'] + ids = [w.id for w in workouts] + res = interactive_multiple_compare_chart(ids,xparam,yparam) + return HttpResponse("Form is valid") + else: + return HttpResponse("Form is not valid") + else: + url = reverse(workouts_view) + return HttpResponseRedirect(url) + # List Workouts @login_required() def workouts_view(request,message='',successmessage='',