delayed load of data on cum_flex
Ajax call to load data for cumulative flex chart. It works. Yay!
This commit is contained in:
@@ -6,8 +6,23 @@
|
|||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
{{ js_res | safe }}
|
|
||||||
{{ css_res| 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 async="true" type="text/javascript">
|
||||||
|
Bokeh.set_log_level("info");
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
<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>
|
||||||
@@ -58,13 +73,10 @@
|
|||||||
|
|
||||||
</script>
|
</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">
|
|
||||||
Bokeh.set_log_level("info");
|
|
||||||
</script>
|
|
||||||
|
|
||||||
{{ interactiveplot |safe }}
|
<div id="id_script">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
/* Need this to get the page in "desktop mode"; not having an infinite height.*/
|
/* Need this to get the page in "desktop mode"; not having an infinite height.*/
|
||||||
@@ -74,11 +86,7 @@
|
|||||||
|
|
||||||
<div id="title" class="grid_12 alpha">
|
<div id="title" class="grid_12 alpha">
|
||||||
<div class="grid_10 alpha">
|
<div class="grid_10 alpha">
|
||||||
{% if theuser %}
|
|
||||||
<h3>{{ theuser.first_name }}'s Stroke Analysis</h3>
|
|
||||||
{% else %}
|
|
||||||
<h3>{{ user.first_name }}'s Stroke Analysis</h3>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
</div>
|
||||||
<div class="grid_2 omega">
|
<div class="grid_2 omega">
|
||||||
{% if user.is_authenticated and user|is_manager %}
|
{% if user.is_authenticated and user|is_manager %}
|
||||||
@@ -99,7 +107,6 @@
|
|||||||
|
|
||||||
<div class="grid_12 alpha">
|
<div class="grid_12 alpha">
|
||||||
<div id="form" class="grid_6 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">
|
<form enctype="multipart/form-data" action="{{ formloc }}" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<div class="grid_2 alpha">
|
<div class="grid_2 alpha">
|
||||||
@@ -229,10 +236,33 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div id="graph" class="grid_12 alpha">
|
<div id="id_chart" class="grid_12 alpha">
|
||||||
|
|
||||||
{{ the_div|safe }}
|
{{ the_div|safe }}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% 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/flexalldata', function(json) {
|
||||||
|
var counter=0;
|
||||||
|
var script = json.script;
|
||||||
|
var div = json.div;
|
||||||
|
$("#id_sitready").remove();
|
||||||
|
$("#id_chart").append(div);
|
||||||
|
console.log(div);
|
||||||
|
$("#id_script").append("<script>"+script+"</s"+"cript>");
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
|
|||||||
@@ -169,8 +169,14 @@ urlpatterns = [
|
|||||||
url(r'^flexall/(?P<xparam>\w+.*)/(?P<yparam1>\w+.*)/(?P<yparam2>\w+.*)$',views.cum_flex),
|
url(r'^flexall/(?P<xparam>\w+.*)/(?P<yparam1>\w+.*)/(?P<yparam2>\w+.*)$',views.cum_flex),
|
||||||
url(r'^flexall/$',views.cum_flex),
|
url(r'^flexall/$',views.cum_flex),
|
||||||
|
|
||||||
|
url(r'^(?P<theuser>\d+)/flexalldata/(?P<xparam>\w+.*)/(?P<yparam1>\w+.*)/(?P<yparam2>\w+.*)/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)$',views.cum_flex_data),
|
||||||
|
url(r'^flexalldata/(?P<xparam>\w+.*)/(?P<yparam1>\w+.*)/(?P<yparam2>\w+.*)/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)$',views.cum_flex_data),
|
||||||
|
url(r'^flexalldata/(?P<xparam>\w+.*)/(?P<yparam1>\w+.*)/(?P<yparam2>\w+.*)$',views.cum_flex_data),
|
||||||
|
url(r'^flexalldata/$',views.cum_flex_data),
|
||||||
|
|
||||||
url(r'^histo/u/(?P<theuser>\d+)$',views.histo),
|
url(r'^histo/u/(?P<theuser>\d+)$',views.histo),
|
||||||
url(r'^flexall/u/(?P<theuser>\d+)$',views.cum_flex),
|
url(r'^flexall/u/(?P<theuser>\d+)$',views.cum_flex),
|
||||||
|
url(r'^flexalldata/u/(?P<theuser>\d+)$',views.cum_flex_data),
|
||||||
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'^(?P<theuser>\d+)/histo/(?P<deltadays>\d+)$',views.histo),
|
||||||
url(r'^histo/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)$',views.histo),
|
url(r'^histo/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)$',views.histo),
|
||||||
|
|||||||
144
rowers/views.py
144
rowers/views.py
@@ -2526,6 +2526,94 @@ def histo_all(request,theuser=0,
|
|||||||
})
|
})
|
||||||
|
|
||||||
# The Flex plot for a large selection of workouts
|
# The Flex plot for a large selection of workouts
|
||||||
|
@login_required()
|
||||||
|
def cum_flex_data(
|
||||||
|
request,
|
||||||
|
options={
|
||||||
|
'includereststrokes':False,
|
||||||
|
'workouttypes':['rower','dynamic','slides'],
|
||||||
|
'waterboattype':['1x','2x','2-','4x','4-','8+'],
|
||||||
|
'theuser':0,
|
||||||
|
'xparam':'spm',
|
||||||
|
'yparam1':'power',
|
||||||
|
'yparam2':'None',
|
||||||
|
'enddatestring':'',
|
||||||
|
'startdatestring':'',
|
||||||
|
'deltadays':-1,
|
||||||
|
}):
|
||||||
|
|
||||||
|
if 'options' in request.session:
|
||||||
|
options = request.session['options']
|
||||||
|
|
||||||
|
workouttypes = options['workouttypes']
|
||||||
|
includereststrokes = options['includereststrokes']
|
||||||
|
waterboattype = options['waterboattype']
|
||||||
|
workstrokesonly = not includereststrokes
|
||||||
|
theuser = options['theuser']
|
||||||
|
xparam = options['xparam']
|
||||||
|
yparam1 = options['yparam1']
|
||||||
|
yparam2 = options['yparam2']
|
||||||
|
startdatestring = options['startdatestring']
|
||||||
|
enddatestring = options['enddatestring']
|
||||||
|
deltadays = options['deltadays']
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
startdate = iso8601.parse_date(startdatestring)
|
||||||
|
|
||||||
|
enddate = iso8601.parse_date(enddatestring)
|
||||||
|
|
||||||
|
if deltadays>0:
|
||||||
|
startdate = enddate-datetime.timedelta(days=int(deltadays))
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
||||||
|
allworkouts = Workout.objects.filter(user=r2,
|
||||||
|
workouttype__in=workouttypes,
|
||||||
|
boattype__in=waterboattype,
|
||||||
|
startdatetime__gte=startdate,
|
||||||
|
startdatetime__lte=enddate)
|
||||||
|
|
||||||
|
if allworkouts:
|
||||||
|
res = interactive_cum_flex_chart2(allworkouts,xparam=xparam,
|
||||||
|
yparam1=yparam1,
|
||||||
|
yparam2=yparam2,
|
||||||
|
promember=promember,
|
||||||
|
workstrokesonly=workstrokesonly)
|
||||||
|
script = res[0]
|
||||||
|
div = res[1]
|
||||||
|
else:
|
||||||
|
script = ''
|
||||||
|
div = '<p>No erg pieces uploaded for this date range.</p>'
|
||||||
|
|
||||||
|
scripta = script.split('\n')[2:-1]
|
||||||
|
script = ''.join(scripta)
|
||||||
|
|
||||||
|
data = {
|
||||||
|
"script":script,
|
||||||
|
"div":div,
|
||||||
|
}
|
||||||
|
|
||||||
|
return JSONResponse(data)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@login_required()
|
@login_required()
|
||||||
def cum_flex(request,theuser=0,
|
def cum_flex(request,theuser=0,
|
||||||
xparam='spm',
|
xparam='spm',
|
||||||
@@ -2651,36 +2739,17 @@ def cum_flex(request,theuser=0,
|
|||||||
})
|
})
|
||||||
deltaform = DeltaDaysForm()
|
deltaform = DeltaDaysForm()
|
||||||
optionsform = StatsOptionsForm()
|
optionsform = StatsOptionsForm()
|
||||||
try:
|
|
||||||
r2 = getrower(theuser)
|
|
||||||
allworkouts = Workout.objects.filter(user=r2,
|
|
||||||
workouttype__in=workouttypes,
|
|
||||||
boattype__in=waterboattype,
|
|
||||||
startdatetime__gte=startdate,
|
|
||||||
startdatetime__lte=enddate)
|
|
||||||
|
|
||||||
except Rower.DoesNotExist:
|
|
||||||
allworkouts = []
|
|
||||||
r2=0
|
|
||||||
|
|
||||||
try:
|
|
||||||
u = User.objects.get(id=theuser)
|
|
||||||
except User.DoesNotExist:
|
|
||||||
u = ''
|
|
||||||
|
|
||||||
if allworkouts:
|
|
||||||
res = interactive_cum_flex_chart2(allworkouts,xparam=xparam,
|
|
||||||
yparam1=yparam1,
|
|
||||||
yparam2=yparam2,
|
|
||||||
promember=promember,
|
|
||||||
workstrokesonly=workstrokesonly)
|
|
||||||
script = res[0]
|
|
||||||
div = res[1]
|
|
||||||
js_resources = res[2]
|
|
||||||
css_resources = res[3]
|
|
||||||
else:
|
|
||||||
script = ''
|
script = ''
|
||||||
div = '<p>No erg pieces uploaded for this date range.</p>'
|
div = """
|
||||||
|
<div id="id_sitready">
|
||||||
|
<p>
|
||||||
|
<blockquote>
|
||||||
|
Sit Ready! We're counting strokes and loading data
|
||||||
|
</blockquote>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
"""
|
||||||
js_resources = ''
|
js_resources = ''
|
||||||
css_resources = ''
|
css_resources = ''
|
||||||
|
|
||||||
@@ -2702,8 +2771,26 @@ def cum_flex(request,theuser=0,
|
|||||||
initial[wtype] = False
|
initial[wtype] = False
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
u = User.objects.get(id=theuser)
|
||||||
|
except User.DoesNotExist:
|
||||||
|
u = ''
|
||||||
|
|
||||||
optionsform = StatsOptionsForm(initial=initial)
|
optionsform = StatsOptionsForm(initial=initial)
|
||||||
|
|
||||||
|
|
||||||
|
options['includereststrokes'] = includereststrokes
|
||||||
|
options['workouttypes'] =workouttypes
|
||||||
|
options['waterboattype'] =waterboattype
|
||||||
|
options['theuser'] =theuser
|
||||||
|
options['xparam'] =xparam
|
||||||
|
options['yparam1'] =yparam1
|
||||||
|
options['yparam2'] =yparam2
|
||||||
|
options['startdatestring'] = startdatestring
|
||||||
|
options['enddatestring'] =enddatestring
|
||||||
|
options['deltadays'] =deltadays
|
||||||
|
|
||||||
|
|
||||||
request.session['options'] = options
|
request.session['options'] = options
|
||||||
|
|
||||||
return render(request, 'cum_flex.html',
|
return render(request, 'cum_flex.html',
|
||||||
@@ -2728,6 +2815,7 @@ def cum_flex(request,theuser=0,
|
|||||||
'noylist':noylist,
|
'noylist':noylist,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
# Show the EMpower Oarlock generated Stroke Profile
|
# Show the EMpower Oarlock generated Stroke Profile
|
||||||
@user_passes_test(ispromember,login_url="/",redirect_field_name=None)
|
@user_passes_test(ispromember,login_url="/",redirect_field_name=None)
|
||||||
def workout_forcecurve_view(request,id=0,workstrokesonly=False):
|
def workout_forcecurve_view(request,id=0,workstrokesonly=False):
|
||||||
|
|||||||
Reference in New Issue
Block a user