Private
Public Access
1
0

first version of box chart (wash only)

This commit is contained in:
Sander Roosendaal
2017-05-12 15:48:47 +02:00
parent 29f84d6e25
commit 50faf1ff1f
5 changed files with 71 additions and 6 deletions

View File

@@ -272,7 +272,7 @@ def getstatsfields():
fielddict = {field.name:field.verbose_name for field in fields}
fielddict.pop('workoutid')
#fielddict.pop('workoutid')
fielddict.pop('ergpace')
fielddict.pop('hr_an')
fielddict.pop('hr_tr')

View File

@@ -11,7 +11,7 @@ from bokeh.palettes import Dark2_8 as palette
import itertools
from bokeh.plotting import figure, ColumnDataSource, Figure,curdoc
from bokeh.models import CustomJS,Slider, TextInput
from bokeh.charts import Histogram,HeatMap
from bokeh.charts import Histogram,HeatMap,Area,BoxPlot
from bokeh.resources import CDN,INLINE
from bokeh.embed import components
from bokeh.layouts import layout,widgetbox
@@ -87,6 +87,22 @@ def tailwind(bearing,vwind,winddir):
from rowers.dataprep import nicepaceformat,niceformat
from rowers.dataprep import timedeltaconv
def interactive_boxchart(datadf,fieldname):
plot = BoxPlot(datadf, values=fieldname, label='date',
legend=False,
title=axlabels[fieldname],
outliers=False)
yrange1 = Range1d(start=yaxminima[fieldname],end=yaxmaxima[fieldname])
plot.y_range = yrange1
script, div = components(plot)
return script,div
def interactive_forcecurve(theworkouts,workstrokesonly=False):
TOOLS = 'save,pan,box_zoom,wheel_zoom,reset,tap,hover,resize,crosshair'

View File

@@ -5,6 +5,35 @@
{% block title %}Workout Statistics{% endblock %}
{% block content %}
<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>
{{ plotscript |safe }}
<script>
// 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.
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, true, true);
};
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 class="grid_12 alpha">
<h1>Workout Statistics</h1>
<p>
@@ -97,6 +126,7 @@
</div>
<div class="grid_8 omega">
{% if cordict %}
<div class="grid_8">
<h2> Correlation Matrix</h2>
<p>This matrix indicates a positive (+) or negative (-) correlation between two parameters. The Spearman correlation coefficient has values between +1 and -1. Positive correlation between two metrics means that if one metric increases, the other value is also likely to increase. Negative is the opposite. The further from zero, the higher the likelyhood.
</p>
@@ -132,8 +162,13 @@
{% endfor %}
</tbody>
</table>
<div class="grid_8">
{% endif %}
</div>
<div class="grid_8">
{{ plotdiv|safe }}
</div>
</div>
</div>
{% endblock %}

View File

@@ -51,4 +51,4 @@
</div>
{% endblock %}
{% endblock %}

View File

@@ -3834,7 +3834,7 @@ def workout_geeky_view(request,id=0,message="",successmessage=""):
# Cumulative stats page
@login_required()
def cumstats(request,theuser=0,
startdate=timezone.now()-datetime.timedelta(days=365),
startdate=timezone.now()-datetime.timedelta(days=30),
enddate=timezone.now(),
deltadays=-1,
startdatestring="",
@@ -3957,6 +3957,12 @@ def cumstats(request,theuser=0,
ids = [int(workout.id) for workout in allergworkouts]
datemapping = {
w.id:w.date for w in allergworkouts
}
fieldlist,fielddict = dataprep.getstatsfields()
# prepare data frame
@@ -3972,6 +3978,7 @@ def cumstats(request,theuser=0,
# Create stats
stats = {}
fielddict.pop('workoutstate')
fielddict.pop('workoutid')
for field,verbosename in fielddict.iteritems():
thedict = {
@@ -3998,8 +4005,13 @@ def cumstats(request,theuser=0,
except KeyError:
thedict[field2] = 0
cordict[field1] = thedict
cordict[field1] = thedict
# interactive box plot
datadf['workoutid'].replace(datemapping,inplace=True)
datadf.rename(columns={"workoutid":"date"},inplace=True)
script,div = interactive_boxchart(datadf,'wash')
# set options form correctly
initial = {}
initial['includereststrokes'] = includereststrokes
@@ -4027,6 +4039,8 @@ def cumstats(request,theuser=0,
'deltaform':deltaform,
'optionsform':optionsform,
'cordict':cordict,
'plotscript':script,
'plotdiv':div,
})
request.session['options'] = options