better plan actual comparison
This commit is contained in:
@@ -1805,6 +1805,26 @@ class TrainingPlan(models.Model):
|
|||||||
else:
|
else:
|
||||||
createmacrofillers(self)
|
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):
|
def check_trainingplan_on_change(sender, **kwargs):
|
||||||
instance = kwargs.pop('instance', None)
|
instance = kwargs.pop('instance', None)
|
||||||
|
|||||||
@@ -202,30 +202,21 @@ def get_execution_report(rower, startdate, enddate, plan=None):
|
|||||||
micros = micros.exclude(enddate__lte=startdate).exclude(
|
micros = micros.exclude(enddate__lte=startdate).exclude(
|
||||||
startdate__gte=enddate)
|
startdate__gte=enddate)
|
||||||
else: # pragma: no cover
|
else: # pragma: no cover
|
||||||
plans = TrainingPlan.objects.filter(
|
plans = TrainingPlan.objects.filter(rowers__in=[rower])
|
||||||
startdate__lte=startdate, enddate__gte=startdate)
|
#plans2 = TrainingPlan.objects.filter(
|
||||||
plans2 = TrainingPlan.objects.filter(
|
# enddate__lte=enddate, startdate__lte=enddate, rowers__in=[rower])
|
||||||
enddate__lte=enddate, startdate__lte=enddate)
|
#plans = plans | plans2
|
||||||
plans = plans | plans2
|
|
||||||
|
|
||||||
plans = plans.exclude(status=False).order_by("-enddate")
|
#plans = plans.exclude(status=False).order_by("-enddate")
|
||||||
|
|
||||||
if not plans:
|
if not plans:
|
||||||
# make week cycles here
|
# make week cycles here
|
||||||
# get monday before startdate
|
# get monday before startdate
|
||||||
startdate += timedelta(days=1-startdate.isoweekday())
|
|
||||||
startdate = startdate-timedelta(days=7)
|
|
||||||
micros = []
|
micros = []
|
||||||
while startdate <= enddate:
|
|
||||||
micro = type('micros', (object,),
|
|
||||||
{
|
|
||||||
'startdate': startdate,
|
|
||||||
'enddate': startdate+timedelta(days=7)
|
|
||||||
})
|
|
||||||
micros.append(micro)
|
|
||||||
startdate += timedelta(days=7)
|
|
||||||
else:
|
else:
|
||||||
plan = plans[0]
|
sorted_plans = sorted(plans, key= lambda t: t.overlap(startdate,enddate))
|
||||||
|
plan = plans.reverse()[0]
|
||||||
macros = TrainingMacroCycle.objects.filter(
|
macros = TrainingMacroCycle.objects.filter(
|
||||||
plan=plan).order_by("startdate")
|
plan=plan).order_by("startdate")
|
||||||
checkscores(rower, macros)
|
checkscores(rower, macros)
|
||||||
@@ -237,12 +228,28 @@ def get_execution_report(rower, startdate, enddate, plan=None):
|
|||||||
startdate__lte=enddate,
|
startdate__lte=enddate,
|
||||||
).order_by("startdate")
|
).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
|
# we've got micros, now get sessions
|
||||||
startdates = []
|
startdates = []
|
||||||
planned = []
|
planned = []
|
||||||
executed = []
|
executed = []
|
||||||
|
|
||||||
|
|
||||||
for mm in micros:
|
for mm in micros:
|
||||||
|
print(mm)
|
||||||
plannedscore = 0
|
plannedscore = 0
|
||||||
actualscore = 0
|
actualscore = 0
|
||||||
sps = get_sessions(rower, startdate=mm.startdate, enddate=mm.enddate)
|
sps = get_sessions(rower, startdate=mm.startdate, enddate=mm.enddate)
|
||||||
|
|||||||
@@ -39,6 +39,8 @@
|
|||||||
<th align="left">Private/Shared</th>
|
<th align="left">Private/Shared</th>
|
||||||
<th align="left">Edit</th>
|
<th align="left">Edit</th>
|
||||||
<th align="left">Copy to Calendar</th>
|
<th align="left">Copy to Calendar</th>
|
||||||
|
<th align="left">Share</th>
|
||||||
|
<th align="left">Lock</th>
|
||||||
<th align="left">Delete</th>
|
<th align="left">Delete</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
{% if plan|mayeditplan:request %}
|
{% if plan|mayeditplan:request %}
|
||||||
<p><a href="/rowers/editplan/{{ plan.id }}">Edit the plan</a></p>
|
<p><a href="/rowers/editplan/{{ plan.id }}">Edit the plan</a></p>
|
||||||
{% endif %}
|
{% 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' }}/">
|
<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
|
View all sessions
|
||||||
</a>
|
</a>
|
||||||
|
|||||||
@@ -1414,6 +1414,13 @@ def save_plan_yaml(request, userid=0):
|
|||||||
ps.interval_string = '{d}m'.format(d=ps.sessionvalue)
|
ps.interval_string = '{d}m'.format(d=ps.sessionvalue)
|
||||||
elif ps.sessionmode == 'time':
|
elif ps.sessionmode == 'time':
|
||||||
ps.interval_string = '{d}min'.format(d=ps.sessionvalue)
|
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.fitfile = ''
|
||||||
ps.steps = None
|
ps.steps = None
|
||||||
ps.save()
|
ps.save()
|
||||||
@@ -1421,7 +1428,6 @@ def save_plan_yaml(request, userid=0):
|
|||||||
steps = ps_reload.steps
|
steps = ps_reload.steps
|
||||||
steps['filename'] = ""
|
steps['filename'] = ""
|
||||||
steps['workoutName'] = ps.name
|
steps['workoutName'] = ps.name
|
||||||
print(steps)
|
|
||||||
workouts.append(steps)
|
workouts.append(steps)
|
||||||
|
|
||||||
trainingdays.append({'order': i+1, 'workouts': workouts})
|
trainingdays.append({'order': i+1, 'workouts': workouts})
|
||||||
|
|||||||
Reference in New Issue
Block a user