lazy loads trend flex, boxplot, cum_flex
This commit is contained in:
@@ -1 +0,0 @@
|
||||
E408191@CZ27LT9RCGN72.648792:1509824931
|
||||
@@ -11,7 +11,9 @@
|
||||
Bokeh.set_log_level("info");
|
||||
</script>
|
||||
|
||||
{{ interactiveplot |safe }}
|
||||
<div id="id_script">
|
||||
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Set things up to resize the plot on a window resize. You can play with
|
||||
@@ -37,7 +39,7 @@
|
||||
<div class="grid_12 alpha">
|
||||
<h1>Multi Flex Chart</h1>
|
||||
<div id="workouts" class="grid_8 alpha">
|
||||
<div id="theplot" class="grid_8 alpha flexplot">
|
||||
<div id="id_chart" class="grid_8 alpha flexplot">
|
||||
{{ the_div|safe }}
|
||||
</div>
|
||||
</div>
|
||||
@@ -67,4 +69,27 @@
|
||||
</div>
|
||||
|
||||
|
||||
{% 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/user-multiflex-data', 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,14 +169,10 @@ urlpatterns = [
|
||||
url(r'^flexall/(?P<xparam>\w+.*)/(?P<yparam1>\w+.*)/(?P<yparam2>\w+.*)$',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'^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<deltadays>\d+)$',views.histo),
|
||||
url(r'^histo/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)$',views.histo),
|
||||
@@ -300,6 +296,7 @@ urlpatterns = [
|
||||
url(r'^user-multiflex/(?P<userid>\d+)$',views.multiflex_view),
|
||||
url(r'^user-multiflex/$',views.multiflex_view),
|
||||
url(r'^user-multiflex$',views.multiflex_view),
|
||||
url(r'^user-multiflex-data$',views.multiflex_data),
|
||||
url(r'^me/teams/$',views.rower_teams_view),
|
||||
url(r'^me/calcdps/$',views.rower_calcdps_view),
|
||||
url(r'^me/exportsettings/$',views.rower_exportsettings_view),
|
||||
|
||||
@@ -57,6 +57,32 @@ defaultleft = [
|
||||
'panel_staticchart.html',
|
||||
]
|
||||
|
||||
coxes_calls = [
|
||||
'Sit Ready!',
|
||||
"Let's relax the shoulders, and give me a power ten to the finish!",
|
||||
"Almost there. Give me ten strokes on the legs!",
|
||||
"Let it run!",
|
||||
]
|
||||
|
||||
info_calls = [
|
||||
"Please give us a minute to count all those strokes, you've been working hard!",
|
||||
"Please give us a minute to count all your strokes."
|
||||
]
|
||||
|
||||
import random
|
||||
|
||||
def get_call():
|
||||
call1 = random.choice(coxes_calls)
|
||||
call2 = random.choice(info_calls)
|
||||
|
||||
call = """<div id="id_sitready" class="successmessage">
|
||||
<p>
|
||||
%s (%s)
|
||||
</p>
|
||||
</div>
|
||||
""" % (call1, call2)
|
||||
|
||||
return call
|
||||
|
||||
def absolute(request):
|
||||
urls = {
|
||||
|
||||
284
rowers/views.py
284
rowers/views.py
@@ -700,7 +700,7 @@ def splitstdata(lijst):
|
||||
|
||||
from utils import (
|
||||
geo_distance,serialize_list,deserialize_list,uniqify,
|
||||
str2bool,range_to_color_hex,absolute,myqueue
|
||||
str2bool,range_to_color_hex,absolute,myqueue,get_call
|
||||
)
|
||||
|
||||
import datautils
|
||||
@@ -2558,10 +2558,15 @@ def cum_flex_data(
|
||||
deltadays = options['deltadays']
|
||||
|
||||
|
||||
try:
|
||||
startdate = iso8601.parse_date(startdatestring)
|
||||
except ParseError:
|
||||
startdate = timezone.now()-datetime.timedelta(days=7)
|
||||
|
||||
startdate = iso8601.parse_date(startdatestring)
|
||||
|
||||
enddate = iso8601.parse_date(enddatestring)
|
||||
try:
|
||||
enddate = iso8601.parse_date(enddatestring)
|
||||
except ParseError:
|
||||
enddate = timezone.now()
|
||||
|
||||
if deltadays>0:
|
||||
startdate = enddate-datetime.timedelta(days=int(deltadays))
|
||||
@@ -2741,15 +2746,7 @@ def cum_flex(request,theuser=0,
|
||||
optionsform = StatsOptionsForm()
|
||||
|
||||
script = ''
|
||||
div = """
|
||||
<div id="id_sitready">
|
||||
<p>
|
||||
<blockquote>
|
||||
Sit Ready! We're counting strokes and loading data
|
||||
</blockquote>
|
||||
</p>
|
||||
</div>
|
||||
"""
|
||||
div = get_call()
|
||||
js_resources = ''
|
||||
css_resources = ''
|
||||
|
||||
@@ -4445,10 +4442,22 @@ def user_multiflex_select(request,
|
||||
})
|
||||
|
||||
@user_passes_test(ispromember,login_url="/",redirect_field_name=None)
|
||||
def multiflex_view(request,userid=0,
|
||||
def multiflex_data(request,userid=0,
|
||||
options={
|
||||
'includereststrokes':False,
|
||||
'ploterrorbars':False,
|
||||
'userid':0,
|
||||
'palette': 'monochrome_blue',
|
||||
'groupby': 'spm',
|
||||
'binsize': 1,
|
||||
'xparam': 'hr',
|
||||
'yparam': 'pace',
|
||||
'spmmin': 15,
|
||||
'spmmax': 55,
|
||||
'workmin': 400,
|
||||
'workmax': 1500,
|
||||
'ids': [],
|
||||
'ploterrorbars':False,
|
||||
}):
|
||||
|
||||
if 'options' in request.session:
|
||||
@@ -4473,90 +4482,23 @@ def multiflex_view(request,userid=0,
|
||||
|
||||
if userid==0:
|
||||
userid = request.user.id
|
||||
|
||||
palette = options['palette']
|
||||
groupby = options['groupby']
|
||||
binsize = options['binsize']
|
||||
xparam = options['xparam']
|
||||
yparam = options['yparam']
|
||||
spmmin = options['spmmin']
|
||||
spmmax = options['spmmax']
|
||||
workmin = options['workmin']
|
||||
workmax = options['workmax']
|
||||
ids = options['ids']
|
||||
|
||||
workouts = [Workout.objects.get(id=id) for id in ids]
|
||||
labeldict = {
|
||||
int(w.id): w.__unicode__() for w in workouts
|
||||
}
|
||||
|
||||
if request.method == 'POST' and 'workouts' in request.POST:
|
||||
form = WorkoutMultipleCompareForm(request.POST)
|
||||
chartform = MultiFlexChoiceForm(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']
|
||||
includereststrokes = chartform.cleaned_data['includereststrokes']
|
||||
ploterrorbars = chartform.cleaned_data['ploterrorbars']
|
||||
request.session['ploterrorbars'] = ploterrorbars
|
||||
request.session['includereststrokes'] = includereststrokes
|
||||
workstrokesonly = not includereststrokes
|
||||
palette = chartform.cleaned_data['palette']
|
||||
request.session['palette'] = palette
|
||||
|
||||
groupby = chartform.cleaned_data['groupby']
|
||||
binsize = chartform.cleaned_data['binsize']
|
||||
if binsize <= 0:
|
||||
binsize = 1
|
||||
if groupby == 'pace':
|
||||
binsize *= 1000
|
||||
|
||||
spmmin = chartform.cleaned_data['spmmin']
|
||||
spmmax = chartform.cleaned_data['spmmax']
|
||||
workmin = chartform.cleaned_data['workmin']
|
||||
workmax = chartform.cleaned_data['workmax']
|
||||
|
||||
ids = [int(w.id) for w in workouts]
|
||||
request.session['ids'] = ids
|
||||
|
||||
else:
|
||||
return HttpResponse("Form is not valid")
|
||||
elif request.method == 'POST' and 'ids' in request.session:
|
||||
chartform = MultiFlexChoiceForm(request.POST)
|
||||
if chartform.is_valid():
|
||||
xparam = chartform.cleaned_data['xparam']
|
||||
yparam = chartform.cleaned_data['yparam']
|
||||
includereststrokes = chartform.cleaned_data['includereststrokes']
|
||||
ploterrorbars = chartform.cleaned_data['ploterrorbars']
|
||||
request.session['ploterrorbars'] = ploterrorbars
|
||||
request.session['includereststrokes'] = includereststrokes
|
||||
workstrokesonly = not includereststrokes
|
||||
palette = chartform.cleaned_data['palette']
|
||||
request.session['palette'] = palette
|
||||
|
||||
groupby = chartform.cleaned_data['groupby']
|
||||
binsize = chartform.cleaned_data['binsize']
|
||||
if binsize <= 0:
|
||||
binsize = 1
|
||||
if groupby == 'pace':
|
||||
binsize *= 1000.
|
||||
|
||||
spmmin = chartform.cleaned_data['spmmin']
|
||||
spmmax = chartform.cleaned_data['spmmax']
|
||||
workmin = chartform.cleaned_data['workmin']
|
||||
workmax = chartform.cleaned_data['workmax']
|
||||
|
||||
ids = request.session['ids']
|
||||
request.session['ids'] = ids
|
||||
workouts = dataprep.get_workouts(ids,userid)
|
||||
if not workouts:
|
||||
message = 'Error: Workouts in session storage do not belong to this user.'
|
||||
messages.error(request,message)
|
||||
url = reverse(user_multiflex_select,
|
||||
kwargs={
|
||||
'userid':userid,
|
||||
}
|
||||
)
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
# workouts = [Workout.objects.get(id=id) for id in ids]
|
||||
|
||||
labeldict = {
|
||||
int(w.id): w.__unicode__() for w in workouts
|
||||
}
|
||||
|
||||
else:
|
||||
return HttpResponse("invalid form")
|
||||
else:
|
||||
url = reverse(user_multiflex_select)
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
fieldlist,fielddict = dataprep.getstatsfields()
|
||||
fieldlist = [xparam,yparam,groupby,
|
||||
'workoutid','spm','driveenergy',
|
||||
@@ -4712,10 +4654,145 @@ def multiflex_view(request,userid=0,
|
||||
binsize=binsize,
|
||||
colorlegend=colorlegend)
|
||||
|
||||
scripta= script.split('\n')[2:-1]
|
||||
script = ''.join(scripta)
|
||||
|
||||
|
||||
return JSONResponse({
|
||||
"script":script,
|
||||
"div":div,
|
||||
})
|
||||
|
||||
|
||||
@user_passes_test(ispromember,login_url="/",redirect_field_name=None)
|
||||
def multiflex_view(request,userid=0,
|
||||
options={
|
||||
'includereststrokes':False,
|
||||
'ploterrorbars':False,
|
||||
}):
|
||||
|
||||
if 'options' in request.session:
|
||||
options = request.session['options']
|
||||
|
||||
try:
|
||||
includereststrokes = options['includereststrokes']
|
||||
except KeyError:
|
||||
includereststrokes = False
|
||||
|
||||
try:
|
||||
ploterrorbars = options['ploterrorbars']
|
||||
except KeyError:
|
||||
ploterrorbars = False
|
||||
|
||||
try:
|
||||
palette = request.session['palette']
|
||||
except KeyError:
|
||||
palette = 'monochrome_blue'
|
||||
|
||||
workstrokesonly = not includereststrokes
|
||||
|
||||
if userid==0:
|
||||
userid = request.user.id
|
||||
|
||||
if request.method == 'POST' and 'workouts' in request.POST:
|
||||
form = WorkoutMultipleCompareForm(request.POST)
|
||||
chartform = MultiFlexChoiceForm(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']
|
||||
includereststrokes = chartform.cleaned_data['includereststrokes']
|
||||
ploterrorbars = chartform.cleaned_data['ploterrorbars']
|
||||
|
||||
workstrokesonly = not includereststrokes
|
||||
palette = chartform.cleaned_data['palette']
|
||||
|
||||
groupby = chartform.cleaned_data['groupby']
|
||||
binsize = chartform.cleaned_data['binsize']
|
||||
if binsize <= 0:
|
||||
binsize = 1
|
||||
if groupby == 'pace':
|
||||
binsize *= 1000
|
||||
|
||||
spmmin = chartform.cleaned_data['spmmin']
|
||||
spmmax = chartform.cleaned_data['spmmax']
|
||||
workmin = chartform.cleaned_data['workmin']
|
||||
workmax = chartform.cleaned_data['workmax']
|
||||
|
||||
ids = [int(w.id) for w in workouts]
|
||||
request.session['ids'] = ids
|
||||
|
||||
else:
|
||||
return HttpResponse("Form is not valid")
|
||||
elif request.method == 'POST' and 'ids' in request.session:
|
||||
chartform = MultiFlexChoiceForm(request.POST)
|
||||
if chartform.is_valid():
|
||||
xparam = chartform.cleaned_data['xparam']
|
||||
yparam = chartform.cleaned_data['yparam']
|
||||
includereststrokes = chartform.cleaned_data['includereststrokes']
|
||||
ploterrorbars = chartform.cleaned_data['ploterrorbars']
|
||||
request.session['ploterrorbars'] = ploterrorbars
|
||||
request.session['includereststrokes'] = includereststrokes
|
||||
workstrokesonly = not includereststrokes
|
||||
palette = chartform.cleaned_data['palette']
|
||||
|
||||
groupby = chartform.cleaned_data['groupby']
|
||||
binsize = chartform.cleaned_data['binsize']
|
||||
if binsize <= 0:
|
||||
binsize = 1
|
||||
if groupby == 'pace':
|
||||
binsize *= 1000.
|
||||
|
||||
spmmin = chartform.cleaned_data['spmmin']
|
||||
spmmax = chartform.cleaned_data['spmmax']
|
||||
workmin = chartform.cleaned_data['workmin']
|
||||
workmax = chartform.cleaned_data['workmax']
|
||||
|
||||
ids = request.session['ids']
|
||||
request.session['ids'] = ids
|
||||
workouts = dataprep.get_workouts(ids,userid)
|
||||
if not workouts:
|
||||
message = 'Error: Workouts in session storage do not belong to this user.'
|
||||
messages.error(request,message)
|
||||
url = reverse(user_multiflex_select,
|
||||
kwargs={
|
||||
'userid':userid,
|
||||
}
|
||||
)
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
# workouts = [Workout.objects.get(id=id) for id in ids]
|
||||
|
||||
|
||||
else:
|
||||
return HttpResponse("invalid form")
|
||||
else:
|
||||
url = reverse(user_multiflex_select)
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
div = get_call()
|
||||
|
||||
options['includereststrokes'] = includereststrokes
|
||||
options['ploterrorbars'] = ploterrorbars
|
||||
options['userid'] = userid
|
||||
options['palette'] = palette
|
||||
options['groupby'] = groupby
|
||||
options['binsize'] = binsize
|
||||
options['xparam'] = xparam
|
||||
options['yparam'] = yparam
|
||||
options['spmmin'] = spmmin
|
||||
options['spmmax'] = spmmax
|
||||
options['workmin'] = workmin
|
||||
options['workmax'] = workmax
|
||||
options['ids'] = ids
|
||||
|
||||
|
||||
request.session['options'] = options
|
||||
|
||||
|
||||
return render(request,'multiflex.html',
|
||||
{'interactiveplot':script,
|
||||
{'interactiveplot':'',
|
||||
'the_div':div,
|
||||
'chartform':chartform,
|
||||
'userid':userid,
|
||||
@@ -4885,6 +4962,7 @@ def boxplot_view_data(request,userid=0,
|
||||
ids = options['ids']
|
||||
userid = options['userid']
|
||||
plotfield = options['plotfield']
|
||||
|
||||
|
||||
workstrokesonly = not includereststrokes
|
||||
|
||||
@@ -5004,15 +5082,7 @@ def boxplot_view(request,userid=0,
|
||||
url = reverse(user_boxplot_select)
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
div = """
|
||||
<div id="id_sitready">
|
||||
<p>
|
||||
<blockquote>
|
||||
Sit Ready! We're counting strokes and loading data
|
||||
</blockquote>
|
||||
</p>
|
||||
</div>
|
||||
"""
|
||||
div = get_call()
|
||||
|
||||
options['spmmin'] = spmmin
|
||||
options['spmmax'] = spmmax
|
||||
|
||||
Reference in New Issue
Block a user