Private
Public Access
1
0

automating the stats

This commit is contained in:
Sander Roosendaal
2017-02-06 09:56:09 +01:00
parent b061eb5b1a
commit 38f7a59476
3 changed files with 56 additions and 109 deletions

View File

@@ -280,6 +280,7 @@ class Workout(models.Model):
('slides','Indoor Rower on Slides'),
('paddle','Paddle Adapter'),
('snow','On-snow'),
('other','Other'),
)
boattypes = (

View File

@@ -6,7 +6,7 @@
{% block content %}
<div class="grid_12 alpha">
<h1>Workout Statistics</h1>
<h1>Workout Statistics for {{ workout.name }}</h1>
<div class="grid_2 alpha">
<p>
<a class="button gray small" href="/rowers/workout/{{ workout.id }}/edit">Edit Workout</a>
@@ -38,7 +38,9 @@
</div>
</div>
<div class="grid_6 alpha">
<h2>Stroke Rate</h2>
{% if stats %}
{% for key, value in stats.items %}
<h2>{{ key }}</h2>
<table width="100%" class="listtable">
<thead>
<tr>
@@ -48,80 +50,24 @@
</thead>
<tbody>
<tr>
<td>Mean</td><td>{{ stats.spm.mean|floatformat:-2 }}</td>
<td>Mean</td><td>{{ value.mean|floatformat:-2 }}</td>
</tr><tr>
<td>Minimum</td><td>{{ stats.spm.min|floatformat:-2 }}</td>
<td>Minimum</td><td>{{ value.min|floatformat:-2 }}</td>
</tr><tr>
<td>25&#37;</td><td>{{ stats.spm.firstq|floatformat:-2 }}</td>
<td>25&#37;</td><td>{{ value.firstq|floatformat:-2 }}</td>
</tr><tr>
<td>Median</td><td>{{ stats.spm.median|floatformat:-2 }}</td>
<td>Median</td><td>{{ value.median|floatformat:-2 }}</td>
</tr><tr>
<td>75&#37;</td><td>{{ stats.spm.thirdq|floatformat:-2 }}</td>
<td>75&#37;</td><td>{{ value.thirdq|floatformat:-2 }}</td>
</tr><tr>
<td>Maximum</td><td>{{ stats.spm.max|floatformat:-2 }}</td>
<td>Maximum</td><td>{{ value.max|floatformat:-2 }}</td>
</tr><tr>
<td>Standard Deviation</td><td>{{ stats.spm.std|floatformat:-2 }}</td>
<td>Standard Deviation</td><td>{{ value.std|floatformat:-2 }}</td>
</tr>
</tbody>
</table>
</div>
<div class="grid_6 alpha">
<h2>Heart Rate</h2>
<table width="100%" class="listtable">
<thead>
<tr>
<th>Metric</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<tr>
<td>Mean</td><td>{{ stats.hr.mean|floatformat:-2 }}</td>
</tr><tr>
<td>Minimum</td><td>{{ stats.hr.min|floatformat:-2 }}</td>
</tr><tr>
<td>25&#37;</td><td>{{ stats.hr.firstq|floatformat:-2 }}</td>
</tr><tr>
<td>Median</td><td>{{ stats.hr.median|floatformat:-2 }}</td>
</tr><tr>
<td>75&#37;</td><td>{{ stats.hr.thirdq|floatformat:-2 }}</td>
</tr><tr>
<td>Maximum</td><td>{{ stats.hr.max|floatformat:-2 }}</td>
</tr><tr>
<td>Standard Deviation</td><td>{{ stats.hr.std|floatformat:-2 }}</td>
</tr>
</tbody>
</table>
</div>
<div class="grid_6 omega">
<div class="grid_6 alpha">
<h2>Power</h2>
<table width="100%" class="listtable">
<thead>
<tr>
<th>Metric</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<tr>
<td>Mean</td><td>{{ stats.power.mean|floatformat:-2 }}</td>
</tr><tr>
<td>Minimum</td><td>{{ stats.power.min|floatformat:-2 }}</td>
</tr><tr>
<td>25&#37;</td><td>{{ stats.power.firstq|floatformat:-2 }}</td>
</tr><tr>
<td>Median</td><td>{{ stats.power.median|floatformat:-2 }}</td>
</tr><tr>
<td>75&#37;</td><td>{{ stats.power.thirdq|floatformat:-2 }}</td>
</tr><tr>
<td>Maximum</td><td>{{ stats.power.max|floatformat:-2 }}</td>
</tr><tr>
<td>Standard Deviation</td><td>{{ stats.power.std|floatformat:-2 }}</td>
</tr>
</tbody>
</table>
</div>
</table>
{% endfor %}
{% endif %}
</div>
{% endblock %}

View File

@@ -26,7 +26,7 @@ from rowers.forms import SummaryStringForm,IntervalUpdateForm,StrokeDataForm
from rowers.models import Workout, User, Rower, WorkoutForm,FavoriteChart
from rowers.models import (
RowerPowerForm,RowerForm,GraphImage,AdvancedWorkoutForm,
RowerPowerZonesForm,AccountRowerForm,UserForm,
RowerPowerZonesForm,AccountRowerForm,UserForm,StrokeData,
)
from rowers.models import FavoriteForm,BaseFavoriteFormSet,SiteAnnouncement
from django.forms.formsets import formset_factory
@@ -2611,15 +2611,15 @@ def workout_stats_view(request,id=0,message="",successmessage=""):
workstrokesonly = True
if request.method == 'POST' and 'workstrokesonly' in request.POST:
workstrokesonly = request.POST['workstrokesonly']
# prepare data frame
datadf,row = dataprep.getrowdata_db(id=id)
if (checkworkoutuser(request.user,row)==False):
message = "You are not allowed to see the stats of this workout"
url = reverse(workouts_view,args=[str(message)])
return HttpResponseRedirect(url)
columns = ['hr','spm','power','workoutstate']
datadf = dataprep.getsmallrowdata_db(columns,ids=[id])
if datadf.empty:
return HttpResponse("CSV data file not found")
@@ -2634,45 +2634,45 @@ def workout_stats_view(request,id=0,message="",successmessage=""):
except:
pass
workstrokesonly = True
# Create stats
stats = {}
# SPM
spmdict = {
'mean':datadf['spm'].mean(),
'max': datadf['spm'].max(),
'min': datadf['spm'].min(),
'std': datadf['spm'].std(),
'median': datadf['spm'].median(),
'firstq':datadf['spm'].quantile(q=0.25),
'thirdq':datadf['spm'].quantile(q=0.75),
stats = {}
# Get field names and remove those that are not useful in stats
fieldnames = StrokeData._meta.get_all_field_names()
fieldnames.remove('workoutid')
fieldnames.remove('ergpace')
fieldnames.remove('hr_an')
fieldnames.remove('hr_tr')
fieldnames.remove('hr_at')
fieldnames.remove('hr_ut2')
fieldnames.remove('hr_ut1')
fieldnames.remove('time')
fieldnames.remove('distance')
fieldnames.remove('nowindpace')
fieldnames.remove('fnowindpace')
fieldnames.remove('fergpace')
fieldnames.remove('equivergpower')
fieldnames.remove('workoutstate')
fieldnames.remove('fpace')
fieldnames.remove('id')
fieldnames.remove('ftime')
fieldnames.remove('x_right')
fieldnames.remove('hr_max')
fieldnames.remove('hr_bottom')
fieldnames.remove('cumdist')
# HR
hrdict = {
'mean':datadf['hr'].mean(),
'max': datadf['hr'].max(),
'min': datadf['hr'].min(),
'std': datadf['hr'].std(),
'median': datadf['hr'].median(),
'firstq':datadf['hr'].quantile(q=0.25),
'thirdq':datadf['hr'].quantile(q=0.75),
}
stats['hr'] = hrdict
# Power
powerdict = {
'mean':datadf['power'].mean(),
'max': datadf['power'].max(),
'min': datadf['power'].min(),
'std': datadf['power'].std(),
'median': datadf['power'].median(),
'firstq':datadf['power'].quantile(q=0.25),
'thirdq':datadf['power'].quantile(q=0.75),
}
for field in fieldnames:
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),
}
stats[field] = thedict
return render(request,