Private
Public Access
1
0

minor improvements plannedsession views

This commit is contained in:
Sander Roosendaal
2018-02-12 17:35:14 +01:00
parent cd96820985
commit 9b8d2229a2
8 changed files with 62 additions and 26 deletions

View File

@@ -825,7 +825,8 @@ class PlannedSession(models.Model):
manager = models.ForeignKey(User) manager = models.ForeignKey(User)
name = models.CharField(max_length=150,blank=True) name = models.CharField(max_length=150,blank=True,
verbose_name='Name')
comment = models.TextField(max_length=500,blank=True, comment = models.TextField(max_length=500,blank=True,
) )

View File

@@ -79,13 +79,16 @@ def get_session_metrics(ps):
distance = [] distance = []
firstname = [] firstname = []
lastname = [] lastname = []
completedate = []
status = []
for r in rowers: for r in rowers:
rscorev = 0 rscorev = 0
trimpv = 0 trimpv = 0
durationv = 0 durationv = 0
distancev = 0 distancev = 0
completedatev = ''
statusv = 0
ws = Workout.objects.filter(user=r,plannedsession=ps) ws = Workout.objects.filter(user=r,plannedsession=ps)
if len(ws) != 0: if len(ws) != 0:
@@ -94,8 +97,9 @@ def get_session_metrics(ps):
durationv += timefield_to_seconds_duration(w.duration) durationv += timefield_to_seconds_duration(w.duration)
trimpv += dataprep.workout_trimp(w) trimpv += dataprep.workout_trimp(w)
rscorev += dataprep.workout_rscore(w) rscorev += dataprep.workout_rscore(w)
ratio,statusv = is_session_complete_ws(ws,ps)
completedatev = ws[0].date.strftime('%Y-%b-%d')
durationv /= 60. durationv /= 60.
trimp.append(int(trimpv)) trimp.append(int(trimpv))
@@ -104,6 +108,8 @@ def get_session_metrics(ps):
rscore.append(int(rscorev)) rscore.append(int(rscorev))
firstname.append(r.user.first_name) firstname.append(r.user.first_name)
lastname.append(r.user.last_name) lastname.append(r.user.last_name)
status.append(statusv)
completedate.append(completedatev)
thedict = { thedict = {
'first_name':firstname, 'first_name':firstname,
@@ -111,19 +117,14 @@ def get_session_metrics(ps):
'duration':duration, 'duration':duration,
'distance':distance, 'distance':distance,
'rscore':rscore, 'rscore':rscore,
'trimp':trimp 'trimp':trimp,
'completedate':completedate,
'status':status,
} }
return thedict return thedict
def is_session_complete(r,ps): def is_session_complete_ws(ws,ps):
status = 'not done'
if r not in ps.rower.all():
return 0,'not assigned'
ws = Workout.objects.filter(user=r,plannedsession=ps)
if len(ws)==0: if len(ws)==0:
today = date.today() today = date.today()
if today > ps.enddate: if today > ps.enddate:
@@ -195,6 +196,18 @@ def is_session_complete(r,ps):
else: else:
return ratio,status return ratio,status
def is_session_complete(r,ps):
status = 'not done'
if r not in ps.rower.all():
return 0,'not assigned'
ws = Workout.objects.filter(user=r,plannedsession=ps)
return is_session_complete_ws(ws,ps)
def rank_results(ps): def rank_results(ps):
return 1 return 1

View File

@@ -63,6 +63,7 @@
<th>On or Before</th> <th>On or Before</th>
<th>Name</th> <th>Name</th>
<th>Type</th> <th>Type</th>
<th>Mode</th>
<th>Edit</th> <th>Edit</th>
<th>Planned</th> <th>Planned</th>
<th>Actual</th> <th>Actual</th>
@@ -96,7 +97,8 @@
href="/rowers/sessions/{{ ps.id }}">Unnamed Session</a> href="/rowers/sessions/{{ ps.id }}">Unnamed Session</a>
{% endif %} {% endif %}
</td> </td>
<td> {{ ps.sessiontype }} </td> <td> {{ ps.get_sessiontype_display }} </td>
<td> {{ ps.get_sessionmode_display }} </td>
<td> <td>
{% if ps.manager == request.user %} {% if ps.manager == request.user %}
<a class="small" <a class="small"

View File

@@ -99,10 +99,10 @@
<td> <td>
{% if thedict|lookup:'results'|lookup:r.id == 'completed' %} {% if thedict|lookup:'results'|lookup:r.id == 'completed' %}
<a class="green dot" <a class="green dot"
href="/rowers/sessions/manage/{{ timeperiod }}/rower/{{ r.id }}/session/{{ key }}">&nbsp;</a> href="{% url 'plannedsession_view' id=key rowerid=r.id %}">&nbsp;</a>
{% elif thedict|lookup:'results'|lookup:r.id == 'partial' %} {% elif thedict|lookup:'results'|lookup:r.id == 'partial' %}
<a class="orange dot" <a class="orange dot"
href="/rowers/sessions/manage/{{ timeperiod }}/rower/{{ r.id }}/session/{{ key }}">&nbsp;</a> href="{% url 'plannedsession_view' id=key rowerid=r.id %}">&nbsp;</a>
{% elif thedict|lookup:'results'|lookup:r.id == 'not done' %} {% elif thedict|lookup:'results'|lookup:r.id == 'not done' %}
<a class="white dot" <a class="white dot"
href="/rowers/sessions/manage/{{ timeperiod }}/rower/{{ r.id }}/session/{{ key }}">&nbsp;</a> href="/rowers/sessions/manage/{{ timeperiod }}/rower/{{ r.id }}/session/{{ key }}">&nbsp;</a>

View File

@@ -64,13 +64,13 @@
</div> </div>
<div class="grid_12 alpha"> <div class="grid_12 alpha">
<div id="left" class="grid_6 alpha"> <div id="left" class="grid_6 alpha">
<h1>Result</h1> <h1>{{ rower.user.first_name }} {{ rower.user.last_name }}</h1>
<p>Status: {{ status }}</p> <p>Status: {{ status }}</p>
<p>Percentage complete: {{ ratio }} </p> <p>Percentage complete: {{ ratio }} </p>
</div> </div>
<div id="right" class="grid_6 omega"> <div id="right" class="grid_6 omega">
<h1>Stats</h1> <h1>Stats</h1>
<table class="listtable shortpadded" width="80%"> <table class="listtable shortpadded" width="100%">
<thead> <thead>
<tr> <tr>
<th>Name</th> <th>Name</th>
@@ -78,6 +78,8 @@
<th>Meters</th> <th>Meters</th>
<th>rScore</th> <th>rScore</th>
<th>TRIMP</th> <th>TRIMP</th>
<th>Complete Date</th>
<th>Status</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@@ -88,6 +90,8 @@
<td>{{ value|lookup:'distance' }}</td> <td>{{ value|lookup:'distance' }}</td>
<td>{{ value|lookup:'rscore' }}</td> <td>{{ value|lookup:'rscore' }}</td>
<td>{{ value|lookup:'trimp' }}</td> <td>{{ value|lookup:'trimp' }}</td>
<td>{{ value|lookup:'completedate' }}</td>
<td>{{ value|lookup:'status' }}</td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>

View File

@@ -427,7 +427,10 @@ urlpatterns = [
url(r'^sessions/(?P<id>\d+)/clone/(?P<timeperiod>[\w\ ]+.*)/rower/(?P<rowerid>\d+)$',views.plannedsession_clone_view), url(r'^sessions/(?P<id>\d+)/clone/(?P<timeperiod>[\w\ ]+.*)/rower/(?P<rowerid>\d+)$',views.plannedsession_clone_view),
url(r'^sessions/(?P<id>\d+)/clone/(?P<timeperiod>[\w\ ]+.*)$',views.plannedsession_clone_view), url(r'^sessions/(?P<id>\d+)/clone/(?P<timeperiod>[\w\ ]+.*)$',views.plannedsession_clone_view),
url(r'^sessions/(?P<id>\d+)$',views.plannedsession_view), url(r'^sessions/(?P<id>\d+)$',views.plannedsession_view,
name='plannedsession_view'),
url(r'^sessions/(?P<id>\d+)/rower/(?P<rowerid>\d+)$',views.plannedsession_view,
name='plannedsession_view'),
url(r'^sessions/(?P<id>\d+)/deleteconfirm$',views.plannedsession_deleteconfirm_view), url(r'^sessions/(?P<id>\d+)/deleteconfirm$',views.plannedsession_deleteconfirm_view),
url(r'^sessions/(?P<id>\d+)/delete$',views.plannedsession_delete_view), url(r'^sessions/(?P<id>\d+)/delete$',views.plannedsession_delete_view),
url(r'^sessions/manage/session/(?P<initialsession>\d+)$', url(r'^sessions/manage/session/(?P<initialsession>\d+)$',

View File

@@ -295,13 +295,26 @@ def calculate_age(born):
def my_dict_from_instance(instance,model): def my_dict_from_instance(instance,model):
thedict = {} thedict = {}
thedict['id'] = instance.id thedict['id'] = instance.id
for attr, value in instance.__dict__.iteritems(): for f in instance._meta.fields:
fname = f.name
try: try:
verbose_name = model._meta.get_field(attr).verbose_name verbosename = f.verbose_name
except: except:
verbose_name = attr verbosename = f.name
thedict[attr] = (verbose_name,value) get_choice = 'get_'+fname+'_display'
if hasattr( instance, get_choice):
value = getattr(instance, get_choice)()
else:
try:
value = getattr(instance,fname)
except AttributeError:
value = None
if f.editable and value:
thedict[fname] = (verbosename,value)
return thedict return thedict

View File

@@ -12243,7 +12243,6 @@ def plannedsession_view(request,id=0,rowerid=0):
resultsdict = pd.DataFrame(resultsdict).transpose().to_dict() resultsdict = pd.DataFrame(resultsdict).transpose().to_dict()
psdict = my_dict_from_instance(ps,PlannedSession) psdict = my_dict_from_instance(ps,PlannedSession)
print psdict
ws = get_workouts_session(r,ps) ws = get_workouts_session(r,ps)
@@ -12256,6 +12255,7 @@ def plannedsession_view(request,id=0,rowerid=0):
'psdict': psdict, 'psdict': psdict,
'attrs':[ 'attrs':[
'name','startdate','enddate','sessiontype', 'name','startdate','enddate','sessiontype',
'sessionmode',
'sessionvalue','sessionunit' 'sessionvalue','sessionunit'
], ],
'workouts': ws, 'workouts': ws,