added stats
This commit is contained in:
@@ -841,7 +841,8 @@ analysischoices = (
|
||||
('boxplot','Box Chart'),
|
||||
('trendflex','Trend Flex'),
|
||||
('histo','Histogram'),
|
||||
('flexall','Cumulative Flex Chart')
|
||||
('flexall','Cumulative Flex Chart'),
|
||||
('stats','Statistics'),
|
||||
)
|
||||
|
||||
|
||||
|
||||
76
rowers/templates/statsdiv.html
Normal file
76
rowers/templates/statsdiv.html
Normal file
@@ -0,0 +1,76 @@
|
||||
|
||||
{% if stats %}
|
||||
<h2>Statistics</h2>
|
||||
<table width="100%" class="listtable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Metric</th>
|
||||
<th>Mean</th>
|
||||
<th>Minimum</th>
|
||||
<th>25%</th>
|
||||
<th>Median</th>
|
||||
<th>75%</th>
|
||||
<th>Maximum</th>
|
||||
<th>Standard Deviation</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for key, value in stats.items() %}
|
||||
<tr>
|
||||
<td>{{ value.verbosename }}</td>
|
||||
<td>{{ value.mean|floatformat }}</td>
|
||||
<td>{{ value.min|floatformat }}</td>
|
||||
<td>{{ value.firstq|floatformat }}</td>
|
||||
<td>{{ value.median|floatformat }}</td>
|
||||
<td>{{ value.thirdq|floatformat }}</td>
|
||||
<td>{{ value.max|floatformat }}</td>
|
||||
<td>{{ value.std|floatformat }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
{% endif %}
|
||||
|
||||
{% if cordict %}
|
||||
<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>
|
||||
<table width="90%" class="cortable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th> </th>
|
||||
{% for key,value in cordict.items() %}
|
||||
<th class="rotate"><div><span>{{ key }}</span></div></th>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for key, thedict in cordict.items() %}
|
||||
<tr>
|
||||
<th> {{ key }}</th>
|
||||
{% for key2,value in thedict.items() %}
|
||||
<td>
|
||||
{% if value > 0.5 %}
|
||||
<div class="poscor">{{ value|floatformat }}</div>
|
||||
{% elif value > 0.1 %}
|
||||
<div class="weakposcor">{{ value|floatformat }}</div>
|
||||
{% elif value < -0.5 %}
|
||||
<div class="negcor">{{ value|floatformat }}</div>
|
||||
{% elif value < -0.1 %}
|
||||
<div class="weaknegcor">{{ value|floatformat }}</div>
|
||||
{% else %}
|
||||
|
||||
{% endif %}
|
||||
</td>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
{% endif %}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -123,6 +123,10 @@
|
||||
yaxis2.show();
|
||||
}
|
||||
|
||||
if (functionfield.val() == 'stats') {
|
||||
plotfield.hide();
|
||||
}
|
||||
|
||||
|
||||
// Setup an event listener for when the state of the
|
||||
// checkbox changes.
|
||||
@@ -198,6 +202,18 @@
|
||||
binsize.hide();
|
||||
errorbars.hide();
|
||||
}
|
||||
else if (Value=='stats') {
|
||||
xaxis.hide();
|
||||
yaxis1.hide();
|
||||
yaxis2.hide();
|
||||
x_param.hide();
|
||||
y_param.hide();
|
||||
groupby.hide();
|
||||
plotfield.hide();
|
||||
palette.hide();
|
||||
binsize.hide();
|
||||
errorbars.hide();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -5,6 +5,19 @@ from __future__ import unicode_literals
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
from rowers.views.statements import *
|
||||
|
||||
from jinja2 import Template,Environment,FileSystemLoader
|
||||
|
||||
def floatformat(x,prec=2):
|
||||
return '{x}'.format(x=round(x,prec))
|
||||
|
||||
|
||||
env = Environment(loader = FileSystemLoader(["rowers/templates"]))
|
||||
env.filters['floatformat'] = floatformat
|
||||
|
||||
|
||||
from django.contrib.staticfiles import finders
|
||||
|
||||
|
||||
# generic Analysis view -
|
||||
|
||||
defaultoptions = {
|
||||
@@ -459,10 +472,76 @@ def histodata(workouts, options):
|
||||
|
||||
return(script,div)
|
||||
|
||||
def statsdata(workouts, 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']
|
||||
function = options['function']
|
||||
|
||||
workstrokesonly = not includereststrokes
|
||||
|
||||
ids = [w.id for w in workouts]
|
||||
|
||||
datamapping = {
|
||||
w.id:w.date for w in workouts
|
||||
}
|
||||
|
||||
fieldlist,fielddict = dataprep.getstatsfields()
|
||||
|
||||
# prepare data frame
|
||||
datadf,extracols = dataprep.read_cols_df_sql(ids,fieldlist)
|
||||
|
||||
datadf = dataprep.clean_df_stats(datadf,workstrokesonly=workstrokesonly)
|
||||
|
||||
# Create stats
|
||||
stats = {}
|
||||
fielddict.pop('workoutstate')
|
||||
fielddict.pop('workoutid')
|
||||
|
||||
for field,verbosename in fielddict.items():
|
||||
thedict = {
|
||||
'mean':datadf[field].mean(),
|
||||
'min': datadf[field].min(),
|
||||
'std': datadf[field].std(),
|
||||
'max': datadf[field].max(),
|
||||
'median': datadf[field].median(),
|
||||
'firstq':datadf[field].quantile(q=0.25),
|
||||
'thirdq':datadf[field].quantile(q=0.75),
|
||||
'verbosename':verbosename,
|
||||
}
|
||||
stats[field] = thedict
|
||||
|
||||
# Create a dict with correlation values
|
||||
cor = datadf.corr(method='spearman')
|
||||
cor.fillna(value=0,inplace=True)
|
||||
cordict = {}
|
||||
for field1,verbosename in fielddict.items():
|
||||
thedict = {}
|
||||
for field2,verbosename in fielddict.items():
|
||||
try:
|
||||
thedict[field2] = cor.loc[field1,field2]
|
||||
except KeyError:
|
||||
thedict[field2] = 0
|
||||
|
||||
cordict[field1] = thedict
|
||||
|
||||
context = {
|
||||
'stats':stats,
|
||||
'cordict':cordict,
|
||||
}
|
||||
|
||||
htmly = env.get_template('statsdiv.html')
|
||||
html_content = htmly.render(context)
|
||||
|
||||
return('',html_content)
|
||||
|
||||
def boxplotdata(workouts,options):
|
||||
|
||||
|
||||
includereststrokes = options['includereststrokes']
|
||||
spmmin = options['spmmin']
|
||||
spmmax = options['spmmax']
|
||||
@@ -570,6 +649,8 @@ def analysis_view_data(request,userid=0):
|
||||
script, div = histodata(workouts, options)
|
||||
elif function == 'flexall':
|
||||
script,div = flexalldata(workouts,options)
|
||||
elif function == 'stats':
|
||||
script,div = statsdata(workouts,options)
|
||||
else:
|
||||
script = ''
|
||||
div = 'Unknown analysis functions'
|
||||
|
||||
Reference in New Issue
Block a user