draft view and chart for multi comparison
This commit is contained in:
@@ -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')
|
||||
|
||||
@@ -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 ['','<p>No non-zero data in selection</p>','','']
|
||||
|
||||
|
||||
|
||||
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'):
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -51,14 +51,17 @@
|
||||
|
||||
</div>
|
||||
|
||||
<div id="workouts_table" class="grid_8 alpha">
|
||||
{% if team %}
|
||||
<h3>{{ team.name }} Team Workouts</h3>
|
||||
{% else %}
|
||||
<h3>Team Workouts</h3>
|
||||
{% endif %}
|
||||
<div class="grid_12 alpha">
|
||||
<h3>{{ team.name }} Team Workouts</h3>
|
||||
</div>
|
||||
|
||||
<form enctype="multipart/form-data" action="/rowers/multi-compare" method="post">
|
||||
<div id="workouts_table" class="grid_8 alpha">
|
||||
|
||||
|
||||
{% if workouts %}
|
||||
|
||||
|
||||
<table width="100%" class="listtable">
|
||||
{{ form.as_table }}
|
||||
</table>
|
||||
@@ -66,30 +69,14 @@
|
||||
<p> No workouts found </p>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div id="form_settings" class="grid_4 alpha">
|
||||
{% csrf_token %}
|
||||
<table>
|
||||
{{ chartform.as_table }}
|
||||
</table>
|
||||
<input name='workoutselectform' class="button green" type="submit" value="Submit">
|
||||
</div>
|
||||
</form>
|
||||
|
||||
|
||||
|
||||
<div class="grid_2 prefix_1 omega">
|
||||
<span class="button gray small">
|
||||
{% if workouts.has_previous %}
|
||||
{% if request.GET.q %}
|
||||
<a class="wh" href="?page={{ workouts.previous_page_number }}&q={{ request.GET.q }}"><</a>
|
||||
{% else %}
|
||||
<a class="wh" href="?page={{ workouts.previous_page_number }}"><</a>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
<span>
|
||||
Page {{ workouts.number }} of {{ workouts.paginator.num_pages }}.
|
||||
</span>
|
||||
|
||||
{% if workouts.has_next %}
|
||||
{% if request.GET.q %}
|
||||
<a class="wh" href="?page={{ workouts.next_page_number }}&q={{ request.GET.q }}">></a>
|
||||
{% else %}
|
||||
<a class="wh" href="?page={{ workouts.next_page_number }}">></a>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</span>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
@@ -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<message>\w+.*)/s/(?P<successmessage>\w+.*)$',views.rower_teams_view),
|
||||
url(r'^me/teams/s/(?P<successmessage>\w+.*)$',views.rower_teams_view),
|
||||
url(r'^me/teams/c/(?P<message>\w+.*)$',views.rower_teams_view),
|
||||
|
||||
@@ -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='',
|
||||
|
||||
Reference in New Issue
Block a user