From 2221a633b1bb01f1a972f2c8b6f7673c3d1664fa Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Thu, 15 Feb 2018 16:32:33 +0100 Subject: [PATCH] test type plannedsessions now have a ranking --- rowers/models.py | 13 +++- rowers/plannedsessions.py | 18 ++++- rowers/templates/.#list_workouts.html | 1 + rowers/templates/plannedsessioncreate.html | 2 + rowers/templates/plannedsessionedit.html | 2 + .../templates/plannedsessionteamcreate.html | 70 +++++++++++++++++++ rowers/templates/plannedsessionteamedit.html | 70 +++++++++++++++++++ rowers/templates/plannedsessionview.html | 27 +++++++ rowers/urls.py | 2 + rowers/views.py | 31 ++++++-- 10 files changed, 228 insertions(+), 8 deletions(-) create mode 100644 rowers/templates/.#list_workouts.html diff --git a/rowers/models.py b/rowers/models.py index b62f0f78..6d380cc2 100644 --- a/rowers/models.py +++ b/rowers/models.py @@ -825,7 +825,6 @@ class PlannedSession(models.Model): sessionunitchoices = ( ('min','minutes'), - ('km','km'), ('m','meters'), ('None',None), ) @@ -904,7 +903,17 @@ class PlannedSession(models.Model): self.sessionunit = 'min' else: self.sessionunit = 'None' - + + if self.sessiontype == 'test': + if self.sessionmode not in ['distance','time']: + if self.sessionvalue < 100: + self.sessionmode = 'time' + self.sessionunit = 'min' + else: + self.sessionmode = 'distance' + self.sessionunit = 'm' + self.criterium = 'exact' + super(PlannedSession,self).save(*args, **kwargs) # Date input utility diff --git a/rowers/plannedsessions.py b/rowers/plannedsessions.py index aaf54676..aaf15c23 100644 --- a/rowers/plannedsessions.py +++ b/rowers/plannedsessions.py @@ -26,7 +26,7 @@ import numpy as np import dataprep # Low Level functions - to be called by higher level methods -def add_workouts_plannedsession(ws,ps): +def add_workouts_plannedsession(ws,ps,r): result = 0 comments = [] errors = [] @@ -36,6 +36,20 @@ def add_workouts_plannedsession(ws,ps): if (not all(d == dates[0] for d in dates)) and ps.sessiontype not in ['challenge','cycletarget']: errors.append('For tests and training sessions, selected workouts must all be done on the same date') return result,comments,errors + + if len(ws)>1 and ps.sessiontype == 'test': + errors.append('For tests, you can only attach one workout') + return result,comments,errors + + + + wold = Workout.objects.filter(plannedsession=ps,user=r) + ids = [w.id for w in wold] + [w.id for w in ws] + ids = list(set(ids)) + + if len(ids)>1 and ps.sessiontype == 'test': + errors.append('For tests, you can only attach one workout') + return result,comments,errors # start adding sessions for w in ws: @@ -99,7 +113,7 @@ def get_session_metrics(ps): rscorev += dataprep.workout_rscore(w)[0] ratio,statusv = is_session_complete_ws(ws,ps) - completedatev = ws[0].date.strftime('%Y-%b-%d') + completedatev = ws[0].date.strftime('%Y-%m-%d') durationv /= 60. trimp.append(int(trimpv)) diff --git a/rowers/templates/.#list_workouts.html b/rowers/templates/.#list_workouts.html new file mode 100644 index 00000000..656119b2 --- /dev/null +++ b/rowers/templates/.#list_workouts.html @@ -0,0 +1 @@ +e408191@CZ27LT9RCGN72.36632:1518629534 \ No newline at end of file diff --git a/rowers/templates/plannedsessioncreate.html b/rowers/templates/plannedsessioncreate.html index d36fe8e8..6a03f149 100644 --- a/rowers/templates/plannedsessioncreate.html +++ b/rowers/templates/plannedsessioncreate.html @@ -155,6 +155,8 @@ } if (this.value == 'test') { $("td #id_criterium").prop("value","exact"); + $("td #id_sessionmode").prop("value","distance"); + $("td #id_sessionunit").prop("value","m"); } if (this.value == 'challenge') { $("td #id_criterium").prop("value","minimum"); diff --git a/rowers/templates/plannedsessionedit.html b/rowers/templates/plannedsessionedit.html index ff679912..9021105f 100644 --- a/rowers/templates/plannedsessionedit.html +++ b/rowers/templates/plannedsessionedit.html @@ -160,6 +160,8 @@ } if (this.value == 'test') { $("td #id_criterium").prop("value","exact"); + $("td #id_sessionmode").prop("value","distance"); + $("td #id_sessionunit").prop("value","m"); } if (this.value == 'challenge') { $("td #id_criterium").prop("value","minimum"); diff --git a/rowers/templates/plannedsessionteamcreate.html b/rowers/templates/plannedsessionteamcreate.html index 2ecb9a80..24169c2e 100644 --- a/rowers/templates/plannedsessionteamcreate.html +++ b/rowers/templates/plannedsessionteamcreate.html @@ -119,3 +119,73 @@ {% endblock %} + +{% block scripts %} + + +{% endblock %} diff --git a/rowers/templates/plannedsessionteamedit.html b/rowers/templates/plannedsessionteamedit.html index 774a4218..0dbf27b6 100644 --- a/rowers/templates/plannedsessionteamedit.html +++ b/rowers/templates/plannedsessionteamedit.html @@ -135,3 +135,73 @@ {% endblock %} + +{% block scripts %} + + +{% endblock %} diff --git a/rowers/templates/plannedsessionview.html b/rowers/templates/plannedsessionview.html index 96bca094..2ee8c3d6 100644 --- a/rowers/templates/plannedsessionview.html +++ b/rowers/templates/plannedsessionview.html @@ -39,6 +39,33 @@