histo_all
This commit is contained in:
@@ -15,30 +15,6 @@ from django.forms import formset_factory
|
|||||||
from utils import landingpages
|
from utils import landingpages
|
||||||
from metrics import axes
|
from metrics import axes
|
||||||
|
|
||||||
class SelectWidget(Select):
|
|
||||||
"""
|
|
||||||
Subclass of Django's select widget that allows disabling options.
|
|
||||||
"""
|
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
self._disabled_choices = []
|
|
||||||
super(SelectWidget, self).__init__(*args, **kwargs)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def disabled_choices(self):
|
|
||||||
return self._disabled_choices
|
|
||||||
|
|
||||||
@disabled_choices.setter
|
|
||||||
def disabled_choices(self, other):
|
|
||||||
self._disabled_choices = other
|
|
||||||
|
|
||||||
def create_option(self, name, value, label, selected, index, subindex=None, attrs=None):
|
|
||||||
option_dict = super(SelectWidget, self).create_option(
|
|
||||||
name, value, label, selected, index, subindex=subindex, attrs=attrs
|
|
||||||
)
|
|
||||||
if value in self.disabled_choices:
|
|
||||||
option_dict['attrs']['disabled'] = 'disabled'
|
|
||||||
|
|
||||||
return option_dict
|
|
||||||
|
|
||||||
# login form
|
# login form
|
||||||
class LoginForm(forms.Form):
|
class LoginForm(forms.Form):
|
||||||
@@ -963,11 +939,11 @@ class FlexAxesForm(forms.Form):
|
|||||||
|
|
||||||
|
|
||||||
xaxis = forms.ChoiceField(
|
xaxis = forms.ChoiceField(
|
||||||
choices=axchoices,label='X-Axis',widget=SelectWidget,required=True)
|
choices=axchoices,label='X-Axis',required=True)
|
||||||
yaxis1 = forms.ChoiceField(
|
yaxis1 = forms.ChoiceField(
|
||||||
choices=yaxchoices,label='Left Axis',widget=SelectWidget,required=True)
|
choices=yaxchoices,label='Left Axis',required=True)
|
||||||
yaxis2 = forms.ChoiceField(
|
yaxis2 = forms.ChoiceField(
|
||||||
choices=yaxchoices2,label='Right Axis',widget=SelectWidget,required=True)
|
choices=yaxchoices2,label='Right Axis',required=True)
|
||||||
|
|
||||||
def __init__(self,request,*args,**kwargs):
|
def __init__(self,request,*args,**kwargs):
|
||||||
super(FlexAxesForm, self).__init__(*args, **kwargs)
|
super(FlexAxesForm, self).__init__(*args, **kwargs)
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
{% extends "base.html" %}
|
{% extends "newbase.html" %}
|
||||||
{% load staticfiles %}
|
{% load staticfiles %}
|
||||||
{% load rowerfilters %}
|
{% load rowerfilters %}
|
||||||
|
|
||||||
{% block title %}Rowsandall Histogram {% endblock %}
|
{% block title %}Rowsandall {% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block main %}
|
||||||
<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
|
<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
|
||||||
<script>
|
<script>
|
||||||
$(function() {
|
$(function() {
|
||||||
|
|
||||||
// Get the form fields and hidden div
|
// Get the form fields and hidden div
|
||||||
var checkbox = $("#id_water");
|
var modality = $("#id_modality");
|
||||||
var hidden = $("#id_waterboattype");
|
var hidden = $("#id_waterboattype");
|
||||||
|
|
||||||
|
|
||||||
@@ -19,15 +19,20 @@
|
|||||||
// enabled.
|
// enabled.
|
||||||
|
|
||||||
hidden.hide();
|
hidden.hide();
|
||||||
|
|
||||||
|
if (modality.val() == 'water') {
|
||||||
|
hidden.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Setup an event listener for when the state of the
|
// Setup an event listener for when the state of the
|
||||||
// checkbox changes.
|
// checkbox changes.
|
||||||
checkbox.change(function() {
|
modality.change(function() {
|
||||||
// Check to see if the checkbox is checked.
|
// Check to see if the checkbox is checked.
|
||||||
// If it is, show the fields and populate the input.
|
// If it is, show the fields and populate the input.
|
||||||
// If not, hide the fields.
|
// If not, hide the fields.
|
||||||
if (checkbox.is(':checked')) {
|
var Value = modality.val();
|
||||||
|
if (Value=='water') {
|
||||||
// Show the hidden fields.
|
// Show the hidden fields.
|
||||||
hidden.show();
|
hidden.show();
|
||||||
} else {
|
} else {
|
||||||
@@ -45,117 +50,98 @@
|
|||||||
// $("#hidden_field").val("");
|
// $("#hidden_field").val("");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</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>
|
|
||||||
|
|
||||||
{{ interactiveplot |safe }}
|
<div id="id_css_res">
|
||||||
|
<link rel="stylesheet" href="/static/css/bokeh-0.12.3.min.css" type="text/css" />
|
||||||
|
<link rel="stylesheet" href="/static/css/bokeh-widgets-0.12.3.min.css" type="text/css" />
|
||||||
|
</div>
|
||||||
|
<div id="id_js_res">
|
||||||
|
<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>
|
</div>
|
||||||
// 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.
|
<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
|
||||||
var plot_resize_setup = function () {
|
|
||||||
var plotid = Object.keys(Bokeh.index)[0]; // assume we have just one plot
|
|
||||||
var plot = Bokeh.index[plotid];
|
|
||||||
var plotresizer = function() {
|
|
||||||
// arguments: use width, use height, maintain aspect ratio
|
|
||||||
plot.resize_width_height(true, false, false);
|
|
||||||
};
|
|
||||||
window.addEventListener('resize', plotresizer);
|
|
||||||
plotresizer();
|
|
||||||
};
|
|
||||||
window.addEventListener('load', plot_resize_setup);
|
|
||||||
</script>
|
|
||||||
<style>
|
|
||||||
/* Need this to get the page in "desktop mode"; not having an infinite height.*/
|
|
||||||
html, body {height: 100%; margin:5px;}
|
|
||||||
</style>
|
|
||||||
|
|
||||||
|
|
||||||
<div id="title" class="grid_12 alpha">
|
<div id="id_script">
|
||||||
<div class="grid_10 alpha">
|
|
||||||
{% if theuser %}
|
</div>
|
||||||
<h3>{{ theuser.first_name }}'s Stroke Analysis</h3>
|
|
||||||
{% else %}
|
<ul class="main-content">
|
||||||
<h3>{{ user.first_name }}'s Stroke Analysis</h3>
|
|
||||||
{% endif %}
|
<li class="grid_4">
|
||||||
</div>
|
|
||||||
<div class="grid_2 omega">
|
|
||||||
{% if user.is_authenticated and user|is_manager %}
|
|
||||||
<div class="grid_2 alpha dropdown">
|
|
||||||
<button class="grid_2 alpha button green small dropbtn">
|
|
||||||
{{ theuser.first_name }} {{ theuser.last_name }}
|
|
||||||
</button>
|
|
||||||
<div class="dropdown-content">
|
|
||||||
{% for member in user|team_members %}
|
|
||||||
<a class="button green small" href="/rowers/{{ member.id }}/flexall/{{ xparam }}/{{ yparam1 }}/{{ yparam2 }}/{{ startdate|date:"Y-m-d" }}/{{ enddate|date:"Y-m-d" }}">{{ member.first_name }} {{ member.last_name }}</a>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
{% else %}
|
|
||||||
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="grid_12 alpha">
|
|
||||||
<div id="form" class="grid_6 alpha">
|
|
||||||
<p>Warning: Large date ranges may take a long time to load. Huge date ranges may crash your browser.</p>
|
|
||||||
<form enctype="multipart/form-data" action="{{ formloc }}" method="post">
|
|
||||||
{% csrf_token %}
|
|
||||||
<div class="grid_2 alpha">
|
|
||||||
<table>
|
|
||||||
{{ optionsform.as_table }}
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
<div class="grid_2 suffix_2 omega">
|
|
||||||
<input type="hidden" name="options" value="options">
|
|
||||||
<input class="grid_1 alpha button green small" value="Submit" type="Submit">
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
<div class="grid_6 omega">
|
|
||||||
<p>Use this form to select a different date range:</p>
|
|
||||||
<p>
|
|
||||||
Select start and end date for a date range:
|
|
||||||
<div class="grid_4 alpha">
|
|
||||||
|
|
||||||
<form enctype="multipart/form-data" action="" method="post">
|
|
||||||
|
|
||||||
<table>
|
|
||||||
{{ form.as_table }}
|
|
||||||
</table>
|
|
||||||
{% csrf_token %}
|
|
||||||
</div>
|
|
||||||
<div class="grid_2 omega">
|
|
||||||
<input name='daterange' class="button green" type="submit" value="Submit"> </form>
|
|
||||||
</div>
|
|
||||||
<div class="grid_4 alpha">
|
|
||||||
<form enctype="multipart/form-data" action="" method="post">
|
|
||||||
Or use the last {{ deltaform }} days.
|
|
||||||
</div>
|
|
||||||
<div class="grid_2 omega">
|
|
||||||
{% csrf_token %}
|
|
||||||
<input name='datedelta' class="button green" type="submit" value="Submit">
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="summary" class="grid_6 suffix_6 alpha">
|
|
||||||
|
|
||||||
<p>Summary for {{ theuser.first_name }} {{ theuser.last_name }}
|
<p>Summary for {{ theuser.first_name }} {{ theuser.last_name }}
|
||||||
between {{ startdate|date }} and {{ enddate|date }}</p>
|
between {{ startdate|date }} and {{ enddate|date }}</p>
|
||||||
</div>
|
</li>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="graph" class="grid_12 alpha">
|
<li class="grid_4">
|
||||||
|
<div id="id_chart">
|
||||||
{{ the_div|safe }}
|
|
||||||
|
{{ the_div|safe }}
|
||||||
</div>
|
</div>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<form enctype="multipart/form-data" action="{{ formloc }}" method="post">
|
||||||
|
<table>
|
||||||
|
{{ optionsform.as_table }}
|
||||||
|
</table>
|
||||||
|
<input type="hidden" name="options" value="options">
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<table>
|
||||||
|
{{ form.as_table }}
|
||||||
|
</table>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
{% csrf_token %}
|
||||||
|
<input class="button green small" value="Submit" type="Submit">
|
||||||
|
</form>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block scripts %}
|
||||||
|
<script type='text/javascript'
|
||||||
|
src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js'>
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
$(function($) {
|
||||||
|
console.log('loading script');
|
||||||
|
$.getJSON(window.location.protocol + '//'+window.location.host + '/rowers/histodata', function(json) {
|
||||||
|
console.log('got script');
|
||||||
|
var counter=0;
|
||||||
|
var script = json.script;
|
||||||
|
var div = json.div;
|
||||||
|
console.log('set vars');
|
||||||
|
$("#id_sitready").remove();
|
||||||
|
console.log('sitready removed');
|
||||||
|
$("#id_chart").append(div);
|
||||||
|
console.log('div appended');
|
||||||
|
$("#id_script").append("<script>"+script+"</s"+"cript>");
|
||||||
|
console.log('script changed');
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block sidebar %}
|
||||||
|
{% include 'menu_analytics.html' %}
|
||||||
|
{% endblock %}
|
||||||
|
|||||||
@@ -214,13 +214,9 @@ urlpatterns = [
|
|||||||
url(r'^flexall/user/(?P<theuser>\d+)/$',views.cum_flex),
|
url(r'^flexall/user/(?P<theuser>\d+)/$',views.cum_flex),
|
||||||
url(r'^flexall/$',views.cum_flex),
|
url(r'^flexall/$',views.cum_flex),
|
||||||
url(r'^flexalldata/$',views.cum_flex_data),
|
url(r'^flexalldata/$',views.cum_flex_data),
|
||||||
|
url(r'^histo/user/(?P<theuser>\d+)$',views.histo),
|
||||||
url(r'^histo/u/(?P<theuser>\d+)$',views.histo),
|
url(r'^histodata$',views.histo_data),
|
||||||
url(r'^flexall/u/(?P<theuser>\d+)$',views.cum_flex),
|
|
||||||
url(r'^(?P<theuser>\d+)/histo/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)$',views.histo),
|
url(r'^(?P<theuser>\d+)/histo/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)$',views.histo),
|
||||||
url(r'^(?P<theuser>\d+)/histo/(?P<deltadays>\d+)$',views.histo),
|
|
||||||
url(r'^histo/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)$',views.histo),
|
|
||||||
url(r'^histo/(?P<deltadays>\d+)$',views.histo),
|
|
||||||
url(r'^histo/$',views.histo),
|
url(r'^histo/$',views.histo),
|
||||||
url(r'^cumstats/u/(?P<theuser>\d+)$',views.cumstats),
|
url(r'^cumstats/u/(?P<theuser>\d+)$',views.cumstats),
|
||||||
url(r'^cumstats/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)/p/(?P<plotfield>\w+.*)$',views.cumstats),
|
url(r'^cumstats/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)/p/(?P<plotfield>\w+.*)$',views.cumstats),
|
||||||
|
|||||||
314
rowers/views.py
314
rowers/views.py
@@ -2558,6 +2558,99 @@ def cum_flex_data(
|
|||||||
|
|
||||||
return JSONResponse(data)
|
return JSONResponse(data)
|
||||||
|
|
||||||
|
# The Flex plot for a large selection of workouts
|
||||||
|
@login_required()
|
||||||
|
def histo_data(
|
||||||
|
request,
|
||||||
|
options={
|
||||||
|
'includereststrokes':False,
|
||||||
|
'rankingonly':False,
|
||||||
|
'modality':'all',
|
||||||
|
'waterboattype':types.waterboattype,
|
||||||
|
'theuser':0,
|
||||||
|
'enddatestring':'',
|
||||||
|
'startdatestring':'',
|
||||||
|
'deltadays':-1,
|
||||||
|
}):
|
||||||
|
|
||||||
|
def_options = options
|
||||||
|
|
||||||
|
|
||||||
|
if 'options' in request.session:
|
||||||
|
options = request.session['options']
|
||||||
|
|
||||||
|
modality = keyvalue_get_default('modality',options,def_options)
|
||||||
|
rankingonly = keyvalue_get_default('rankingonly',options,def_options)
|
||||||
|
includereststrokes = keyvalue_get_default('includereststrokes',options,def_options)
|
||||||
|
waterboattype = keyvalue_get_default('waterboattype',options,def_options)
|
||||||
|
workstrokesonly = not includereststrokes
|
||||||
|
theuser = keyvalue_get_default('theuser',options,def_options)
|
||||||
|
startdatestring = keyvalue_get_default('startdatestring',options,def_options)
|
||||||
|
enddatestring = keyvalue_get_default('enddatestring',options,def_options)
|
||||||
|
|
||||||
|
if modality == 'all':
|
||||||
|
modalities = [m[0] for m in types.workouttypes]
|
||||||
|
else:
|
||||||
|
modalities = [modality]
|
||||||
|
|
||||||
|
try:
|
||||||
|
startdate = iso8601.parse_date(startdatestring)
|
||||||
|
except ParseError:
|
||||||
|
startdate = timezone.now()-datetime.timedelta(days=7)
|
||||||
|
|
||||||
|
try:
|
||||||
|
enddate = iso8601.parse_date(enddatestring)
|
||||||
|
except ParseError:
|
||||||
|
enddate = timezone.now()
|
||||||
|
|
||||||
|
|
||||||
|
if enddate < startdate:
|
||||||
|
s = enddate
|
||||||
|
enddate = startdate
|
||||||
|
startdate = s
|
||||||
|
|
||||||
|
promember=0
|
||||||
|
if theuser == 0:
|
||||||
|
theuser = request.user.id
|
||||||
|
|
||||||
|
if not request.user.is_anonymous():
|
||||||
|
r = getrower(request.user)
|
||||||
|
result = request.user.is_authenticated() and ispromember(request.user)
|
||||||
|
if result:
|
||||||
|
promember=1
|
||||||
|
|
||||||
|
r2 = getrower(theuser)
|
||||||
|
|
||||||
|
if rankingonly:
|
||||||
|
rankingpiece = [True,]
|
||||||
|
else:
|
||||||
|
rankingpiece = [True,False]
|
||||||
|
|
||||||
|
allworkouts = Workout.objects.filter(user=r2,
|
||||||
|
workouttype__in=modalities,
|
||||||
|
boattype__in=waterboattype,
|
||||||
|
startdatetime__gte=startdate,
|
||||||
|
startdatetime__lte=enddate,
|
||||||
|
rankingpiece__in=rankingpiece)
|
||||||
|
|
||||||
|
if allworkouts:
|
||||||
|
res = interactive_histoall(allworkouts)
|
||||||
|
script = res[0]
|
||||||
|
div = res[1]
|
||||||
|
else:
|
||||||
|
script = ''
|
||||||
|
div = '<p>No pieces uploaded for this date range.</p>'
|
||||||
|
|
||||||
|
scripta = script.split('\n')[2:-1]
|
||||||
|
script = ''.join(scripta)
|
||||||
|
|
||||||
|
data = {
|
||||||
|
"script":script,
|
||||||
|
"div":div,
|
||||||
|
}
|
||||||
|
|
||||||
|
return JSONResponse(data)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -2893,29 +2986,50 @@ def histo(request,theuser=0,
|
|||||||
options={
|
options={
|
||||||
'includereststrokes':False,
|
'includereststrokes':False,
|
||||||
'workouttypes':[i[0] for i in types.workouttypes],
|
'workouttypes':[i[0] for i in types.workouttypes],
|
||||||
'waterboattype':types.waterboattype
|
'waterboattype':types.waterboattype,
|
||||||
|
'rankingonly': False,
|
||||||
}):
|
}):
|
||||||
|
|
||||||
if 'options' in request.session:
|
r = getrequestrower(request,userid=theuser)
|
||||||
options = request.session['options']
|
theuser = r.user
|
||||||
|
|
||||||
|
if 'waterboattype' in request.session:
|
||||||
|
waterboattype = request.session['waterboattype']
|
||||||
|
else:
|
||||||
|
waterboattype = types.waterboattype
|
||||||
|
|
||||||
|
|
||||||
|
if 'rankingonly' in request.session:
|
||||||
|
rankingonly = request.session['rankingonly']
|
||||||
|
else:
|
||||||
|
rankingonly = False
|
||||||
|
|
||||||
|
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]
|
||||||
|
modality = 'all'
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
workouttypes = options['workouttypes']
|
rankingonly = options['rankingonly']
|
||||||
includereststrokes = options['includereststrokes']
|
|
||||||
waterboattype = options['waterboattype']
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
workouttypes = [i[0] for i in types.workouttypes]
|
rankingonly = False
|
||||||
waterboattype = types.waterboattype
|
|
||||||
includereststrokes = False
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
includereststrokes = options['includereststrokes']
|
||||||
|
except KeyError:
|
||||||
|
includereststrokes = False
|
||||||
|
|
||||||
|
|
||||||
workstrokesonly = not includereststrokes
|
workstrokesonly = not includereststrokes
|
||||||
|
|
||||||
|
waterboattype = types.waterboattype
|
||||||
|
|
||||||
# checktypes = ['water','rower','dynamic','slides','skierg',
|
|
||||||
# 'paddle','snow','coastal','other']
|
|
||||||
|
|
||||||
if deltadays>0:
|
|
||||||
startdate = enddate-datetime.timedelta(days=int(deltadays))
|
|
||||||
|
|
||||||
if startdatestring != "":
|
if startdatestring != "":
|
||||||
startdate = iso8601.parse_date(startdatestring)
|
startdate = iso8601.parse_date(startdatestring)
|
||||||
@@ -2928,27 +3042,13 @@ def histo(request,theuser=0,
|
|||||||
enddate = startdate
|
enddate = startdate
|
||||||
startdate = s
|
startdate = s
|
||||||
|
|
||||||
promember=0
|
|
||||||
r = getrequestrower(request,userid=theuser)
|
|
||||||
theuser = r.user.id
|
|
||||||
|
|
||||||
|
|
||||||
if not request.user.is_anonymous():
|
|
||||||
r = getrower(request.user)
|
|
||||||
result = request.user.is_authenticated() and ispromember(request.user)
|
|
||||||
if result:
|
|
||||||
promember=1
|
|
||||||
|
|
||||||
if not promember:
|
|
||||||
return HttpResponseRedirect("/rowers/promembership/")
|
|
||||||
|
|
||||||
# get all indoor rows of in date range
|
# get all indoor rows of in date range
|
||||||
|
|
||||||
# process form
|
# process form
|
||||||
if request.method == 'POST' and "daterange" in request.POST:
|
if request.method == 'POST':
|
||||||
form = DateRangeForm(request.POST)
|
form = DateRangeForm(request.POST)
|
||||||
deltaform = DeltaDaysForm(request.POST)
|
modalityform = TrendFlexModalForm(request.POST)
|
||||||
optionsform = StatsOptionsForm()
|
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
startdate = form.cleaned_data['startdate']
|
startdate = form.cleaned_data['startdate']
|
||||||
enddate = form.cleaned_data['enddate']
|
enddate = form.cleaned_data['enddate']
|
||||||
@@ -2956,118 +3056,90 @@ def histo(request,theuser=0,
|
|||||||
s = enddate
|
s = enddate
|
||||||
enddate = startdate
|
enddate = startdate
|
||||||
startdate = s
|
startdate = s
|
||||||
elif request.method == 'POST' and "datedelta" in request.POST:
|
if modalityform.is_valid():
|
||||||
deltaform = DeltaDaysForm(request.POST)
|
modality = modalityform.cleaned_data['modality']
|
||||||
optionsform = StatsOptionsForm()
|
waterboattype = modalityform.cleaned_data['waterboattype']
|
||||||
if deltaform.is_valid():
|
rankingonly = modalityform.cleaned_data['rankingonly']
|
||||||
deltadays = deltaform.cleaned_data['deltadays']
|
if modality == 'all':
|
||||||
if deltadays != 0 and deltadays != None:
|
modalities = [m[0] for m in types.workouttypes]
|
||||||
enddate = timezone.now()
|
|
||||||
startdate = enddate-datetime.timedelta(days=deltadays)
|
|
||||||
if startdate > enddate:
|
|
||||||
s = enddate
|
|
||||||
enddate = startdate
|
|
||||||
startdate = s
|
|
||||||
form = DateRangeForm(initial={
|
|
||||||
'startdate': startdate,
|
|
||||||
'enddate': enddate,
|
|
||||||
})
|
|
||||||
else:
|
else:
|
||||||
form = DateRangeForm()
|
modalities = [modality]
|
||||||
optionsform = StatsOptionsForm()
|
|
||||||
elif request.method == 'POST' and 'options' in request.POST:
|
|
||||||
optionsform = StatsOptionsForm(request.POST)
|
|
||||||
if optionsform.is_valid():
|
|
||||||
includereststrokes = optionsform.cleaned_data['includereststrokes']
|
|
||||||
workstrokesonly = not includereststrokes
|
|
||||||
waterboattype = optionsform.cleaned_data['waterboattype']
|
|
||||||
workouttypes = []
|
|
||||||
for type in types.checktypes:
|
|
||||||
if optionsform.cleaned_data[type]:
|
|
||||||
workouttypes.append(type)
|
|
||||||
|
|
||||||
|
|
||||||
options = {
|
|
||||||
'includereststrokes':includereststrokes,
|
|
||||||
'workouttypes':workouttypes,
|
|
||||||
'waterboattype':waterboattype,
|
|
||||||
}
|
|
||||||
request.session['options'] = options
|
|
||||||
form = DateRangeForm(initial={
|
|
||||||
'startdate': startdate,
|
|
||||||
'enddate': enddate,
|
|
||||||
})
|
|
||||||
deltaform = DeltaDaysForm()
|
|
||||||
else:
|
|
||||||
form = DateRangeForm(initial={
|
|
||||||
'startdate': startdate,
|
|
||||||
'enddate': enddate,
|
|
||||||
})
|
|
||||||
deltaform = DeltaDaysForm()
|
|
||||||
|
|
||||||
|
if modality != 'water':
|
||||||
|
waterboattype = [b[0] for b in types.boattypes]
|
||||||
|
|
||||||
|
|
||||||
|
request.session['modalities'] = modalities
|
||||||
|
request.session['waterboattype'] = waterboattype
|
||||||
|
request.session['rankingonly'] = rankingonly
|
||||||
|
form = DateRangeForm(initial={
|
||||||
|
'startdate': startdate,
|
||||||
|
'enddate': enddate,
|
||||||
|
})
|
||||||
else:
|
else:
|
||||||
form = DateRangeForm(initial={
|
form = DateRangeForm(initial={
|
||||||
'startdate': startdate,
|
'startdate': startdate,
|
||||||
'enddate': enddate,
|
'enddate': enddate,
|
||||||
})
|
})
|
||||||
deltaform = DeltaDaysForm()
|
includereststrokes = False
|
||||||
optionsform = StatsOptionsForm()
|
|
||||||
try:
|
|
||||||
r2 = getrower(theuser)
|
|
||||||
allergworkouts = Workout.objects.filter(user=r2,
|
|
||||||
workouttype__in=workouttypes,
|
|
||||||
boattype__in=waterboattype,
|
|
||||||
startdatetime__gte=startdate,
|
|
||||||
startdatetime__lte=enddate)
|
|
||||||
|
|
||||||
except Rower.DoesNotExist:
|
|
||||||
allergworkouts = []
|
|
||||||
r2=0
|
|
||||||
|
|
||||||
try:
|
workstrokesonly = not includereststrokes
|
||||||
u = User.objects.get(id=theuser)
|
modalityform = TrendFlexModalForm(
|
||||||
except User.DoesNotExist:
|
initial={
|
||||||
u = ''
|
'modality':modality,
|
||||||
|
'waterboattype':waterboattype,
|
||||||
|
'rankingonly':rankingonly,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
if allergworkouts:
|
negtypes = []
|
||||||
res = interactive_histoall(allergworkouts)
|
for b in types.boattypes:
|
||||||
script = res[0]
|
if b[0] not in waterboattype:
|
||||||
div = res[1]
|
negtypes.append(b[0])
|
||||||
else:
|
|
||||||
script = ''
|
|
||||||
typesstring = ', '.join('{}'.format(item) for i,item in enumerate(workouttypes))
|
|
||||||
if 'water' in workouttypes:
|
|
||||||
boatsstring = 'water ('+', '.join('{}'.format(item) for i,item in enumerate(waterboattype))+')'
|
|
||||||
typesstring = typesstring.replace('water',boatsstring)
|
|
||||||
div = '<p>No pieces found for '+typesstring+' for this date range.</p>'
|
|
||||||
|
|
||||||
# set options form correctly
|
|
||||||
initial = {}
|
|
||||||
initial['includereststrokes'] = includereststrokes
|
|
||||||
|
|
||||||
initial['waterboattype'] = waterboattype
|
|
||||||
|
|
||||||
for wtype in types.checktypes:
|
|
||||||
if wtype in workouttypes:
|
|
||||||
initial[wtype] = True
|
|
||||||
else:
|
|
||||||
initial[wtype] = False
|
|
||||||
|
|
||||||
|
|
||||||
optionsform = StatsOptionsForm(initial=initial)
|
|
||||||
|
script = ''
|
||||||
|
div = get_call()
|
||||||
|
js_resources = ''
|
||||||
|
css_resources = ''
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
options = {
|
||||||
|
'modality': modality,
|
||||||
|
'theuser': theuser.id,
|
||||||
|
'waterboattype':waterboattype,
|
||||||
|
'startdatestring':startdatestring,
|
||||||
|
'enddatestring':enddatestring,
|
||||||
|
'rankingonly':rankingonly,
|
||||||
|
'includereststrokes':includereststrokes,
|
||||||
|
}
|
||||||
|
|
||||||
|
request.session['options'] = options
|
||||||
|
|
||||||
|
promember=0
|
||||||
|
mayedit=0
|
||||||
|
if not request.user.is_anonymous():
|
||||||
|
result = request.user.is_authenticated() and ispromember(request.user)
|
||||||
|
if result:
|
||||||
|
promember = 1
|
||||||
|
|
||||||
|
|
||||||
request.session['options'] = options
|
request.session['options'] = options
|
||||||
|
|
||||||
return render(request, 'histo.html',
|
return render(request, 'histo.html',
|
||||||
{'interactiveplot':script,
|
{'interactiveplot':script,
|
||||||
'the_div':div,
|
'the_div':div,
|
||||||
'id':theuser,
|
'id':theuser,
|
||||||
'theuser':u,
|
'active':'nav-analysis',
|
||||||
|
'theuser':theuser,
|
||||||
|
'rower':r,
|
||||||
'startdate':startdate,
|
'startdate':startdate,
|
||||||
'enddate':enddate,
|
'enddate':enddate,
|
||||||
'form':form,
|
'form':form,
|
||||||
'optionsform':optionsform,
|
'optionsform':modalityform,
|
||||||
'deltaform':deltaform,
|
|
||||||
'teams':get_my_teams(request.user),
|
'teams':get_my_teams(request.user),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user