adding plan/actual in plan view
This commit is contained in:
@@ -1313,10 +1313,21 @@ class TrainingMacroCycle(models.Model):
|
||||
enddate = models.DateField(
|
||||
default=half_year_from_now)
|
||||
notes = models.TextField(max_length=300,blank=True)
|
||||
|
||||
type = models.CharField(default='filler',
|
||||
choices=cycletypechoices,
|
||||
max_length=150)
|
||||
|
||||
plantime = models.IntegerField(default=0,verbose_name='Planned Duration')
|
||||
plandistance = models.IntegerField(default=0,verbose_name='Planned Distance')
|
||||
planrscore = models.IntegerField(default=0,verbose_name='Planned rScore')
|
||||
plantrimp = models.IntegerField(default=0,verbose_name='Planned TRIMP')
|
||||
|
||||
actualtime = models.IntegerField(default=0,verbose_name='Actual Duration')
|
||||
actualdistance = models.IntegerField(default=0,verbose_name='Actual Distance')
|
||||
actualrscore = models.IntegerField(default=0,verbose_name='Actual rScore')
|
||||
actualtrimp = models.IntegerField(default=0,verbose_name='Actual TRIMP')
|
||||
|
||||
def __unicode__(self):
|
||||
stri = 'Macro Cycle - {n} ({sd} - {ed})'.format(
|
||||
n = self.name,
|
||||
@@ -1391,6 +1402,18 @@ class TrainingMesoCycle(models.Model):
|
||||
type = models.CharField(default='filler',
|
||||
choices=cycletypechoices,
|
||||
max_length=150)
|
||||
|
||||
plantime = models.IntegerField(default=0,verbose_name='Planned Duration')
|
||||
plandistance = models.IntegerField(default=0,verbose_name='Planned Distance')
|
||||
planrscore = models.IntegerField(default=0,verbose_name='Planned rScore')
|
||||
plantrimp = models.IntegerField(default=0,verbose_name='Planned TRIMP')
|
||||
|
||||
actualtime = models.IntegerField(default=0,verbose_name='Actual Duration')
|
||||
actualdistance = models.IntegerField(default=0,verbose_name='Actual Distance')
|
||||
actualrscore = models.IntegerField(default=0,verbose_name='Actual rScore')
|
||||
actualtrimp = models.IntegerField(default=0,verbose_name='Actual TRIMP')
|
||||
|
||||
|
||||
def __unicode__(self):
|
||||
stri = 'Meso Cycle - {n} ({sd} - {ed})'.format(
|
||||
n = self.name,
|
||||
@@ -1454,6 +1477,20 @@ class TrainingMicroCycle(models.Model):
|
||||
type = models.CharField(default='filler',
|
||||
choices=cycletypechoices,
|
||||
max_length=150)
|
||||
|
||||
plantime = models.IntegerField(default=0,verbose_name='Planned Duration')
|
||||
plandistance = models.IntegerField(default=0,verbose_name='Planned Distance')
|
||||
planrscore = models.IntegerField(default=0,verbose_name='Planned rScore')
|
||||
plantrimp = models.IntegerField(default=0,verbose_name='Planned TRIMP')
|
||||
|
||||
actualtime = models.IntegerField(default=0,verbose_name='Actual Duration')
|
||||
actualdistance = models.IntegerField(default=0,verbose_name='Actual Distance')
|
||||
actualrscore = models.IntegerField(default=0,verbose_name='Actual rScore')
|
||||
actualtrimp = models.IntegerField(default=0,verbose_name='Actual TRIMP')
|
||||
|
||||
|
||||
|
||||
|
||||
def __unicode__(self):
|
||||
stri = 'Micro Cycle - {n} ({sd} - {ed})'.format(
|
||||
n = self.name,
|
||||
@@ -1491,6 +1528,8 @@ class TrainingMicroCycle(models.Model):
|
||||
if othercycle.enddate >= self.startdate and othercycle.enddate <= self.enddate:
|
||||
self.startdate = othercycle.enddate+datetime.timedelta(days=1)
|
||||
|
||||
|
||||
|
||||
if not self.enddate <= self.startdate:
|
||||
super(TrainingMicroCycle,self).save(*args, **kwargs)
|
||||
|
||||
|
||||
@@ -306,10 +306,10 @@ def is_session_complete_ws(ws,ps):
|
||||
for record in vs:
|
||||
if record.workoutid in wids:
|
||||
if record.coursecompleted:
|
||||
ratio = record.distance/ps.sessionvalue
|
||||
ratio = record.distance/float(ps.sessionvalue)
|
||||
return ratio,'completed',completiondate
|
||||
else:
|
||||
ratio = record.distance/ps.sessionvalue
|
||||
ratio = record.distance/float(ps.sessionvalue)
|
||||
return ratio,'partial',completiondate
|
||||
|
||||
# we're still here - no record, need to create one
|
||||
@@ -338,6 +338,7 @@ def is_session_complete_ws(ws,ps):
|
||||
def is_session_complete(r,ps):
|
||||
status = 'not done'
|
||||
|
||||
|
||||
if r not in ps.rower.all():
|
||||
return 0,'not assigned',None
|
||||
|
||||
|
||||
@@ -40,18 +40,49 @@
|
||||
{% else %}
|
||||
<div class="grid_4 palegreen alpha">
|
||||
{% endif %}
|
||||
<div class="padded">
|
||||
<h3>{{ macrocycle.0.name }} ({{ macrocycle.0.startdate }} - {{ macrocycle.0.enddate }})</h3>
|
||||
{% if todays_date <= macrocycle.0.enddate|date:"Y-m-d" %}
|
||||
<p><a href="/rowers/macrocycle/{{ macrocycle.0.id }}">edit</a>
|
||||
/
|
||||
<a href="/rowers/deletemacrocycle/{{ macrocycle.0.id }}">delete</a>
|
||||
/
|
||||
<a href='/rowers/sessions/{{ macrocycle.0.startdate|date:"Y-m-d" }}/{{ macrocycle.0.enddate|date:"Y-m-d" }}'>sessions</a>
|
||||
</p>
|
||||
{% else %}
|
||||
<p> </p>
|
||||
{% endif %}
|
||||
<div class="padded">
|
||||
<table width="100%">
|
||||
<tr>
|
||||
<th colspan="4">
|
||||
{{ macrocycle.0.name }} ({{ macrocycle.0.startdate }} - {{ macrocycle.0.enddate }})
|
||||
</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td>dist (m)</td>
|
||||
<td>t (min)</td>
|
||||
<td>rScore</td>
|
||||
<td>TRIMP</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>plan</td>
|
||||
<td>{{ macrocycle.0.plandistance }}</td>
|
||||
<td>{{ macrocycle.0.plantime }}</td>
|
||||
<td>{{ maccrocycle.0.planrscore }}</td>
|
||||
<td>{{ macrocycle.0.plantrimp }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>actual</td>
|
||||
<td>{{ macrocycle.0.actualdistance }}</td>
|
||||
<td>{{ macrocycle.0.actualtime }}</td>
|
||||
<td>{{ macrocycle.0.actualrscore }}</td>
|
||||
<td>{{ macrocycle.0.actualtrimp }}</td>
|
||||
</tr>
|
||||
{% if todays_date <= macrocycle.0.enddate|date:"Y-m-d" %}
|
||||
<tr>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="4">
|
||||
<a href="/rowers/macrocycle/{{ macrocycle.0.id }}">edit</a>
|
||||
/
|
||||
<a href="/rowers/deletemacrocycle/{{ macrocycle.0.id }}">delete</a>
|
||||
/
|
||||
<a href='/rowers/sessions/{{ macrocycle.0.startdate|date:"Y-m-d" }}/{{ macrocycle.0.enddate|date:"Y-m-d" }}'>sessions</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid_8 alpha">
|
||||
@@ -59,55 +90,115 @@
|
||||
{% if mesocycle.0.type == 'filler' %}
|
||||
<div class="grid_4 filler alpha">
|
||||
{% else %}
|
||||
<div class="grid_4 lightsalmon alpha">
|
||||
<div class="grid_4 lightsalmon alpha">
|
||||
{% endif %}
|
||||
<div class="padded">
|
||||
<table width="100%">
|
||||
<tr>
|
||||
<th colspan="4">
|
||||
{{ mesocycle.0.name }} ({{ mesocycle.0.startdate }} - {{ mesocycle.0.enddate }})
|
||||
</th>
|
||||
</tr>
|
||||
{% if mesocycle.0.plan.type == 'userdefined' %}
|
||||
<tr>
|
||||
<td></td>
|
||||
<td>dist (m)</td>
|
||||
<td>t (min)</td>
|
||||
<td>rScore</td>
|
||||
<td>TRIMP</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>plan</td>
|
||||
<td>{{ mesocycle.0.plandistance }}</td>
|
||||
<td>{{ mesocycle.0.plantime }}</td>
|
||||
<td>{{ mesocycle.0.planrscore }}</td>
|
||||
<td>{{ mesocycle.0.plantrimp }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>actual</td>
|
||||
<td>{{ mesocycle.0.actualdistance }}</td>
|
||||
<td>{{ mesocycle.0.actualtime }}</td>
|
||||
<td>{{ mesocycle.0.actualrscore }}</td>
|
||||
<td>{{ mesocycle.0.actualtrimp }}</td>
|
||||
</tr>
|
||||
{% if todays_date <= mesocycle.0.enddate|date:"Y-m-d" %}
|
||||
<tr>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="4">
|
||||
<a href="/rowers/microcycle/{{ mesocycle.0.id }}">edit</a>
|
||||
/
|
||||
<a href="/rowers/deletemicrocycle/{{ mesocycle.0.id }}">delete</a>
|
||||
/
|
||||
<a href='/rowers/sessions/{{ mesocycle.0.startdate|date:"Y-m-d" }}/{{ mesocycle.0.enddate|date:"Y-m-d" }}'>sessions</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid_4 omega">
|
||||
{% for microcycle in mesocycle.1 %}
|
||||
{% if microcycle.type == 'filler' %}
|
||||
<div class="grid_4 filler">
|
||||
{% else %}
|
||||
<div class="grid_4 paleblue ">
|
||||
{% endif %}
|
||||
<div class="padded">
|
||||
<h3>{{ mesocycle.0.name }} ({{ mesocycle.0.startdate }} - {{ mesocycle.0.enddate }})</h3>
|
||||
{% if mesocycle.0.plan.type == 'userdefined' %}
|
||||
{% if todays_date <= mesocycle.0.enddate|date:"Y-m-d" %}
|
||||
<p><a href="/rowers/mesocycle/{{ mesocycle.0.id }}">edit</a>
|
||||
/
|
||||
<a href="/rowers/deletemesocycle/{{ mesocycle.0.id }}">delete</a>
|
||||
/
|
||||
<a href='/rowers/sessions/{{ mesocycle.0.startdate|date:"Y-m-d" }}/{{ mesocycle.0.enddate|date:"Y-m-d" }}'>sessions</a>
|
||||
|
||||
</p>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<p> </p>
|
||||
{% endif %}
|
||||
<table width="100%">
|
||||
<tr>
|
||||
<th colspan="4">
|
||||
{{ microcycle.name }} ({{ microcycle.startdate }} - {{ microcycle.enddate }})
|
||||
</th>
|
||||
</tr>
|
||||
{% if microcycle.plan.type == 'userdefined' %}
|
||||
<tr>
|
||||
<td></td>
|
||||
<td>dist (m)</td>
|
||||
<td>t (min)</td>
|
||||
<td>rScore</td>
|
||||
<td>TRIMP</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>plan</td>
|
||||
<td>{{ microcycle.plandistance }}</td>
|
||||
<td>{{ microcycle.plantime }}</td>
|
||||
<td>{{ microcycle.planrscore }}</td>
|
||||
<td>{{ microcycle.plantrimp }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>actual</td>
|
||||
<td>{{ microcycle.actualdistance }}</td>
|
||||
<td>{{ microcycle.actualtime }}</td>
|
||||
<td>{{ microcycle.actualrscore }}</td>
|
||||
<td>{{ microcycle.actualtrimp }}</td>
|
||||
</tr>
|
||||
{% if todays_date <= microcycle.enddate|date:"Y-m-d" %}
|
||||
<tr>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="4">
|
||||
<a href="/rowers/microcycle/{{ microcycle.id }}">edit</a>
|
||||
/
|
||||
<a href="/rowers/deletemicrocycle/{{ microcycle.id }}">delete</a>
|
||||
/
|
||||
<a href='/rowers/sessions/{{ microcycle.startdate|date:"Y-m-d" }}/{{ microcycle.enddate|date:"Y-m-d" }}'>sessions</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid_4 omega">
|
||||
{% for microcycle in mesocycle.1 %}
|
||||
{% if microcycle.type == 'filler' %}
|
||||
<div class="grid_4 filler">
|
||||
{% else %}
|
||||
<div class="grid_4 paleblue ">
|
||||
{% endif %}
|
||||
<div class="padded">
|
||||
<h3>{{ microcycle.name }} ({{ microcycle.startdate }} - {{ microcycle.enddate }})</h3>
|
||||
{% if microcycle.plan.type == 'userdefined' %}
|
||||
{% if todays_date <= microcycle.enddate|date:"Y-m-d" %}
|
||||
<p>
|
||||
<a href="/rowers/microcycle/{{ microcycle.id }}">edit</a>
|
||||
/
|
||||
<a href="/rowers/deletemicrocycle/{{ microcycle.id }}">delete</a>
|
||||
/
|
||||
<a href='/rowers/sessions/{{ microcycle.startdate|date:"Y-m-d" }}/{{ microcycle.enddate|date:"Y-m-d" }}'>sessions</a>
|
||||
</p>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<p> </p>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="grid_12">
|
||||
<p>Click on the plan cycles to edit their names, start and end dates. The gray "filler"
|
||||
|
||||
@@ -14499,17 +14499,98 @@ def rower_trainingplan_view(request,id=0):
|
||||
count = 0
|
||||
cycles = {}
|
||||
|
||||
r = plan.rower
|
||||
|
||||
for m in macrocycles:
|
||||
createmesofillers(m)
|
||||
m.plantime = 0
|
||||
m.actualtime = 0
|
||||
m.plandistance = 0
|
||||
m.actualdistance = 0
|
||||
m.planrscore = 0
|
||||
m.actualrscore = 0
|
||||
m.plantrimp = 0
|
||||
m.actualtrimp = 0
|
||||
|
||||
|
||||
mesocycles = TrainingMesoCycle.objects.filter(plan=m).order_by("startdate")
|
||||
mesos = {}
|
||||
count2 = 0
|
||||
for me in mesocycles:
|
||||
createmicrofillers(me)
|
||||
me.plantime = 0
|
||||
me.actualtime = 0
|
||||
me.plandistance = 0
|
||||
me.actualdistance = 0
|
||||
me.planrscore = 0
|
||||
me.actualrscore = 0
|
||||
me.plantrimp = 0
|
||||
me.actualtrimp = 0
|
||||
|
||||
microcycles = TrainingMicroCycle.objects.filter(plan=me).order_by("startdate")
|
||||
|
||||
for mm in microcycles:
|
||||
sps = PlannedSession.objects.filter(
|
||||
rower = plan.rower,
|
||||
startdate__lte=mm.enddate,
|
||||
enddate__gte=mm.startdate)
|
||||
|
||||
|
||||
mm.plantime = 0
|
||||
mm.actualtime = 0
|
||||
mm.plandistance = 0
|
||||
mm.actualdistance = 0
|
||||
mm.planrscore = 0
|
||||
mm.actualrscore = 0
|
||||
mm.plantrimp = 0
|
||||
mm.actualtrimp = 0
|
||||
|
||||
|
||||
if mm.type == 'userdefined':
|
||||
for ps in sps:
|
||||
ratio, status, cdate = is_session_complete(r,ps)
|
||||
if ps.sessionmode == 'time':
|
||||
mm.plantime += ps.sessionvalue
|
||||
mm.actualtime += ps.sessionvalue*ratio
|
||||
elif ps.sessionmode == 'distance':
|
||||
mm.plandistance += ps.sessionvalue
|
||||
mm.actualdistance += ps.sessionvalue*ratio
|
||||
elif ps.sessionmode == 'rScore':
|
||||
mm.planrscore += ps.sessionvalue
|
||||
mm.actualrscore += ps.sessionvalue*ratio
|
||||
elif ps.sessionmode == 'TRIMP':
|
||||
mm.plantrimp += ps.sessionvalue
|
||||
mm.actualtrimp += ps.sessionvalue*ratio
|
||||
|
||||
mm.save()
|
||||
|
||||
me.plantime += mm.plantime
|
||||
me.actualtime += mm.actualtime
|
||||
me.plandistance += mm.plandistance
|
||||
me.actualdistance += mm.actualdistance
|
||||
me.planrscore += mm.planrscore
|
||||
me.actualrscore += mm.actualrscore
|
||||
me.plantrimp += mm.plantrimp
|
||||
me.actualtrimp += mm.actualtrimp
|
||||
|
||||
if me.type == 'userdefined':
|
||||
me.save()
|
||||
|
||||
m.plantime += me.plantime
|
||||
m.actualtime += me.actualtime
|
||||
m.plandistance += me.plandistance
|
||||
m.actualdistance += me.actualdistance
|
||||
m.planrscore += me.planrscore
|
||||
m.actualrscore += me.actualrscore
|
||||
m.plantrimp += me.plantrimp
|
||||
m.actualtrimp += me.actualtrimp
|
||||
|
||||
|
||||
mesos[count2] = (me, microcycles)
|
||||
count2 += 1
|
||||
|
||||
if m.type == 'userdefined':
|
||||
m.save()
|
||||
cycles[count] = (m,mesos)
|
||||
count += 1
|
||||
|
||||
@@ -14604,6 +14685,7 @@ class TrainingMicroCycleUpdate(UpdateView):
|
||||
form.instance.user = self.request.user
|
||||
form.instance.post_date = datetime.datetime.now()
|
||||
microcycle = form.save()
|
||||
|
||||
return super(TrainingMicroCycleUpdate, self).form_valid(form)
|
||||
|
||||
def get_object(self, *args, **kwargs):
|
||||
|
||||
Reference in New Issue
Block a user