From 29f84d6e251e46c6e7c2b42387fc4368b7ef3f87 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Fri, 12 May 2017 14:19:50 +0200 Subject: [PATCH] added HR drift, normalized power, training score --- rowers/templates/workoutstats.html | 29 ++++++++++++++++ rowers/views.py | 54 ++++++++++++++++++++++++++++++ rowsandall_app/settings_dev.py | 3 +- 3 files changed, 85 insertions(+), 1 deletion(-) diff --git a/rowers/templates/workoutstats.html b/rowers/templates/workoutstats.html index 6d413dea..75dc0f8c 100644 --- a/rowers/templates/workoutstats.html +++ b/rowers/templates/workoutstats.html @@ -74,6 +74,34 @@ {% endif %}
+ {% if otherstats %} +
+   +
+
+

Other Stats

+ + + + + + + + + + {% for key, value in otherstats.items %} + + + + + + {% endfor %} + +
MetricValueUnit
{{ value.verbose_name }}{{ value.value }}{{ value.unit }}
+
+ {% endif %} + +
{% if cordict %}

Correlation matrix

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. @@ -112,6 +140,7 @@ {% endif %} +

{% endblock %} diff --git a/rowers/views.py b/rowers/views.py index a1685e48..1e6b24c8 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -4036,6 +4036,9 @@ def cumstats(request,theuser=0, # Stats page @login_required() def workout_stats_view(request,id=0,message="",successmessage=""): + + r = Rower.objects.get(user=request.user) + workstrokesonly = True if request.method == 'POST' and 'workstrokesonly' in request.POST: workstrokesonly = request.POST['workstrokesonly'] @@ -4093,6 +4096,56 @@ def workout_stats_view(request,id=0,message="",successmessage=""): cordict[field1] = thedict + # additional non-automated stats + otherstats = {} + + # Normalized power & TSS + duration = datadf['time'].max()-datadf['time'].min() + duration /= 1.0e3 + pwr4 = datadf['power']**(4) + normp = (pwr4.mean())**(0.25) + if not np.isnan(normp): + intensityfactor = datadf['power'].mean()/float(r.ftp) + intensityfactor = normp/float(r.ftp) + tss = 100.*((duration*normp*intensityfactor)/(3600.*r.ftp)) + + otherstats['np'] = { + 'verbose_name':'rPower', + 'value':int(10*normp)/10., + 'unit':'Watt' + } + + otherstats['tss'] = { + 'verbose_name':'rScore', + 'value':int(tss), + 'unit':'' + } + + # HR Drift + tmax = datadf['time'].max() + tmin = datadf['time'].min() + thalf = tmin+0.5*(tmax-tmin) + mask1 = datadf['time'] < thalf + mask2 = datadf['time'] > thalf + + hr1 = datadf.loc[mask1,'hr'].mean() + hr2 = datadf.loc[mask2,'hr'].mean() + + pwr1 = datadf.loc[mask1,'power'].mean() + pwr2 = datadf.loc[mask2,'power'].mean() + + try: + hrdrift = ((pwr1/hr1)-(pwr2/hr2))/(pwr1/hr1) + hrdrift *= 100. + otherstats['hrdrift'] = { + 'verbose_name': 'Heart Rate Drift', + 'value': int(100*hrdrift)/100., + 'unit': '%', + } + except ZeroDivisionError: + pass + + return render(request, 'workoutstats.html', { @@ -4101,6 +4154,7 @@ def workout_stats_view(request,id=0,message="",successmessage=""): 'workout':row, 'workstrokesonly':workstrokesonly, 'cordict':cordict, + 'otherstats':otherstats, }) # The Advanced edit page diff --git a/rowsandall_app/settings_dev.py b/rowsandall_app/settings_dev.py index 8720c8b4..82d0dffe 100644 --- a/rowsandall_app/settings_dev.py +++ b/rowsandall_app/settings_dev.py @@ -45,7 +45,8 @@ CELERY_SEND_TASK_SENT_EVENT = True # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -TEMPLATE_DEBUG = DEBUG + +TEMPLATES[0]['OPTIONS']['debug'] = DEBUG ALLOWED_HOSTS = ['localhost']