Private
Public Access
1
0

Merge branch 'feature/plancompare' into develop

This commit is contained in:
Sander Roosendaal
2022-04-12 10:01:40 +02:00
5 changed files with 53 additions and 19 deletions

View File

@@ -1805,6 +1805,26 @@ class TrainingPlan(models.Model):
else:
createmacrofillers(self)
def length(self):
startdate = self.startdate
enddate = self.enddate
return (enddate-startdate).days
def overlap(self,startdate,enddate):
is_overlapped = max(self.startdate, startdate) < min(self.enddate, enddate)
if not is_overlapped:
return 0
if startdate >= self.startdate:
if self.enddate >= enddate:
return (enddate-startdate).days
else:
return (self.enddate-startdate).days
elif startdate < self.startdate:
if enddate >= self.enddate:
return (self.enddate-self.startdate).days
else:
return (enddate-self.startdate).days
def check_trainingplan_on_change(sender, **kwargs):
instance = kwargs.pop('instance', None)

View File

@@ -202,30 +202,21 @@ def get_execution_report(rower, startdate, enddate, plan=None):
micros = micros.exclude(enddate__lte=startdate).exclude(
startdate__gte=enddate)
else: # pragma: no cover
plans = TrainingPlan.objects.filter(
startdate__lte=startdate, enddate__gte=startdate)
plans2 = TrainingPlan.objects.filter(
enddate__lte=enddate, startdate__lte=enddate)
plans = plans | plans2
plans = TrainingPlan.objects.filter(rowers__in=[rower])
#plans2 = TrainingPlan.objects.filter(
# enddate__lte=enddate, startdate__lte=enddate, rowers__in=[rower])
#plans = plans | plans2
plans = plans.exclude(status=False).order_by("-enddate")
#plans = plans.exclude(status=False).order_by("-enddate")
if not plans:
# make week cycles here
# get monday before startdate
startdate += timedelta(days=1-startdate.isoweekday())
startdate = startdate-timedelta(days=7)
micros = []
while startdate <= enddate:
micro = type('micros', (object,),
{
'startdate': startdate,
'enddate': startdate+timedelta(days=7)
})
micros.append(micro)
startdate += timedelta(days=7)
else:
plan = plans[0]
sorted_plans = sorted(plans, key= lambda t: t.overlap(startdate,enddate))
plan = plans.reverse()[0]
macros = TrainingMacroCycle.objects.filter(
plan=plan).order_by("startdate")
checkscores(rower, macros)
@@ -237,11 +228,26 @@ def get_execution_report(rower, startdate, enddate, plan=None):
startdate__lte=enddate,
).order_by("startdate")
if len(micros)==0:
startdate += timedelta(days=1-startdate.isoweekday())
startdate = startdate-timedelta(days=7)
micros = []
while startdate <= enddate:
micro = type('micros', (object,),
{
'startdate': startdate,
'enddate': startdate+timedelta(days=7)
})
micros.append(micro)
startdate += timedelta(days=7)
# we've got micros, now get sessions
startdates = []
planned = []
executed = []
for mm in micros:
plannedscore = 0
actualscore = 0

View File

@@ -39,6 +39,8 @@
<th align="left">Private/Shared</th>
<th align="left">Edit</th>
<th align="left">Copy to Calendar</th>
<th align="left">Share</th>
<th align="left">Lock</th>
<th align="left">Delete</th>
</tr>
</thead>

View File

@@ -32,7 +32,7 @@
{% if plan|mayeditplan:request %}
<p><a href="/rowers/editplan/{{ plan.id }}">Edit the plan</a></p>
{% endif %}
<p><a href="/rowers/plan/{{ plan.id }}/execution/">Plan vs Actual chart</a></p>
<p><a href="/rowers/plan/{{ plan.id }}/execution/?when={{ plan.startdate|date:'Y-m-d' }}/{{ plan.enddate|date:'Y-m-d' }}/">Plan vs Actual chart</a></p>
<p><a href="/rowers/sessions/user/{{ rower.user.id }}?when={{ plan.startdate|date:'Y-m-d' }}/{{ plan.enddate|date:'Y-m-d' }}/">
View all sessions
</a>

View File

@@ -1414,6 +1414,13 @@ def save_plan_yaml(request, userid=0):
ps.interval_string = '{d}m'.format(d=ps.sessionvalue)
elif ps.sessionmode == 'time':
ps.interval_string = '{d}min'.format(d=ps.sessionvalue)
elif ps.sessionmode == 'rScore':
print('aap')
ps.approximate_duration = ps.sessionvalue
ps.interval_string = '{d}min'.format(d=ps.sessionvalue)
elif ps.sessionmode == 'TRIMP':
ps.approximate_duration = int(ps.sessionvalue/2.)
ps.interval_string = '{d}min'.format(d=int(ps.sessionvalue/2.))
ps.fitfile = ''
ps.steps = None
ps.save()
@@ -1421,7 +1428,6 @@ def save_plan_yaml(request, userid=0):
steps = ps_reload.steps
steps['filename'] = ""
steps['workoutName'] = ps.name
print(steps)
workouts.append(steps)
trainingdays.append({'order': i+1, 'workouts': workouts})