lazy loads box chart
This commit is contained in:
1
rowers/templates/.#cum_flex.html
Normal file
1
rowers/templates/.#cum_flex.html
Normal file
@@ -0,0 +1 @@
|
||||
E408191@CZ27LT9RCGN72.648792:1509824931
|
||||
@@ -11,7 +11,8 @@
|
||||
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 +38,7 @@
|
||||
<div class="grid_12 alpha">
|
||||
<h1>Box 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 +68,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-boxplot-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 %}
|
||||
|
||||
@@ -296,6 +296,7 @@ urlpatterns = [
|
||||
url(r'^user-boxplot/(?P<userid>\d+)$',views.boxplot_view),
|
||||
url(r'^user-boxplot/$',views.boxplot_view),
|
||||
url(r'^user-boxplot$',views.boxplot_view),
|
||||
url(r'^user-boxplot-data$',views.boxplot_view_data),
|
||||
url(r'^user-multiflex/(?P<userid>\d+)$',views.multiflex_view),
|
||||
url(r'^user-multiflex/$',views.multiflex_view),
|
||||
url(r'^user-multiflex$',views.multiflex_view),
|
||||
|
||||
235
rowers/views.py
235
rowers/views.py
@@ -4861,6 +4861,92 @@ def user_boxplot_select(request,
|
||||
'teams':get_my_teams(request.user),
|
||||
})
|
||||
|
||||
@user_passes_test(ispromember,login_url="/",redirect_field_name=None)
|
||||
def boxplot_view_data(request,userid=0,
|
||||
options={
|
||||
'includereststrokes':False,
|
||||
'spmmin':15,
|
||||
'spmmax':55,
|
||||
'workmin':0,
|
||||
'workmax':1500,
|
||||
'ids':[],
|
||||
'userid':0,
|
||||
'plotfield':'spm',
|
||||
}):
|
||||
|
||||
if 'options' in request.session:
|
||||
options = request.session['options']
|
||||
|
||||
includereststrokes = options['includereststrokes']
|
||||
spmmin = options['spmmin']
|
||||
spmmax = options['spmmax']
|
||||
workmin = options['workmin']
|
||||
workmax = options['workmax']
|
||||
ids = options['ids']
|
||||
userid = options['userid']
|
||||
plotfield = options['plotfield']
|
||||
|
||||
workstrokesonly = not includereststrokes
|
||||
|
||||
if userid==0:
|
||||
userid = request.user.id
|
||||
|
||||
workouts = [Workout.objects.get(id=id) for id in ids]
|
||||
labeldict = {
|
||||
int(w.id): w.__unicode__() for w in workouts
|
||||
}
|
||||
|
||||
|
||||
datemapping = {
|
||||
w.id:w.date for w in workouts
|
||||
}
|
||||
|
||||
|
||||
|
||||
fieldlist,fielddict = dataprep.getstatsfields()
|
||||
fieldlist = [plotfield,'workoutid','spm','driveenergy',
|
||||
'workoutstate']
|
||||
|
||||
# prepare data frame
|
||||
datadf = dataprep.read_cols_df_sql(ids,fieldlist)
|
||||
|
||||
datadf = dataprep.clean_df_stats(datadf,workstrokesonly=workstrokesonly)
|
||||
|
||||
datadf = dataprep.filter_df(datadf,'spm',spmmin,
|
||||
largerthan=True)
|
||||
datadf = dataprep.filter_df(datadf,'spm',spmmax,
|
||||
largerthan=False)
|
||||
datadf = dataprep.filter_df(datadf,'driveenergy',workmin,
|
||||
largerthan=True)
|
||||
datadf = dataprep.filter_df(datadf,'driveneergy',workmax,
|
||||
largerthan=False)
|
||||
|
||||
datadf.dropna(axis=0,how='any',inplace=True)
|
||||
|
||||
datadf['workoutid'].replace(datemapping,inplace=True)
|
||||
datadf.rename(columns={"workoutid":"date"},inplace=True)
|
||||
datadf = datadf.sort_values(['date'])
|
||||
|
||||
if userid == 0:
|
||||
extratitle = ''
|
||||
else:
|
||||
u = User.objects.get(id=userid)
|
||||
extratitle = ' '+u.first_name+' '+u.last_name
|
||||
|
||||
|
||||
|
||||
script,div = interactive_boxchart(datadf,plotfield,
|
||||
extratitle=extratitle)
|
||||
|
||||
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 boxplot_view(request,userid=0,
|
||||
options={
|
||||
@@ -4895,60 +4981,6 @@ def boxplot_view(request,userid=0,
|
||||
ids = [int(w.id) for w in workouts]
|
||||
request.session['ids'] = ids
|
||||
|
||||
labeldict = {
|
||||
int(w.id): w.__unicode__() for w in workouts
|
||||
}
|
||||
|
||||
|
||||
datemapping = {
|
||||
w.id:w.date for w in workouts
|
||||
}
|
||||
|
||||
|
||||
|
||||
fieldlist,fielddict = dataprep.getstatsfields()
|
||||
fieldlist = [plotfield,'workoutid','spm','driveenergy',
|
||||
'workoutstate']
|
||||
|
||||
# prepare data frame
|
||||
datadf = dataprep.read_cols_df_sql(ids,fieldlist)
|
||||
|
||||
datadf = dataprep.clean_df_stats(datadf,workstrokesonly=workstrokesonly)
|
||||
|
||||
datadf = dataprep.filter_df(datadf,'spm',spmmin,
|
||||
largerthan=True)
|
||||
datadf = dataprep.filter_df(datadf,'spm',spmmax,
|
||||
largerthan=False)
|
||||
datadf = dataprep.filter_df(datadf,'driveenergy',workmin,
|
||||
largerthan=True)
|
||||
datadf = dataprep.filter_df(datadf,'driveneergy',workmax,
|
||||
largerthan=False)
|
||||
|
||||
datadf.dropna(axis=0,how='any',inplace=True)
|
||||
|
||||
datadf['workoutid'].replace(datemapping,inplace=True)
|
||||
datadf.rename(columns={"workoutid":"date"},inplace=True)
|
||||
datadf = datadf.sort_values(['date'])
|
||||
|
||||
if userid == 0:
|
||||
extratitle = ''
|
||||
else:
|
||||
u = User.objects.get(id=userid)
|
||||
extratitle = ' '+u.first_name+' '+u.last_name
|
||||
|
||||
|
||||
|
||||
script,div = interactive_boxchart(datadf,plotfield,
|
||||
extratitle=extratitle)
|
||||
|
||||
|
||||
return render(request,'boxplot.html',
|
||||
{'interactiveplot':script,
|
||||
'the_div':div,
|
||||
'chartform':chartform,
|
||||
'userid':userid,
|
||||
'teams':get_my_teams(request.user),
|
||||
})
|
||||
else:
|
||||
return HttpResponse("Form is not valid")
|
||||
elif request.method == 'POST' and 'ids' in request.session:
|
||||
@@ -4964,80 +4996,43 @@ def boxplot_view(request,userid=0,
|
||||
workstrokesonly = not includereststrokes
|
||||
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_boxplot_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
|
||||
}
|
||||
|
||||
datemapping = {
|
||||
w.id:w.date for w in workouts
|
||||
}
|
||||
|
||||
fieldlist,fielddict = dataprep.getstatsfields()
|
||||
fieldlist = [plotfield,'workoutid','spm','driveenergy',
|
||||
'workoutstate']
|
||||
|
||||
# prepare data frame
|
||||
datadf = dataprep.read_cols_df_sql(ids,fieldlist)
|
||||
|
||||
# dummy values for drive energy
|
||||
mask = datadf['driveenergy'] == 0
|
||||
datadf.loc[mask,'driveenergy'] = 450
|
||||
|
||||
datadf = dataprep.clean_df_stats(datadf,
|
||||
workstrokesonly=workstrokesonly)
|
||||
|
||||
|
||||
datadf = dataprep.filter_df(datadf,'spm',spmmin,
|
||||
largerthan=True)
|
||||
datadf = dataprep.filter_df(datadf,'spm',spmmax,
|
||||
largerthan=False)
|
||||
datadf = dataprep.filter_df(datadf,'driveenergy',workmin,
|
||||
largerthan=True)
|
||||
datadf = dataprep.filter_df(datadf,'driveneergy',workmax,
|
||||
largerthan=False)
|
||||
|
||||
datadf.dropna(axis=0,how='any',inplace=True)
|
||||
|
||||
datadf['workoutid'].replace(datemapping,inplace=True)
|
||||
datadf.rename(columns={"workoutid":"date"},inplace=True)
|
||||
datadf = datadf.sort_values(['date'])
|
||||
|
||||
if userid == 0:
|
||||
extratitle = ''
|
||||
else:
|
||||
u = User.objects.get(id=userid)
|
||||
extratitle = ' '+u.first_name+' '+u.last_name
|
||||
|
||||
script,div = interactive_boxchart(datadf,plotfield,
|
||||
extratitle=extratitle)
|
||||
|
||||
|
||||
return render(request,'boxplot.html',
|
||||
{'interactiveplot':script,
|
||||
'the_div':div,
|
||||
'chartform':chartform,
|
||||
'userid':userid,
|
||||
'teams':get_my_teams(request.user),
|
||||
})
|
||||
else:
|
||||
return HttpResponse("invalid form")
|
||||
else:
|
||||
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>
|
||||
"""
|
||||
|
||||
options['spmmin'] = spmmin
|
||||
options['spmmax'] = spmmax
|
||||
options['workmin'] = workmin
|
||||
options['workmax'] = workmax
|
||||
options['ids'] = ids
|
||||
options['userid'] = userid
|
||||
options['plotfield'] = plotfield
|
||||
|
||||
request.session['options'] = options
|
||||
|
||||
return render(request,'boxplot.html',
|
||||
{'interactiveplot':'',
|
||||
'the_div':div,
|
||||
'chartform':chartform,
|
||||
'userid':userid,
|
||||
'teams':get_my_teams(request.user),
|
||||
})
|
||||
|
||||
|
||||
# List Workouts
|
||||
@login_required()
|
||||
def workouts_view(request,message='',successmessage='',
|
||||
|
||||
Reference in New Issue
Block a user