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)
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,
)

View File

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

View File

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

View File

@@ -99,10 +99,10 @@
<td>
{% if thedict|lookup:'results'|lookup:r.id == 'completed' %}
<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' %}
<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' %}
<a class="white dot"
href="/rowers/sessions/manage/{{ timeperiod }}/rower/{{ r.id }}/session/{{ key }}">&nbsp;</a>

View File

@@ -64,13 +64,13 @@
</div>
<div class="grid_12 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>Percentage complete: {{ ratio }} </p>
</div>
<div id="right" class="grid_6 omega">
<h1>Stats</h1>
<table class="listtable shortpadded" width="80%">
<table class="listtable shortpadded" width="100%">
<thead>
<tr>
<th>Name</th>
@@ -78,6 +78,8 @@
<th>Meters</th>
<th>rScore</th>
<th>TRIMP</th>
<th>Complete Date</th>
<th>Status</th>
</tr>
</thead>
<tbody>
@@ -88,6 +90,8 @@
<td>{{ value|lookup:'distance' }}</td>
<td>{{ value|lookup:'rscore' }}</td>
<td>{{ value|lookup:'trimp' }}</td>
<td>{{ value|lookup:'completedate' }}</td>
<td>{{ value|lookup:'status' }}</td>
</tr>
{% endfor %}
</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\ ]+.*)$',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+)/delete$',views.plannedsession_delete_view),
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):
thedict = {}
thedict['id'] = instance.id
for attr, value in instance.__dict__.iteritems():
for f in instance._meta.fields:
fname = f.name
try:
verbose_name = model._meta.get_field(attr).verbose_name
verbosename = f.verbose_name
except:
verbose_name = attr
thedict[attr] = (verbose_name,value)
verbosename = f.name
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

View File

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