test type plannedsessions now have a ranking
This commit is contained in:
@@ -825,7 +825,6 @@ class PlannedSession(models.Model):
|
|||||||
|
|
||||||
sessionunitchoices = (
|
sessionunitchoices = (
|
||||||
('min','minutes'),
|
('min','minutes'),
|
||||||
('km','km'),
|
|
||||||
('m','meters'),
|
('m','meters'),
|
||||||
('None',None),
|
('None',None),
|
||||||
)
|
)
|
||||||
@@ -904,7 +903,17 @@ class PlannedSession(models.Model):
|
|||||||
self.sessionunit = 'min'
|
self.sessionunit = 'min'
|
||||||
else:
|
else:
|
||||||
self.sessionunit = 'None'
|
self.sessionunit = 'None'
|
||||||
|
|
||||||
|
if self.sessiontype == 'test':
|
||||||
|
if self.sessionmode not in ['distance','time']:
|
||||||
|
if self.sessionvalue < 100:
|
||||||
|
self.sessionmode = 'time'
|
||||||
|
self.sessionunit = 'min'
|
||||||
|
else:
|
||||||
|
self.sessionmode = 'distance'
|
||||||
|
self.sessionunit = 'm'
|
||||||
|
self.criterium = 'exact'
|
||||||
|
|
||||||
super(PlannedSession,self).save(*args, **kwargs)
|
super(PlannedSession,self).save(*args, **kwargs)
|
||||||
|
|
||||||
# Date input utility
|
# Date input utility
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import numpy as np
|
|||||||
import dataprep
|
import dataprep
|
||||||
|
|
||||||
# Low Level functions - to be called by higher level methods
|
# Low Level functions - to be called by higher level methods
|
||||||
def add_workouts_plannedsession(ws,ps):
|
def add_workouts_plannedsession(ws,ps,r):
|
||||||
result = 0
|
result = 0
|
||||||
comments = []
|
comments = []
|
||||||
errors = []
|
errors = []
|
||||||
@@ -36,6 +36,20 @@ def add_workouts_plannedsession(ws,ps):
|
|||||||
if (not all(d == dates[0] for d in dates)) and ps.sessiontype not in ['challenge','cycletarget']:
|
if (not all(d == dates[0] for d in dates)) and ps.sessiontype not in ['challenge','cycletarget']:
|
||||||
errors.append('For tests and training sessions, selected workouts must all be done on the same date')
|
errors.append('For tests and training sessions, selected workouts must all be done on the same date')
|
||||||
return result,comments,errors
|
return result,comments,errors
|
||||||
|
|
||||||
|
if len(ws)>1 and ps.sessiontype == 'test':
|
||||||
|
errors.append('For tests, you can only attach one workout')
|
||||||
|
return result,comments,errors
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
wold = Workout.objects.filter(plannedsession=ps,user=r)
|
||||||
|
ids = [w.id for w in wold] + [w.id for w in ws]
|
||||||
|
ids = list(set(ids))
|
||||||
|
|
||||||
|
if len(ids)>1 and ps.sessiontype == 'test':
|
||||||
|
errors.append('For tests, you can only attach one workout')
|
||||||
|
return result,comments,errors
|
||||||
|
|
||||||
# start adding sessions
|
# start adding sessions
|
||||||
for w in ws:
|
for w in ws:
|
||||||
@@ -99,7 +113,7 @@ def get_session_metrics(ps):
|
|||||||
rscorev += dataprep.workout_rscore(w)[0]
|
rscorev += dataprep.workout_rscore(w)[0]
|
||||||
|
|
||||||
ratio,statusv = is_session_complete_ws(ws,ps)
|
ratio,statusv = is_session_complete_ws(ws,ps)
|
||||||
completedatev = ws[0].date.strftime('%Y-%b-%d')
|
completedatev = ws[0].date.strftime('%Y-%m-%d')
|
||||||
durationv /= 60.
|
durationv /= 60.
|
||||||
|
|
||||||
trimp.append(int(trimpv))
|
trimp.append(int(trimpv))
|
||||||
|
|||||||
1
rowers/templates/.#list_workouts.html
Normal file
1
rowers/templates/.#list_workouts.html
Normal file
@@ -0,0 +1 @@
|
|||||||
|
e408191@CZ27LT9RCGN72.36632:1518629534
|
||||||
@@ -155,6 +155,8 @@
|
|||||||
}
|
}
|
||||||
if (this.value == 'test') {
|
if (this.value == 'test') {
|
||||||
$("td #id_criterium").prop("value","exact");
|
$("td #id_criterium").prop("value","exact");
|
||||||
|
$("td #id_sessionmode").prop("value","distance");
|
||||||
|
$("td #id_sessionunit").prop("value","m");
|
||||||
}
|
}
|
||||||
if (this.value == 'challenge') {
|
if (this.value == 'challenge') {
|
||||||
$("td #id_criterium").prop("value","minimum");
|
$("td #id_criterium").prop("value","minimum");
|
||||||
|
|||||||
@@ -160,6 +160,8 @@
|
|||||||
}
|
}
|
||||||
if (this.value == 'test') {
|
if (this.value == 'test') {
|
||||||
$("td #id_criterium").prop("value","exact");
|
$("td #id_criterium").prop("value","exact");
|
||||||
|
$("td #id_sessionmode").prop("value","distance");
|
||||||
|
$("td #id_sessionunit").prop("value","m");
|
||||||
}
|
}
|
||||||
if (this.value == 'challenge') {
|
if (this.value == 'challenge') {
|
||||||
$("td #id_criterium").prop("value","minimum");
|
$("td #id_criterium").prop("value","minimum");
|
||||||
|
|||||||
@@ -119,3 +119,73 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block scripts %}
|
||||||
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
|
||||||
|
<script>
|
||||||
|
$(document).ready(function(){
|
||||||
|
$("td #id_sessionmode").change(function() {
|
||||||
|
|
||||||
|
if (this.value == 'TRIMP') {
|
||||||
|
$("td #id_sessionunit").prop("value","None");
|
||||||
|
}
|
||||||
|
if (this.value == 'distance') {
|
||||||
|
$("td #id_sessionunit").prop("value","m");
|
||||||
|
}
|
||||||
|
if (this.value == 'time') {
|
||||||
|
$("td #id_sessionunit").prop("value","min");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.value == 'rScore') {
|
||||||
|
$("td #id_sessionunit").prop("value","None");
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
$("td #id_sessiontype").change(function() {
|
||||||
|
|
||||||
|
if (this.value == 'session') {
|
||||||
|
$("td #id_criterium").prop("value","none");
|
||||||
|
}
|
||||||
|
if (this.value == 'test') {
|
||||||
|
$("td #id_criterium").prop("value","exact");
|
||||||
|
$("td #id_sessionmode").prop("value","distance");
|
||||||
|
$("td #id_sessionunit").prop("value","m");
|
||||||
|
}
|
||||||
|
if (this.value == 'challenge') {
|
||||||
|
$("td #id_criterium").prop("value","minimum");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.value == 'cycletarget') {
|
||||||
|
$("td #id_criterium").prop("value","none");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
);
|
||||||
|
|
||||||
|
$("td #id_sessionunit").change(function() {
|
||||||
|
|
||||||
|
if (this.value == 'm') {
|
||||||
|
$("td #id_sessionmode").prop("value","distance");
|
||||||
|
}
|
||||||
|
if (this.value == 'km') {
|
||||||
|
$("td #id_sessionmode").prop("value","distance");
|
||||||
|
}
|
||||||
|
if (this.value == 'None') {
|
||||||
|
$("td #id_sessionmode").prop("value","rScore");
|
||||||
|
}
|
||||||
|
if (this.value == 'min') {
|
||||||
|
$("td #id_sessionmode").prop("value","time");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
|
|||||||
@@ -135,3 +135,73 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block scripts %}
|
||||||
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
|
||||||
|
<script>
|
||||||
|
$(document).ready(function(){
|
||||||
|
$("td #id_sessionmode").change(function() {
|
||||||
|
|
||||||
|
if (this.value == 'TRIMP') {
|
||||||
|
$("td #id_sessionunit").prop("value","None");
|
||||||
|
}
|
||||||
|
if (this.value == 'distance') {
|
||||||
|
$("td #id_sessionunit").prop("value","m");
|
||||||
|
}
|
||||||
|
if (this.value == 'time') {
|
||||||
|
$("td #id_sessionunit").prop("value","min");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.value == 'rScore') {
|
||||||
|
$("td #id_sessionunit").prop("value","None");
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
$("td #id_sessiontype").change(function() {
|
||||||
|
|
||||||
|
if (this.value == 'session') {
|
||||||
|
$("td #id_criterium").prop("value","none");
|
||||||
|
}
|
||||||
|
if (this.value == 'test') {
|
||||||
|
$("td #id_criterium").prop("value","exact");
|
||||||
|
$("td #id_sessionmode").prop("value","distance");
|
||||||
|
$("td #id_sessionunit").prop("value","m");
|
||||||
|
}
|
||||||
|
if (this.value == 'challenge') {
|
||||||
|
$("td #id_criterium").prop("value","minimum");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.value == 'cycletarget') {
|
||||||
|
$("td #id_criterium").prop("value","none");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
);
|
||||||
|
|
||||||
|
$("td #id_sessionunit").change(function() {
|
||||||
|
|
||||||
|
if (this.value == 'm') {
|
||||||
|
$("td #id_sessionmode").prop("value","distance");
|
||||||
|
}
|
||||||
|
if (this.value == 'km') {
|
||||||
|
$("td #id_sessionmode").prop("value","distance");
|
||||||
|
}
|
||||||
|
if (this.value == 'None') {
|
||||||
|
$("td #id_sessionmode").prop("value","rScore");
|
||||||
|
}
|
||||||
|
if (this.value == 'min') {
|
||||||
|
$("td #id_sessionmode").prop("value","time");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
|
|||||||
@@ -39,6 +39,33 @@
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<div id="right" class="grid_6 omega">
|
<div id="right" class="grid_6 omega">
|
||||||
|
{% if plannedsession.sessiontype == 'test' %}
|
||||||
|
<h1>Ranking</h1>
|
||||||
|
<table class="listtable shortpadded" width="80%">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Nr</th>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Distance</th>
|
||||||
|
<th>Time</th>
|
||||||
|
<th>Date</th>
|
||||||
|
<th>Type</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for result in ranking %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ forloop.counter }}</td>
|
||||||
|
<td>{{ result|lookup:'name' }}</td>
|
||||||
|
<td>{{ result|lookup:'distance' }}</td>
|
||||||
|
<td>{{ result|lookup:'time'|durationprint:"%H:%M:%S.%f" }}</td>
|
||||||
|
<td>{{ result|lookup:'date'|date:"Y-m-d" }}</td>
|
||||||
|
<td>{{ result|lookup:'type' }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{% endif %}
|
||||||
<h1>Workouts attached</h1>
|
<h1>Workouts attached</h1>
|
||||||
<table class="listtable shortpadded" width="80%">
|
<table class="listtable shortpadded" width="80%">
|
||||||
<thead>
|
<thead>
|
||||||
|
|||||||
@@ -440,6 +440,8 @@ urlpatterns = [
|
|||||||
|
|
||||||
url(r'^sessions/(?P<id>\d+)$',views.plannedsession_view,
|
url(r'^sessions/(?P<id>\d+)$',views.plannedsession_view,
|
||||||
name='plannedsession_view'),
|
name='plannedsession_view'),
|
||||||
|
url(r'^sessions/(?P<id>\d+)/(?P<timeperiod>[\w\ ]+.*)/rower/(?P<rowerid>\d+)$',views.plannedsession_view,
|
||||||
|
name='plannedsession_view'),
|
||||||
url(r'^sessions/(?P<id>\d+)/rower/(?P<rowerid>\d+)$',views.plannedsession_view,
|
url(r'^sessions/(?P<id>\d+)/rower/(?P<rowerid>\d+)$',views.plannedsession_view,
|
||||||
name='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),
|
||||||
|
|||||||
@@ -11959,7 +11959,6 @@ def plannedsession_teamedit_view(request,timeperiod='thisweek',
|
|||||||
'rowersform':sessionrowerform,
|
'rowersform':sessionrowerform,
|
||||||
'timeperiod':timeperiod,
|
'timeperiod':timeperiod,
|
||||||
'plannedsessions':sps,
|
'plannedsessions':sps,
|
||||||
'rower':r,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
@user_passes_test(iscoachmember,login_url="/rowers/planmembership/",
|
@user_passes_test(iscoachmember,login_url="/rowers/planmembership/",
|
||||||
@@ -12163,7 +12162,7 @@ def plannedsessions_manage_view(request,timeperiod='thisweek',rowerid=0,
|
|||||||
if w.id not in selectedworkouts:
|
if w.id not in selectedworkouts:
|
||||||
remove_workout_plannedsession(w,ps)
|
remove_workout_plannedsession(w,ps)
|
||||||
|
|
||||||
result,comments,errors = add_workouts_plannedsession(workouts,ps)
|
result,comments,errors = add_workouts_plannedsession(workouts,ps,r)
|
||||||
for c in comments:
|
for c in comments:
|
||||||
messages.info(request,c)
|
messages.info(request,c)
|
||||||
for er in errors:
|
for er in errors:
|
||||||
@@ -12289,7 +12288,6 @@ def plannedsession_edit_view(request,id=0,timeperiod='thisweek',rowerid=0):
|
|||||||
kwargs={
|
kwargs={
|
||||||
'timeperiod':timeperiod,
|
'timeperiod':timeperiod,
|
||||||
'sessionid':id,
|
'sessionid':id,
|
||||||
'rower':r,
|
|
||||||
})
|
})
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
@@ -12336,7 +12334,8 @@ def plannedsession_edit_view(request,id=0,timeperiod='thisweek',rowerid=0):
|
|||||||
|
|
||||||
|
|
||||||
@login_required()
|
@login_required()
|
||||||
def plannedsession_view(request,id=0,rowerid=0):
|
def plannedsession_view(request,id=0,rowerid=0,
|
||||||
|
timeperiod='thisweek'):
|
||||||
|
|
||||||
m = getrower(request.user)
|
m = getrower(request.user)
|
||||||
|
|
||||||
@@ -12365,6 +12364,27 @@ def plannedsession_view(request,id=0,rowerid=0):
|
|||||||
ratio,status = is_session_complete(r,ps)
|
ratio,status = is_session_complete(r,ps)
|
||||||
|
|
||||||
ratio = int(100.*ratio)
|
ratio = int(100.*ratio)
|
||||||
|
|
||||||
|
# ranking for test
|
||||||
|
ranking = []
|
||||||
|
|
||||||
|
if ps.sessiontype == 'test':
|
||||||
|
if ps.sessionmode == 'distance':
|
||||||
|
rankws = Workout.objects.filter(
|
||||||
|
plannedsession=ps).order_by("duration")
|
||||||
|
else:
|
||||||
|
rankws = Workout.objects.filter(
|
||||||
|
plannedsession=ps).order_by("-distance")
|
||||||
|
for w in rankws:
|
||||||
|
wdict = {
|
||||||
|
'name': w.user.user.first_name+' '+w.user.user.last_name,
|
||||||
|
'date': w.date,
|
||||||
|
'distance': w.distance,
|
||||||
|
'time': w.duration,
|
||||||
|
'type': w.workouttype,
|
||||||
|
}
|
||||||
|
ranking.append(wdict)
|
||||||
|
|
||||||
|
|
||||||
return render(request,'plannedsessionview.html',
|
return render(request,'plannedsessionview.html',
|
||||||
{
|
{
|
||||||
@@ -12380,6 +12400,9 @@ def plannedsession_view(request,id=0,rowerid=0):
|
|||||||
'ratio':ratio,
|
'ratio':ratio,
|
||||||
'status':status,
|
'status':status,
|
||||||
'results':resultsdict,
|
'results':resultsdict,
|
||||||
|
'plannedsession':ps,
|
||||||
|
'timeperiod':timeperiod,
|
||||||
|
'ranking':ranking,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user