Private
Public Access
1
0

Merge branch 'feature/usersmooth' into develop

This commit is contained in:
Sander Roosendaal
2020-11-04 21:51:20 +01:00
5 changed files with 63 additions and 3 deletions

View File

@@ -13,7 +13,7 @@ from rowingdata import main as rmain
from rowingdata import cumcpdata,histodata from rowingdata import cumcpdata,histodata
from rowingdata import rowingdata as rrdata from rowingdata import rowingdata as rrdata
from math import pi from math import pi,log2
from django.utils import timezone from django.utils import timezone
from rowingdata import make_cumvalues from rowingdata import make_cumvalues
@@ -79,6 +79,7 @@ from scipy.interpolate import griddata
import rowers.stravastuff as stravastuff import rowers.stravastuff as stravastuff
from rowers.metrics import rowingmetrics,metricsdicts
from rowers.dataprep import rdata from rowers.dataprep import rdata
import rowers.dataprep as dataprep 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, rowdata = dataprep.getsmallrowdata_db(columns,ids=[id],doclean=True,
workstrokesonly=workstrokesonly) 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: if len(rowdata)<2:
rowdata = dataprep.getsmallrowdata_db(columns,ids=[id],doclean=True, rowdata = dataprep.getsmallrowdata_db(columns,ids=[id],doclean=True,

View File

@@ -11,7 +11,7 @@ import pandas as pd
from scipy import optimize from scipy import optimize
from django.utils import timezone from django.utils import timezone
from math import log10 from math import log10,log2
from rowers.mytypes import otwtypes,otetypes from rowers.mytypes import otwtypes,otetypes
nometrics = [ nometrics = [
@@ -58,6 +58,7 @@ rowingmetrics = (
'mode':'both', 'mode':'both',
'type': 'basic', 'type': 'basic',
'group':'basic', 'group':'basic',
'maysmooth': False,
'sigfigs': -1}), 'sigfigs': -1}),
('hr',{ ('hr',{
@@ -68,6 +69,7 @@ rowingmetrics = (
'ax_max': 200, 'ax_max': 200,
'mode':'both', 'mode':'both',
'type': 'basic', 'type': 'basic',
'maysmooth': False,
'group':'athlete', 'group':'athlete',
'sigfigs':0,}), 'sigfigs':0,}),
@@ -80,6 +82,7 @@ rowingmetrics = (
'mode':'both', 'mode':'both',
'type': 'basic', 'type': 'basic',
'sigfigs': 1, 'sigfigs': 1,
'maysmooth': True,
'group': 'basic'}), 'group': 'basic'}),
('velo',{ ('velo',{
@@ -91,6 +94,7 @@ rowingmetrics = (
'default': 0, 'default': 0,
'mode':'both', 'mode':'both',
'sigfigs': 1, 'sigfigs': 1,
'maysmooth': True,
'type':'pro', 'type':'pro',
'group': 'basic'}), 'group': 'basic'}),
@@ -113,6 +117,7 @@ rowingmetrics = (
'mode':'both', 'mode':'both',
'sigfigs': 1, 'sigfigs': 1,
'type': 'basic', 'type': 'basic',
'maysmooth': True,
'group':'basic'}), 'group':'basic'}),
('driveenergy',{ ('driveenergy',{
@@ -124,6 +129,7 @@ rowingmetrics = (
'mode':'both', 'mode':'both',
'sigfigs': 0, 'sigfigs': 0,
'type': 'pro', 'type': 'pro',
'maysmooth': True,
'group':'forcepower'}), 'group':'forcepower'}),
('power',{ ('power',{
@@ -135,6 +141,7 @@ rowingmetrics = (
'mode':'both', 'mode':'both',
'sigfigs': 0, 'sigfigs': 0,
'type': 'basic', 'type': 'basic',
'maysmooth': True,
'group':'forcepower'}), 'group':'forcepower'}),
('averageforce',{ ('averageforce',{
@@ -145,6 +152,7 @@ rowingmetrics = (
'ax_max': 1200, 'ax_max': 1200,
'mode':'both', 'mode':'both',
'sigfigs': 0, 'sigfigs': 0,
'maysmooth': True,
'type': 'pro', 'type': 'pro',
'group':'forcepower'}), 'group':'forcepower'}),
@@ -156,6 +164,7 @@ rowingmetrics = (
'ax_max': 1500, 'ax_max': 1500,
'sigfigs': 0, 'sigfigs': 0,
'mode':'both', 'mode':'both',
'maysmooth': True,
'type': 'pro', 'type': 'pro',
'group':'forcepower'}), 'group':'forcepower'}),
@@ -167,6 +176,7 @@ rowingmetrics = (
'ax_max': 2.5, 'ax_max': 2.5,
'mode':'rower', 'mode':'rower',
'sigfigs': 2, 'sigfigs': 2,
'maysmooth': False,
'type': 'pro', 'type': 'pro',
'group':'stroke'}), 'group':'stroke'}),
@@ -177,6 +187,7 @@ rowingmetrics = (
'ax_min': 0, 'ax_min': 0,
'ax_max': 1, 'ax_max': 1,
'sigfigs': 2, 'sigfigs': 2,
'maysmooth': True,
'mode':'both', 'mode':'both',
'type': 'pro', 'type': 'pro',
'group': 'forcepower'}), 'group': 'forcepower'}),
@@ -189,6 +200,7 @@ rowingmetrics = (
'ax_max': 1e5, 'ax_max': 1e5,
'sigfigs': 0, 'sigfigs': 0,
'mode':'both', 'mode':'both',
'maysmooth': False,
'type': 'basic', 'type': 'basic',
'group':'basic'}), 'group':'basic'}),
@@ -200,6 +212,7 @@ rowingmetrics = (
'ax_max': 1e5, 'ax_max': 1e5,
'mode':'both', 'mode':'both',
'sigfigs': 0, 'sigfigs': 0,
'maysmooth': False,
'type': 'basic', 'type': 'basic',
'group':'basic'}), 'group':'basic'}),
@@ -211,6 +224,7 @@ rowingmetrics = (
'ax_max': 4, 'ax_max': 4,
'default': 0, 'default': 0,
'sigfigs': 2, 'sigfigs': 2,
'maysmooth': True,
'mode':'both', 'mode':'both',
'type': 'pro', 'type': 'pro',
'group': 'stroke'}), 'group': 'stroke'}),
@@ -225,6 +239,7 @@ rowingmetrics = (
'default': 0, 'default': 0,
'sigfigs': 0, 'sigfigs': 0,
'mode':'water', 'mode':'water',
'maysmooth': True,
'type': 'pro', 'type': 'pro',
'group': 'stroke'}), 'group': 'stroke'}),
@@ -236,6 +251,7 @@ rowingmetrics = (
'ax_max': 20, 'ax_max': 20,
'default': 0, 'default': 0,
'sigfigs': 1, 'sigfigs': 1,
'maysmooth': True,
'mode':'water', 'mode':'water',
'type': 'pro', 'type': 'pro',
'group': 'stroke'}), 'group': 'stroke'}),
@@ -248,6 +264,7 @@ rowingmetrics = (
'ax_max': 55, 'ax_max': 55,
'default': 0, 'default': 0,
'sigfigs': 0, 'sigfigs': 0,
'maysmooth': True,
'mode':'water', 'mode':'water',
'type': 'pro', 'type': 'pro',
'group': 'stroke'}), 'group': 'stroke'}),
@@ -260,6 +277,7 @@ rowingmetrics = (
'ax_max': 30, 'ax_max': 30,
'default': 0, 'default': 0,
'sigfigs': 1, 'sigfigs': 1,
'maysmooth': True,
'mode':'water', 'mode':'water',
'type': 'pro', 'type': 'pro',
'group': 'stroke'}), 'group': 'stroke'}),
@@ -272,6 +290,7 @@ rowingmetrics = (
'ax_max': 50, 'ax_max': 50,
'default': 0, 'default': 0,
'sigfigs': 0, 'sigfigs': 0,
'maysmooth': True,
'mode':'water', 'mode':'water',
'type': 'pro', 'type': 'pro',
'group':'stroke'}), 'group':'stroke'}),
@@ -285,6 +304,7 @@ rowingmetrics = (
'ax_max': 140, 'ax_max': 140,
'default': 0, 'default': 0,
'sigfigs': 0, 'sigfigs': 0,
'maysmooth': True,
'mode':'water', 'mode':'water',
'type': 'pro', 'type': 'pro',
'group':'stroke'}), 'group':'stroke'}),
@@ -299,6 +319,7 @@ rowingmetrics = (
'default': 0, 'default': 0,
'sigfigs': 0, 'sigfigs': 0,
'mode':'water', 'mode':'water',
'maysmooth': True,
'type': 'pro', 'type': 'pro',
'group':'stroke'}), 'group':'stroke'}),
@@ -311,6 +332,7 @@ rowingmetrics = (
'default': 1.0, 'default': 1.0,
'sigfigs': 0, 'sigfigs': 0,
'mode':'erg', 'mode':'erg',
'maysmooth': True,
'type': 'pro', 'type': 'pro',
'group':'stroke'}), 'group':'stroke'}),
@@ -323,6 +345,7 @@ rowingmetrics = (
'default': 0, 'default': 0,
'sigfigs': 0, 'sigfigs': 0,
'mode':'water', 'mode':'water',
'maysmooth': True,
'type': 'pro', 'type': 'pro',
'group':'forcepower'}), 'group':'forcepower'}),
@@ -334,12 +357,19 @@ rowingmetrics = (
'ax_max': 15, 'ax_max': 15,
'default': 0, 'default': 0,
'sigfigs': 1, 'sigfigs': 1,
'maysmooth': True,
'mode':'both', 'mode':'both',
'type': 'basic', 'type': 'basic',
'group':'basic'}), 'group':'basic'}),
) )
metricsdicts = {}
for key,dict in rowingmetrics:
metricsdicts[key] = dict
metricsgroups = list(set([d['group'] for n,d in rowingmetrics])) metricsgroups = list(set([d['group'] for n,d in rowingmetrics]))
dtypes = {} dtypes = {}

View File

@@ -84,6 +84,14 @@ favanalysischoices = (
('cp','Critical Power'), ('cp','Critical Power'),
) )
smoothingchoices = (
(1,1),
(2,2),
(4,4),
(8,8),
(16,16),
)
def half_year_from_now(): def half_year_from_now():
return (datetime.datetime.now(tz=timezone.utc)+timezone.timedelta(days=182)).date() return (datetime.datetime.now(tz=timezone.utc)+timezone.timedelta(days=182)).date()
@@ -991,6 +999,9 @@ class Rower(models.Model):
max_length=100, max_length=100,
verbose_name='Favorite Analysis') verbose_name='Favorite Analysis')
usersmooth = models.IntegerField(default=1,choices=smoothingchoices,
verbose_name="Chart Smoothing")
staticchartonupload = models.CharField(default='None',choices=plotchoices, staticchartonupload = models.CharField(default='None',choices=plotchoices,
max_length=100, max_length=100,
verbose_name='Generate a static chart automatically on upload') verbose_name='Generate a static chart automatically on upload')
@@ -3778,6 +3789,7 @@ class AccountRowerForm(ModelForm):
'getimportantemails', 'getimportantemails',
'defaulttimezone','showfavoritechartnotes', 'defaulttimezone','showfavoritechartnotes',
'fav_analysis', 'fav_analysis',
'usersmooth',
'defaultlandingpage', 'defaultlandingpage',
'offercoaching','autojoin','emailalternatives'] 'offercoaching','autojoin','emailalternatives']
@@ -3817,7 +3829,7 @@ class AccountRowerForm(ModelForm):
class StaticChartRowerForm(ModelForm): class StaticChartRowerForm(ModelForm):
class Meta: class Meta:
model = Rower 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): def __init__(self, *args, **kwargs):
super(StaticChartRowerForm, self).__init__(*args, **kwargs) super(StaticChartRowerForm, self).__init__(*args, **kwargs)

View File

@@ -114,6 +114,7 @@ class UserPreferencesTest(TestCase):
'defaulttimezone':'UTC', 'defaulttimezone':'UTC',
'showfavoritechartnotes':False, 'showfavoritechartnotes':False,
'fav_analysis':'compare', 'fav_analysis':'compare',
'usersmooth':2,
'defaultlandingpage':'workout_edit_view', 'defaultlandingpage':'workout_edit_view',
'first_name': self.u.first_name, 'first_name': self.u.first_name,
'last_name': self.u.last_name, 'last_name': self.u.last_name,

View File

@@ -247,6 +247,7 @@ def rower_favoritecharts_view(request,userid=0):
r.fastpaceotw = staticchartform.cleaned_data.get('fastpaceotw') r.fastpaceotw = staticchartform.cleaned_data.get('fastpaceotw')
r.staticchartonupload = staticchartform.cleaned_data.get('staticchartonupload') r.staticchartonupload = staticchartform.cleaned_data.get('staticchartonupload')
r.fav_analysis = staticchartform.cleaned_data.get('fav_analysis') r.fav_analysis = staticchartform.cleaned_data.get('fav_analysis')
r.usersmooth = staticchartform.cleaned_data.get('usersmooth')
r.save() r.save()
if request.method == 'POST' and 'form-TOTAL_FORMS' in request.POST: if request.method == 'POST' and 'form-TOTAL_FORMS' in request.POST:
@@ -405,6 +406,8 @@ def rower_edit_view(request,rowerid=0,userid=0,message=""):
getemailnotifications = cd['getemailnotifications'] getemailnotifications = cd['getemailnotifications']
getimportantemails = cd['getimportantemails'] getimportantemails = cd['getimportantemails']
defaulttimezone=cd['defaulttimezone'] defaulttimezone=cd['defaulttimezone']
fav_analysis = cd['fav_analysis']
usersmooth = cd['usersmooth']
u = r.user u = r.user
if u.email != email and len(email): if u.email != email and len(email):
resetbounce = True resetbounce = True
@@ -432,6 +435,8 @@ def rower_edit_view(request,rowerid=0,userid=0,message=""):
r.birthdate = birthdate r.birthdate = birthdate
r.autojoin = autojoin r.autojoin = autojoin
r.emailalternatives = emailalternatives r.emailalternatives = emailalternatives
r.fav_analysis = fav_analysis
r.usersmooth = usersmooth
if resetbounce and r.emailbounced: if resetbounce and r.emailbounced: