Private
Public Access
1
0

added boat type selector to stats and flexall

This commit is contained in:
Sander Roosendaal
2017-08-04 13:07:59 +02:00
parent e673255f43
commit 981075fd68
4 changed files with 128 additions and 8 deletions

View File

@@ -275,10 +275,24 @@ class IntervalUpdateForm(forms.Form):
self.fields['type_%s' % i].widget.attrs['style'] = 'width:156px; height: 22px;'
self.fields['intervald_%s' % i].widget = forms.TimeInput(format='%H:%M:%S.%f')
boattypes = (
('1x', '1x (single)'),
('2x', '2x (double)'),
('2-', '2- (pair)'),
('4x', '4x (quad)'),
('4-', '4- (four)'),
('8+', '8+ (eight)'),
)
# This form sets options for the summary stats page
class StatsOptionsForm(forms.Form):
includereststrokes = forms.BooleanField(initial=False,label='Include Rest Strokes',required=False)
water = forms.BooleanField(initial=False,required=False)
waterboattype = forms.MultipleChoiceField(choices=boattypes,
label='Water Boat Type',
widget=forms.CheckboxSelectMultiple(),
initial = ['1x','2x','2-','4x','4-','8+'])
rower = forms.BooleanField(initial=True,required=False)
dynamic = forms.BooleanField(initial=True,required=False)
slides = forms.BooleanField(initial=True,required=False)

View File

@@ -9,6 +9,55 @@
{{ js_res | safe }}
{{ css_res| safe }}
<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
$(function() {
// Get the form fields and hidden div
var checkbox = $("#id_water");
var hidden = $("#id_waterboattype");
// Hide the fields.
// Use JS to do this in case the user doesn't have JS
// enabled.
hidden.hide();
// Setup an event listener for when the state of the
// checkbox changes.
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.
if (checkbox.is(':checked')) {
// Show the hidden fields.
hidden.show();
} else {
// Make sure that the hidden fields are indeed
// hidden.
hidden.hide();
// You may also want to clear the value of the
// hidden fields here. Just in case somebody
// shows the fields, enters data to them and then
// unticks the checkbox.
//
// This would do the job:
//
// $("#hidden_field").val("");
}
});
});
</script>
<script type="text/javascript" src="/static/js/bokeh-0.12.3.min.js"></script>
<script type="text/javascript" src="/static/js/bokeh-widgets-0.12.3.min.js"></script>
<script async="true" type="text/javascript">

View File

@@ -6,14 +6,58 @@
{% block content %}
<script type="text/javascript" src="/static/js/bokeh-0.12.3.min.js"></script>
<script async="true" type="text/javascript">
Bokeh.set_log_level("info");
</script>
<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
$(function() {
// Get the form fields and hidden div
var checkbox = $("#id_water");
var hidden = $("#id_waterboattype");
{{ plotscript |safe }}
// Hide the fields.
// Use JS to do this in case the user doesn't have JS
// enabled.
<script>
hidden.hide();
// Setup an event listener for when the state of the
// checkbox changes.
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.
if (checkbox.is(':checked')) {
// Show the hidden fields.
hidden.show();
} else {
// Make sure that the hidden fields are indeed
// hidden.
hidden.hide();
// You may also want to clear the value of the
// hidden fields here. Just in case somebody
// shows the fields, enters data to them and then
// unticks the checkbox.
//
// This would do the job:
//
// $("#hidden_field").val("");
}
});
});
</script>
<script type="text/javascript" src="/static/js/bokeh-0.12.3.min.js"></script>
<script async="true" type="text/javascript">
Bokeh.set_log_level("info");
</script>
{{ plotscript |safe }}
<script>
// Set things up to resize the plot on a window resize. You can play with
// the arguments of resize_width_height() to change the plot's behavior.
var plot_resize_setup = function () {

View File

@@ -2097,7 +2097,8 @@ def cum_flex(request,theuser=0,
enddatestring="",
options={
'includereststrokes':False,
'workouttypes':['rower','dynamic','slides']
'workouttypes':['rower','dynamic','slides'],
'waterboattype':['1x','2x','2-','4x','4-','8+']
}):
if 'options' in request.session:
@@ -2108,6 +2109,7 @@ def cum_flex(request,theuser=0,
workstrokesonly = not includereststrokes
checktypes = ['water','rower','dynamic','slides','skierg',
'paddle','snow','coastal','other']
waterboattype = ['1x','2x','2-','4x','4-','8+']
if deltadays>0:
startdate = enddate-datetime.timedelta(days=int(deltadays))
@@ -2174,6 +2176,7 @@ def cum_flex(request,theuser=0,
if optionsform.is_valid():
includereststrokes = optionsform.cleaned_data['includereststrokes']
workstrokesonly = not includereststrokes
waterboattype = optionsform.cleaned_data['waterboattype']
workouttypes = []
for type in checktypes:
if optionsform.cleaned_data[type]:
@@ -2182,6 +2185,7 @@ def cum_flex(request,theuser=0,
options = {
'includereststrokes':includereststrokes,
'workouttypes':workouttypes,
'waterboattype':waterboattype,
}
form = DateRangeForm(initial={
'startdate': startdate,
@@ -2205,6 +2209,7 @@ def cum_flex(request,theuser=0,
r2 = getrower(theuser)
allworkouts = Workout.objects.filter(user=r2,
workouttype__in=workouttypes,
boattype__in=waterboattype,
startdatetime__gte=startdate,
startdatetime__lte=enddate)
@@ -2242,6 +2247,8 @@ def cum_flex(request,theuser=0,
initial = {}
initial['includereststrokes'] = includereststrokes
initial['waterboattype'] = waterboattype
for wtype in checktypes:
if wtype in workouttypes:
initial[wtype] = True
@@ -4934,7 +4941,8 @@ def cumstats(request,theuser=0,
plotfield='spm',
options={
'includereststrokes':False,
'workouttypes':['rower','dynamic','slides']
'workouttypes':['rower','dynamic','slides'],
'waterboattype':['1x','2x','2-','4x','4-','8+']
}):
if 'options' in request.session:
@@ -4945,6 +4953,7 @@ def cumstats(request,theuser=0,
workstrokesonly = not includereststrokes
checktypes = ['water','rower','dynamic','slides','skierg',
'paddle','snow','other','coastal']
waterboattype = ['1x','2x','2-','4x','4-','8+']
if deltadays>0:
startdate = enddate-datetime.timedelta(days=int(deltadays))
@@ -5011,6 +5020,7 @@ def cumstats(request,theuser=0,
includereststrokes = optionsform.cleaned_data['includereststrokes']
workstrokesonly = not includereststrokes
workouttypes = []
waterboattype = optionsform.cleaned_data['waterboattype']
for type in checktypes:
if optionsform.cleaned_data[type]:
workouttypes.append(type)
@@ -5018,6 +5028,7 @@ def cumstats(request,theuser=0,
options = {
'includereststrokes':includereststrokes,
'workouttypes':workouttypes,
'waterboattype':waterboattype,
}
form = DateRangeForm()
deltaform = DeltaDaysForm()
@@ -5036,6 +5047,7 @@ def cumstats(request,theuser=0,
r2 = getrower(theuser)
allergworkouts = Workout.objects.filter(user=r2,
workouttype__in=workouttypes,
boattype__in=waterboattype,
startdatetime__gte=startdate,
startdatetime__lte=enddate)
@@ -5137,6 +5149,7 @@ def cumstats(request,theuser=0,
# set options form correctly
initial = {}
initial['includereststrokes'] = includereststrokes
initial['waterboattype'] = waterboattype
for wtype in checktypes:
if wtype in workouttypes: