Private
Public Access
1
0

added box plot

This commit is contained in:
Sander Roosendaal
2017-08-10 14:10:39 +02:00
parent c74b08d966
commit 0de3bd333c
2 changed files with 130 additions and 17 deletions

View File

@@ -12,6 +12,55 @@
checkboxes[i].checked = source.checked;
}
}
</script>
<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
$(function() {
// Get the form fields and hidden div
var modality = $("#id_modality");
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.
modality.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') {
// 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>
@@ -45,23 +94,42 @@
</div>
</div>
<div class="grid_12 alpha">
<div class="grid_4 alpha">
<div class="grid_6 alpha">
{% if theuser %}
<form enctype="multipart/form-data" action="/rowers/user-boxplot-select/user/{{ theuser.id }}/" method="post">
{% else %}
<form enctype="multipart/form-data" action="/rowers/user-boxplot-select/" method="post">
{% endif %}
<table>
{{ dateform.as_table }}
</table>
{% csrf_token %}
{% else %}
<form enctype="multipart/form-data" action="/rowers/user-boxplot-select/" method="post">
{% endif %}
<div class="grid_4 alpha">
<table>
{{ dateform.as_table }}
</table>
{% csrf_token %}
</div>
<div class="grid_2 omega">
<input name='daterange' class="button green" type="submit" value="Submit">
</div>
</form>
{% if theuser %}
<form enctype="multipart/form-data" action="/rowers/user-boxplot-select/user/{{ theuser.id }}/" method="post">
{% else %}
<form enctype="multipart/form-data" action="/rowers/user-boxplot-select/" method="post">
{% endif %}
<div class="grid_4 alpha">
<table>
{{ modalityform.as_table }}
</table>
{% csrf_token %}
</div>
<div class="grid_2 omega">
<input name='modalityform' class="button green" type="submit" value="Submit">
</div>
</form>
</div>
<div class="grid_2">
<input name='daterange' class="button green" type="submit" value="Submit"> </form>
</div>
<div class="grid_5 prefix_1 omega">
<div class="grid_5 prefix_1 omega">
<form id="searchform" action=""
method="get" accept-charset="utf-8">
<div class="grid_3 prefix_1 alpha">

View File

@@ -3409,7 +3409,6 @@ def user_multiflex_select(request,
enddatestring = enddate.strftime('%Y-%m-%d')
request.session['startdate'] = startdatestring
request.session['enddate'] = enddatestring
print 'nootje',enddatestring,request.session['enddate']
else:
dateform = DateRangeForm(initial={
'startdate':startdate,
@@ -3809,17 +3808,53 @@ def user_boxplot_select(request,
enddate = iso8601.parse_date(request.session['enddate'])
if request.method == 'POST':
if 'waterboattype' in request.session:
waterboattype = request.session['waterboattype']
else:
waterboattype = ['1x','2x','2-','4x','4-','8+']
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]
if request.method == 'POST' and 'daterange' in request.POST:
dateform = DateRangeForm(request.POST)
if dateform.is_valid():
startdate = dateform.cleaned_data['startdate']
enddate = dateform.cleaned_data['enddate']
startdatestring = startdate.strftime('%Y-%m-%d')
enddatestring = enddate.strftime('%Y-%m-%d')
request.session['startdate'] = startdatestring
request.session['enddate'] = enddatestring
else:
dateform = DateRangeForm(initial={
'startdate':startdate,
'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 modality != 'water':
waterboattype = [b[0] for b in types.boattypes]
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))
enddate = enddate+datetime.timedelta(days=1)
@@ -3834,10 +3869,15 @@ def user_boxplot_select(request,
enddate = startdate
startdate = s
negtypes = []
for b in types.boattypes:
if b[0] not in waterboattype:
negtypes.append(b[0])
workouts = Workout.objects.filter(user=r,
startdatetime__gte=startdate,
startdatetime__lte=enddate).order_by("-date", "-starttime")
startdatetime__lte=enddate,
workouttype__in=modalities).order_by("-date", "-starttime").exclude(boattype__in=negtypes)
query = request.GET.get('q')
if query:
@@ -3853,6 +3893,10 @@ def user_boxplot_select(request,
form.fields["workouts"].queryset = workouts
chartform = BoxPlotChoiceForm()
modalityform = TrendFlexModalForm(initial={
'modality':modality,
'waterboattype':waterboattype
})
messages.info(request,successmessage)
messages.error(request,message)
@@ -3870,6 +3914,7 @@ def user_boxplot_select(request,
'theuser':user,
'form':form,
'chartform':chartform,
'modalityform':modalityform,
'teams':get_my_teams(request.user),
})