From 3d06bf5ad17091474d261f00aa190d677bc0ce29 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Wed, 31 Oct 2018 10:33:47 +0100 Subject: [PATCH 1/6] in side menu show only plans that are in today's range --- rowers/models.py | 6 ++++-- rowers/templatetags/rowerfilters.py | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/rowers/models.py b/rowers/models.py index 14aec8d2..cafcc47b 100644 --- a/rowers/models.py +++ b/rowers/models.py @@ -945,6 +945,7 @@ class TrainingTarget(models.Model): def __unicode__(self): date = self.date name = self.name + id = self.pk try: ownerfirst = self.manager.user.first_name ownerlast = self.manager.user.last_name @@ -952,11 +953,12 @@ class TrainingTarget(models.Model): ownerfirst = '' ownerlast = '' - stri = u'{ownerfirst} {ownerlast} {d} {n}'.format( + stri = u'{id} {n} {d} {ownerfirst} {ownerlast}'.format( ownerfirst = ownerfirst, ownerlast = ownerlast, d = date.strftime('%Y-%m-%d'), - n = name + n = name, + id = id, ) return stri diff --git a/rowers/templatetags/rowerfilters.py b/rowers/templatetags/rowerfilters.py index 1707661d..7f4334eb 100644 --- a/rowers/templatetags/rowerfilters.py +++ b/rowers/templatetags/rowerfilters.py @@ -397,9 +397,12 @@ def timeurl(path,timestring): @register.filter def trainingplans(rower): + today = datetime.date.today() plans = TrainingPlan.objects.filter( rowers=rower, - status=True).order_by("-startdate") + status=True, + startdate__lte=today, + enddate__gte=today).order_by("-startdate") return plans From b4255c4e2a6e3bf6a008e18c79acf40675cdcbe2 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Wed, 31 Oct 2018 11:49:23 +0100 Subject: [PATCH 2/6] target unicode representation and target selection --- rowers/models.py | 2 +- rowers/views.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/rowers/models.py b/rowers/models.py index cafcc47b..b0d71fb0 100644 --- a/rowers/models.py +++ b/rowers/models.py @@ -953,7 +953,7 @@ class TrainingTarget(models.Model): ownerfirst = '' ownerlast = '' - stri = u'{id} {n} {d} {ownerfirst} {ownerlast}'.format( + stri = u'#{id}: {n} {d} {ownerfirst} {ownerlast}'.format( ownerfirst = ownerfirst, ownerlast = ownerlast, d = date.strftime('%Y-%m-%d'), diff --git a/rowers/views.py b/rowers/views.py index 96d76a03..713869b9 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -16188,7 +16188,10 @@ def rower_create_trainingplan(request,userid=0): p.rowers.add(therower) - targets = TrainingTarget.objects.filter(rowers=therower).order_by("date") + targets = TrainingTarget.objects.filter( + rowers=therower, + date__gte=datetime.date.today(), + ).order_by("date") targetform = TrainingTargetForm() plans = TrainingPlan.objects.filter(rowers=therower).order_by("-startdate") From eb773bb7e1c3b130e40099ae9b18ebc488fc13f8 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Wed, 31 Oct 2018 13:20:09 +0100 Subject: [PATCH 3/6] adding cycle notes to training plan --- rowers/models.py | 6 ++++++ rowers/templates/trainingplan.html | 21 +++++++++++++++++++++ rowers/views.py | 2 ++ 3 files changed, 29 insertions(+) diff --git a/rowers/models.py b/rowers/models.py index b0d71fb0..93a1e9cd 100644 --- a/rowers/models.py +++ b/rowers/models.py @@ -1101,6 +1101,12 @@ class TrainingPlanForm(ModelForm): targetchoices = [(x.id,x) for x in targets] targetchoices.append((None,'---')) self.fields['target'].choices = targetchoices + elif self.instance.pk is not None: + self.fields['target'].queryset = TrainingTarget.objects.filter( + manager=self.instance.manager, + date__gte=datetime.date.today()).order_by("date") + else: + self.fields.pop('target') try: teams = Team.objects.filter(manager=self.instance.manager.user) diff --git a/rowers/templates/trainingplan.html b/rowers/templates/trainingplan.html index 1d29b18e..8e2e57d0 100644 --- a/rowers/templates/trainingplan.html +++ b/rowers/templates/trainingplan.html @@ -70,6 +70,13 @@ {{ macrocycle.0.name }} ({{ macrocycle.0.startdate }} - {{ macrocycle.0.enddate }}) + {% if macrocycle.0.notes %} + + + {{ macrocycle.0.notes|linebreaks }} + + + {% endif %} {% if macrocycle.0.type == 'userdefined' and macrocycle.0.plan.status %} @@ -180,6 +187,13 @@ Meso {{ mesocycle.0.name }} ({{ mesocycle.0.startdate }} - {{ mesocycle.0.enddate }}) + {% if mesocycle.0.notes %} + + + {{ mesocycle.0.notes|linebreaks }} + + + {% endif %} {% if mesocycle.0.type == 'userdefined' and mesocycle.0.plan.plan.status %} @@ -299,6 +313,13 @@ Micro {{ microcycle.name }} ({{ microcycle.startdate }} - {{ microcycle.enddate }}) + {% if microcycle.notes %} + + + {{ microcycle.notes|linebreaks }} + + + {% endif %} {% if microcycle.plan.plan.plan.status %} diff --git a/rowers/views.py b/rowers/views.py index 713869b9..f5077146 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -17011,6 +17011,8 @@ class TrainingPlanUpdate(UpdateView): obj = super(TrainingPlanUpdate, self).get_object(*args, **kwargs) if obj.manager is not None and self.request.user.rower != obj.manager: raise PermissionDenied('You are not allowed to edit this training plan cycle') + if obj.manager.rowerplan not in ['coach','plan']: + raise PermissionDenied('You are not allowed to edit this training plan') return obj From fdf399dd4c0cd76453acb5e56d409a6f47a76a87 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Thu, 1 Nov 2018 17:52:43 +0100 Subject: [PATCH 4/6] fixed a bug in rScore calculation --- rowers/tasks.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/rowers/tasks.py b/rowers/tasks.py index 653c5513..c3b7bf41 100644 --- a/rowers/tasks.py +++ b/rowers/tasks.py @@ -580,22 +580,34 @@ def handle_calctrimp(id, df = rowdata.df df['deltat'] = df[' ElapsedTime (sec)'].diff().abs() - duration = df['TimeStamp (sec)'].max()-df['TimeStamp (sec)'].min() - df[' Power (watts)'] = df[' Power (watts)'].abs() + df2 = df.copy() - df['pwr4'] = df[' Power (watts)']**(4.0) - pwr4mean = wavg(df,'pwr4','deltat') - pwrmean = wavg(df,' Power (watts)','deltat') + df2['time'] = df2[' ElapsedTime (sec)'] + df2['time'] = df2['time'].apply( + lambda x:timedelta(seconds=x) + ) + + duration = df['TimeStamp (sec)'].max()-df['TimeStamp (sec)'].min() + df2 = df2.resample('30s',on='time').mean() + + + df2[' Power (watts)'] = df2[' Power (watts)'].abs() + + df2['pwr4'] = df2[' Power (watts)']**(4.0) + # pwr4mean = wavg(df,'pwr4','deltat') + pwr4mean = df2['pwr4'].mean() + pwrmean = df2[' Power (watts)'].mean() + # pwrmean = wavg(df,' Power (watts)','deltat') if pwr4mean > 0: normp = (pwr4mean)**(0.25) else: normp = pwrmean - - intensityfactor = pwrmean/float(ftp) + intensityfactor = normp/float(ftp) tss = 100.*((duration*normp*intensityfactor)/(3600.*ftp)) + if sex == 'male': f = 1.92 else: From 8903040d11fe8cee69b8778a8d777c3189ec5160 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Thu, 1 Nov 2018 19:43:04 +0100 Subject: [PATCH 5/6] refined rScore --- rowers/tasks.py | 6 ++++-- rowers/urls.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/rowers/tasks.py b/rowers/tasks.py index c3b7bf41..d0df13bd 100644 --- a/rowers/tasks.py +++ b/rowers/tasks.py @@ -589,8 +589,9 @@ def handle_calctrimp(id, ) duration = df['TimeStamp (sec)'].max()-df['TimeStamp (sec)'].min() - df2 = df2.resample('30s',on='time').mean() - + df2 = df2.resample('1s',on='time').mean() + df2.fillna(method='ffill',inplace=True) + df2 = df2.rolling(30).mean() df2[' Power (watts)'] = df2[' Power (watts)'].abs() @@ -607,6 +608,7 @@ def handle_calctrimp(id, intensityfactor = normp/float(ftp) tss = 100.*((duration*normp*intensityfactor)/(3600.*ftp)) + print tss if sex == 'male': f = 1.92 diff --git a/rowers/urls.py b/rowers/urls.py index 489b093f..0807ffef 100644 --- a/rowers/urls.py +++ b/rowers/urls.py @@ -170,7 +170,7 @@ urlpatterns = [ url(r'^team-compare-select/workout/(?P\d+)/user/(?P\d+)/$',views.team_comparison_select), url(r'^team-compare-select/team/(?P\d+)/user/(?P\d+)/$',views.team_comparison_select), url(r'^team-compare-select/workout/(?P\d+)/$',views.team_comparison_select), - url(r'^team-compare-select/team/(?P\d+)$',views.team_comparison_select), + url(r'^team-compare-select/team/(?P\d+)/$',views.team_comparison_select), url(r'^team-compare-select/$',views.team_comparison_select), url(r'^workouts-join-select/team/(?P\d+)/(?P\d+-\d+-\d+)/(?P\d+-\d+-\d+)$',views.workouts_join_select), url(r'^workouts-join$',views.workouts_join_view), From 40941bc6d6609fc02593b7f3a506ce2f085e1ad2 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Thu, 1 Nov 2018 19:44:02 +0100 Subject: [PATCH 6/6] removing some debugging code --- rowers/tasks.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/rowers/tasks.py b/rowers/tasks.py index d0df13bd..fbe58f3f 100644 --- a/rowers/tasks.py +++ b/rowers/tasks.py @@ -608,8 +608,6 @@ def handle_calctrimp(id, intensityfactor = normp/float(ftp) tss = 100.*((duration*normp*intensityfactor)/(3600.*ftp)) - print tss - if sex == 'male': f = 1.92 else: