From d8c198f3b22e901153353eae7312ba3fe2598fd3 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Wed, 4 Nov 2020 21:14:35 +0100 Subject: [PATCH 1/2] fav analysis --- rowers/views/userviews.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rowers/views/userviews.py b/rowers/views/userviews.py index 031a7bba..ab4f66a4 100644 --- a/rowers/views/userviews.py +++ b/rowers/views/userviews.py @@ -405,6 +405,7 @@ def rower_edit_view(request,rowerid=0,userid=0,message=""): getemailnotifications = cd['getemailnotifications'] getimportantemails = cd['getimportantemails'] defaulttimezone=cd['defaulttimezone'] + fav_analysis = cd['fav_analysis'] u = r.user if u.email != email and len(email): resetbounce = True @@ -432,6 +433,7 @@ def rower_edit_view(request,rowerid=0,userid=0,message=""): r.birthdate = birthdate r.autojoin = autojoin r.emailalternatives = emailalternatives + r.fav_analysis = fav_analysis if resetbounce and r.emailbounced: From 33b4411a6f298853531db1b8ae07f1e6e5b67e31 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Wed, 4 Nov 2020 21:51:17 +0100 Subject: [PATCH 2/2] usersmooth --- rowers/interactiveplots.py | 14 +++++++++++++- rowers/metrics.py | 32 +++++++++++++++++++++++++++++++- rowers/models.py | 14 +++++++++++++- rowers/tests/test_user.py | 1 + rowers/views/userviews.py | 3 +++ 5 files changed, 61 insertions(+), 3 deletions(-) diff --git a/rowers/interactiveplots.py b/rowers/interactiveplots.py index 5273b2de..c271506c 100644 --- a/rowers/interactiveplots.py +++ b/rowers/interactiveplots.py @@ -13,7 +13,7 @@ from rowingdata import main as rmain from rowingdata import cumcpdata,histodata from rowingdata import rowingdata as rrdata -from math import pi +from math import pi,log2 from django.utils import timezone from rowingdata import make_cumvalues @@ -79,6 +79,7 @@ from scipy.interpolate import griddata import rowers.stravastuff as stravastuff +from rowers.metrics import rowingmetrics,metricsdicts from rowers.dataprep import rdata import rowers.dataprep as dataprep @@ -4442,6 +4443,17 @@ def interactive_flex_chart2(id,r,promember=0, rowdata = dataprep.getsmallrowdata_db(columns,ids=[id],doclean=True, workstrokesonly=workstrokesonly) + if r.usersmooth > 1: + for column in columns: + try: + if metricsdicts[column]['maysmooth']: + nrsteps = int(log2(r.usersmooth)) + for i in range(nrsteps): + rowdata[column] = stravastuff.ewmovingaverage(rowdata[column],5) + except KeyError: + pass + + if len(rowdata)<2: rowdata = dataprep.getsmallrowdata_db(columns,ids=[id],doclean=True, diff --git a/rowers/metrics.py b/rowers/metrics.py index 9b86d3ce..cdd0199b 100644 --- a/rowers/metrics.py +++ b/rowers/metrics.py @@ -11,7 +11,7 @@ import pandas as pd from scipy import optimize from django.utils import timezone -from math import log10 +from math import log10,log2 from rowers.mytypes import otwtypes,otetypes nometrics = [ @@ -58,6 +58,7 @@ rowingmetrics = ( 'mode':'both', 'type': 'basic', 'group':'basic', + 'maysmooth': False, 'sigfigs': -1}), ('hr',{ @@ -68,6 +69,7 @@ rowingmetrics = ( 'ax_max': 200, 'mode':'both', 'type': 'basic', + 'maysmooth': False, 'group':'athlete', 'sigfigs':0,}), @@ -80,6 +82,7 @@ rowingmetrics = ( 'mode':'both', 'type': 'basic', 'sigfigs': 1, + 'maysmooth': True, 'group': 'basic'}), ('velo',{ @@ -91,6 +94,7 @@ rowingmetrics = ( 'default': 0, 'mode':'both', 'sigfigs': 1, + 'maysmooth': True, 'type':'pro', 'group': 'basic'}), @@ -113,6 +117,7 @@ rowingmetrics = ( 'mode':'both', 'sigfigs': 1, 'type': 'basic', + 'maysmooth': True, 'group':'basic'}), ('driveenergy',{ @@ -124,6 +129,7 @@ rowingmetrics = ( 'mode':'both', 'sigfigs': 0, 'type': 'pro', + 'maysmooth': True, 'group':'forcepower'}), ('power',{ @@ -135,6 +141,7 @@ rowingmetrics = ( 'mode':'both', 'sigfigs': 0, 'type': 'basic', + 'maysmooth': True, 'group':'forcepower'}), ('averageforce',{ @@ -145,6 +152,7 @@ rowingmetrics = ( 'ax_max': 1200, 'mode':'both', 'sigfigs': 0, + 'maysmooth': True, 'type': 'pro', 'group':'forcepower'}), @@ -156,6 +164,7 @@ rowingmetrics = ( 'ax_max': 1500, 'sigfigs': 0, 'mode':'both', + 'maysmooth': True, 'type': 'pro', 'group':'forcepower'}), @@ -167,6 +176,7 @@ rowingmetrics = ( 'ax_max': 2.5, 'mode':'rower', 'sigfigs': 2, + 'maysmooth': False, 'type': 'pro', 'group':'stroke'}), @@ -177,6 +187,7 @@ rowingmetrics = ( 'ax_min': 0, 'ax_max': 1, 'sigfigs': 2, + 'maysmooth': True, 'mode':'both', 'type': 'pro', 'group': 'forcepower'}), @@ -189,6 +200,7 @@ rowingmetrics = ( 'ax_max': 1e5, 'sigfigs': 0, 'mode':'both', + 'maysmooth': False, 'type': 'basic', 'group':'basic'}), @@ -200,6 +212,7 @@ rowingmetrics = ( 'ax_max': 1e5, 'mode':'both', 'sigfigs': 0, + 'maysmooth': False, 'type': 'basic', 'group':'basic'}), @@ -211,6 +224,7 @@ rowingmetrics = ( 'ax_max': 4, 'default': 0, 'sigfigs': 2, + 'maysmooth': True, 'mode':'both', 'type': 'pro', 'group': 'stroke'}), @@ -225,6 +239,7 @@ rowingmetrics = ( 'default': 0, 'sigfigs': 0, 'mode':'water', + 'maysmooth': True, 'type': 'pro', 'group': 'stroke'}), @@ -236,6 +251,7 @@ rowingmetrics = ( 'ax_max': 20, 'default': 0, 'sigfigs': 1, + 'maysmooth': True, 'mode':'water', 'type': 'pro', 'group': 'stroke'}), @@ -248,6 +264,7 @@ rowingmetrics = ( 'ax_max': 55, 'default': 0, 'sigfigs': 0, + 'maysmooth': True, 'mode':'water', 'type': 'pro', 'group': 'stroke'}), @@ -260,6 +277,7 @@ rowingmetrics = ( 'ax_max': 30, 'default': 0, 'sigfigs': 1, + 'maysmooth': True, 'mode':'water', 'type': 'pro', 'group': 'stroke'}), @@ -272,6 +290,7 @@ rowingmetrics = ( 'ax_max': 50, 'default': 0, 'sigfigs': 0, + 'maysmooth': True, 'mode':'water', 'type': 'pro', 'group':'stroke'}), @@ -285,6 +304,7 @@ rowingmetrics = ( 'ax_max': 140, 'default': 0, 'sigfigs': 0, + 'maysmooth': True, 'mode':'water', 'type': 'pro', 'group':'stroke'}), @@ -299,6 +319,7 @@ rowingmetrics = ( 'default': 0, 'sigfigs': 0, 'mode':'water', + 'maysmooth': True, 'type': 'pro', 'group':'stroke'}), @@ -311,6 +332,7 @@ rowingmetrics = ( 'default': 1.0, 'sigfigs': 0, 'mode':'erg', + 'maysmooth': True, 'type': 'pro', 'group':'stroke'}), @@ -323,6 +345,7 @@ rowingmetrics = ( 'default': 0, 'sigfigs': 0, 'mode':'water', + 'maysmooth': True, 'type': 'pro', 'group':'forcepower'}), @@ -334,12 +357,19 @@ rowingmetrics = ( 'ax_max': 15, 'default': 0, 'sigfigs': 1, + 'maysmooth': True, 'mode':'both', 'type': 'basic', 'group':'basic'}), ) +metricsdicts = {} +for key,dict in rowingmetrics: + metricsdicts[key] = dict + + + metricsgroups = list(set([d['group'] for n,d in rowingmetrics])) dtypes = {} diff --git a/rowers/models.py b/rowers/models.py index 1e6e9e00..e9fb16cd 100644 --- a/rowers/models.py +++ b/rowers/models.py @@ -84,6 +84,14 @@ favanalysischoices = ( ('cp','Critical Power'), ) +smoothingchoices = ( + (1,1), + (2,2), + (4,4), + (8,8), + (16,16), +) + def half_year_from_now(): return (datetime.datetime.now(tz=timezone.utc)+timezone.timedelta(days=182)).date() @@ -991,6 +999,9 @@ class Rower(models.Model): max_length=100, verbose_name='Favorite Analysis') + usersmooth = models.IntegerField(default=1,choices=smoothingchoices, + verbose_name="Chart Smoothing") + staticchartonupload = models.CharField(default='None',choices=plotchoices, max_length=100, verbose_name='Generate a static chart automatically on upload') @@ -3778,6 +3789,7 @@ class AccountRowerForm(ModelForm): 'getimportantemails', 'defaulttimezone','showfavoritechartnotes', 'fav_analysis', + 'usersmooth', 'defaultlandingpage', 'offercoaching','autojoin','emailalternatives'] @@ -3817,7 +3829,7 @@ class AccountRowerForm(ModelForm): class StaticChartRowerForm(ModelForm): class Meta: model = Rower - fields = ['staticgrids','slowpaceerg','fastpaceerg','slowpaceotw','fastpaceotw','staticchartonupload','fav_analysis'] + fields = ['usersmooth','staticgrids','slowpaceerg','fastpaceerg','slowpaceotw','fastpaceotw','staticchartonupload','fav_analysis'] def __init__(self, *args, **kwargs): super(StaticChartRowerForm, self).__init__(*args, **kwargs) diff --git a/rowers/tests/test_user.py b/rowers/tests/test_user.py index 3199249b..998beea4 100644 --- a/rowers/tests/test_user.py +++ b/rowers/tests/test_user.py @@ -114,6 +114,7 @@ class UserPreferencesTest(TestCase): 'defaulttimezone':'UTC', 'showfavoritechartnotes':False, 'fav_analysis':'compare', + 'usersmooth':2, 'defaultlandingpage':'workout_edit_view', 'first_name': self.u.first_name, 'last_name': self.u.last_name, diff --git a/rowers/views/userviews.py b/rowers/views/userviews.py index ab4f66a4..afa15a28 100644 --- a/rowers/views/userviews.py +++ b/rowers/views/userviews.py @@ -247,6 +247,7 @@ def rower_favoritecharts_view(request,userid=0): r.fastpaceotw = staticchartform.cleaned_data.get('fastpaceotw') r.staticchartonupload = staticchartform.cleaned_data.get('staticchartonupload') r.fav_analysis = staticchartform.cleaned_data.get('fav_analysis') + r.usersmooth = staticchartform.cleaned_data.get('usersmooth') r.save() if request.method == 'POST' and 'form-TOTAL_FORMS' in request.POST: @@ -406,6 +407,7 @@ def rower_edit_view(request,rowerid=0,userid=0,message=""): getimportantemails = cd['getimportantemails'] defaulttimezone=cd['defaulttimezone'] fav_analysis = cd['fav_analysis'] + usersmooth = cd['usersmooth'] u = r.user if u.email != email and len(email): resetbounce = True @@ -434,6 +436,7 @@ def rower_edit_view(request,rowerid=0,userid=0,message=""): r.autojoin = autojoin r.emailalternatives = emailalternatives r.fav_analysis = fav_analysis + r.usersmooth = usersmooth if resetbounce and r.emailbounced: