Private
Public Access
1
0

Merge branch 'feature/planning3' into develop

This commit is contained in:
Sander Roosendaal
2018-02-11 20:03:23 +01:00
9 changed files with 393 additions and 22 deletions
+68 -12
View File
@@ -16,7 +16,7 @@ queuelow = django_rq.get_queue('low')
queuehigh = django_rq.get_queue('low')
from rowers.models import (
Rower, Workout,
Rower, Workout,Team,
GeoCourse, TrainingMicroCycle,TrainingMesoCycle,TrainingMacroCycle,
TrainingPlan,PlannedSession,
)
@@ -71,9 +71,57 @@ def timefield_to_seconds_duration(t):
return duration
def get_session_metrics(ps):
rowers = ps.rower.all()
rscore = []
trimp = []
duration = []
distance = []
firstname = []
lastname = []
for r in rowers:
rscorev = 0
trimpv = 0
durationv = 0
distancev = 0
ws = Workout.objects.filter(user=r,plannedsession=ps)
if len(ws) != 0:
for w in ws:
distancev += w.distance
durationv += timefield_to_seconds_duration(w.duration)
trimpv += dataprep.workout_trimp(w)
rscorev += dataprep.workout_rscore(w)
durationv /= 60.
trimp.append(int(trimpv))
duration.append(int(durationv))
distance.append(int(distancev))
rscore.append(int(rscorev))
firstname.append(r.user.first_name)
lastname.append(r.user.last_name)
thedict = {
'first_name':firstname,
'last_name':lastname,
'duration':duration,
'distance':distance,
'rscore':rscore,
'trimp':trimp
}
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)
if len(ws)==0:
@@ -208,6 +256,25 @@ def get_dates_timeperiod(timeperiod):
return startdate,enddate
def get_sessions_manager(m,teamid=0,startdate=date.today(),
enddate=date.today()+timezone.timedelta(+1000)):
if teamid:
t = Team.objects.get(id=teamid)
sps = PlannedSession.objects.filter(
team__in=[t],
manager=m,
startdate__lte=enddate,
enddate__gte=startdate,
).order_by("startdate","enddate")
else:
sps = PlannedSession.objects.filter(
manager=m,
startdate__lte=enddate,
enddate__gte=startdate,
).order_by("startdate","enddate")
return sps
def get_sessions(r,startdate=date.today(),
enddate=date.today()+timezone.timedelta(+1000)):
@@ -219,17 +286,6 @@ def get_sessions(r,startdate=date.today(),
return sps
def get_sessions_manager(manager,startdate=date.today(),
enddate=date.today()+timezone.timedelta(+1000)):
sps = PlannedSession.objects.filter(
manager=manager,
startdate__lte=enddate,
enddate__gte=startdate,
).order_by("startdate","enddate").exclude(team__isnull=True)
return sps
def get_workouts_session(r,ps):
ws = Workout.objects.filter(user=r,plannedsession=ps)
+181
View File
@@ -0,0 +1,181 @@
{% extends "base.html" %}
{% load staticfiles %}
{% load rowerfilters %}
{% block title %}Planned Sessions{% endblock %}
{% block content %}
<div class="grid_12 alpha">
{% include "planningbuttons.html" %}
</div>
<div class="grid_4 alpha">
{% if theteam %}
<h1>Coach Overview. Team {{ theteam.name }}</h1>
{% else %}
<h1>Coach Overview</h1>
{% endif %}
</div>
<div id="timeperiod" class="grid_2 dropdown">
<button class="grid_2 alpha button gray small dropbtn">Select Time Period ({{ timeperiod|verbosetimeperiod }})</button>
<div class="dropdown-content">
<a class="button gray small alpha"
href="/rowers/sessions/coach/today">
Today
</a>
<a class="button gray small alpha"
href="/rowers/sessions/coach/thisweek">
This Week
</a>
<a class="button gray small alpha"
href="/rowers/sessions/coach/thismonth">
This Month
</a>
<a class="button gray small alpha"
href="/rowers/sessions/coach/lastweek">
Last Week
</a>
<a class="button gray small alpha"
href="/rowers/sessions/coach/lastmonth/">
Last Month
</a>
</div>
</div>
{% if user.is_authenticated and user|is_manager %}
<div class="grid_2 dropdown">
<button class="grid_2 alpha button green small dropbtn">
Select Rower Individual Plan
</button>
<div class="dropdown-content">
{% for member in user|team_rowers %}
<a class="button green small" href="/rowers/sessions/{{ timeperiod }}/rower/{{ member.id }}">{{ member.user.first_name }} {{ member.user.last_name }}</a>
{% endfor %}
</div>
</div>
<div class="grid_2 dropdown">
<button class="grid_2 alpha button green small dropbtn">
Select Team
</button>
<div class="dropdown-content">
<a class="button green small" href="/rowers/sessions/coach/{{ timeperiod }}">
All Teams
</a>
{% for team in myteams %}
<a class="button green small" href="/rowers/sessions/coach/{{ timeperiod }}/team/{{ team.id }}">{{ team.name }}</a>
{% endfor %}
</div>
</div>
{% endif %}
<div class="grid_12 alpha">
<table width="90%" class="listtable">
<thead>
<tr>
<th>On or after</th>
<th>On or before</th>
<th>Name</th>
{% for r in rowers %}
<th class="rotate"><div><span>
{{ r.user.first_name }} {{ r.user.last_name }}
</span></div></th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for key, thedict in statusdict.items %}
<tr>
<td>
{{ thedict|lookup:'startdate'|date:"Y-m-d" }}
</td>
<td>
{{ thedict|lookup:'enddate'|date:"Y-m-d" }}
</td>
<td>
<a href="/rowers/sessions/{{ key }}">
{{ thedict|lookup:'name' }}
</a>
</td>
{% for r in rowers %}
<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>
{% elif thedict|lookup:'results'|lookup:r.id == 'partial' %}
<a class="orange dot"
href="/rowers/sessions/manage/{{ timeperiod }}/rower/{{ r.id }}/session/{{ key }}">&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>
{% elif thedict|lookup:'results'|lookup:r.id == 'not assigned' %}
&nbsp;
{% else %}
<a class="red dot"
href="/rowers/sessions/manage/{{ timeperiod }}/rower/{{ r.id }}/session/{{ key }}">&nbsp;</a>
{% endif %}
</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
{% if unmatchedworkouts %}
<h1>Workouts that are not linked to any session</h1>
<table width="90%" class="listtable shortpadded">
<thead>
<tr>
<th> Rower</th>
<th style="width:80"> Date</th>
<th> Time</th>
<th> Name</th>
<th> Type</th>
<th> Distance </th>
<th> Duration </th>
<th> Avg HR </th>
<th> Max HR </th>
</tr>
</thead>
<tbody>
{% for workout in unmatchedworkouts %}
<tr>
<td> {{ workout.user.user.first_name }} {{ workout.user.user.last_name }} </td>
<td> {{ workout.date|date:"Y-m-d" }} </td>
<td> {{ workout.starttime|date:"H:i" }} </td>
{% if workout.user.user == user or user == team.manager %}
{% if workout.name != '' %}
<td>
<a href={% url rower.defaultlandingpage id=workout.id %}>
{{ workout.name }}
</a>
</td>
{% else %}
<td>
<a href={% url rower.defaultlandingpage id=workout.id %}>No Name
</a></td>
{% endif %}
{% else %}
{% if workout.name != '' %}
<td><a href="/rowers/workout/{{ workout.id }}/">{{ workout.name }}</a></td>
{% else %}
<td><a href="/rowers/workout/{{ workout.id }}/">No Name</a> </td>
{% endif %}
{% endif %}
<td> {{ workout.workouttype }} </td>
<td> {{ workout.distance }}m</td>
<td> {{ workout.duration |durationprint:"%H:%M:%S.%f" }} </td>
<td> {{ workout.averagehr }} </td>
<td> {{ workout.maxhr }} </td>
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
</div>
</form>
{% endblock %}
+44 -5
View File
@@ -9,6 +9,17 @@
{% include "planningbuttons.html" %}
</div>
<div class="grid_12 alpha">
<div class="grid_2 alpha">
{% if user.is_authenticated and psdict.id.1|is_session_manager:user %}
<a class="button small gray" href="/rowers/sessions/{{ psdict.id.1 }}/edit">
Edit Session</a>
{% else %}
&nbsp;
{% endif %}
</div>
</div>
<div class="grid_12 alpha">
<div id="left" class="grid_6 alpha">
<h1>Session {{ psdict.name.1 }}</h1>
<table class="listtable shortpadded" width="80%">
@@ -22,9 +33,6 @@
{% endfor %}
{% endfor %}
</table>
<h1>Result</h1>
<p>Status: {{ status }}</p>
<p>Percentage complete: {{ ratio }} </p>
</div>
<div id="right" class="grid_6 omega">
<h1>Workouts attached</h1>
@@ -53,7 +61,38 @@
</tbody>
</table>
</div>
</div>
<div class="grid_12 alpha">
<div id="left" class="grid_6 alpha">
<h1>Result</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%">
<thead>
<tr>
<th>Name</th>
<th>Minutes</th>
<th>Meters</th>
<th>rScore</th>
<th>TRIMP</th>
</tr>
</thead>
<tbody>
{% for id, value in results.items %}
<tr>
<td>{{ value|lookup:'first_name' }} {{ value|lookup:'last_name' }}</td>
<td>{{ value|lookup:'duration' }}</td>
<td>{{ value|lookup:'distance' }}</td>
<td>{{ value|lookup:'rscore' }}</td>
<td>{{ value|lookup:'trimp' }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endblock %}
+13 -2
View File
@@ -32,12 +32,23 @@
{% endif %}
</p>
</div>
<div class="grid_2 omega">
<div class="grid_2">
{% if user.is_authenticated and user|is_manager %}
{% if timeperiod %}
<a class="button gray small" href="/rowers/sessions/teamcreate/{{ timeperiod }}">Add Team Session</a>
{% else %}
<a class="button gray small" href="/rowers/session/teamcreate">Add Team Session</a>
<a class="button gray small" href="/rowers/sessions/teamcreate">Add Team Session</a>
{% endif %}
{% else %}
&nbsp;
{% endif %}
</div>
<div class="grid_2 omega">
{% if user.is_authenticated and user|is_manager %}
{% if timeperiod %}
<a class="button gray small" href="/rowers/sessions/coach/{{ timeperiod }}">Coach Overview</a>
{% else %}
<a class="button gray small" href="/rowers/sessions/coach">Coach Overview</a>
{% endif %}
{% else %}
&nbsp;
+10
View File
@@ -100,6 +100,16 @@ def ualookup(dict, key):
return s
from rowers.models import PlannedSession
@register.filter
def is_session_manager(id,user):
try:
ps = PlannedSession.objects.get(id=id)
except PlannedSession.DoesNotExist:
return False
return ps.manager == user
@register.filter(name='times')
def times(number):
return range(number)
+5
View File
@@ -448,6 +448,11 @@ urlpatterns = [
views.plannedsessions_manage_view),
url(r'^sessions/manage/(?P<timeperiod>[\w\ ]+.*)$',
views.plannedsessions_manage_view),
url(r'^sessions/coach$',views.plannedsessions_coach_view),
url(r'^sessions/coach/(?P<timeperiod>[\w\ ]+.*)/team/(?P<teamid>\d+)$',
views.plannedsessions_coach_view),
url(r'^sessions/coach/(?P<timeperiod>[\w\ ]+.*)$',
views.plannedsessions_coach_view),
url(r'^sessions/?$',views.plannedsessions_view),
url(r'^sessions/rower/(?P<rowerid>\d+)$',views.plannedsessions_view),
url(r'^sessions/(?P<timeperiod>[\w\ ]+.*)/rower/(?P<rowerid>\d+)$',views.plannedsessions_view),
+1
View File
@@ -294,6 +294,7 @@ def calculate_age(born):
def my_dict_from_instance(instance,model):
thedict = {}
thedict['id'] = instance.id
for attr, value in instance.__dict__.iteritems():
try:
+68 -1
View File
@@ -11854,6 +11854,68 @@ def plannedsession_teamedit_view(request,timeperiod='thisweek',
'plannedsessions':sps,
})
@user_passes_test(iscoachmember,login_url="/rowers/planmembership/",
redirect_field_name=None)
def plannedsessions_coach_view(request,timeperiod='thisweek',
teamid=0):
startdate,enddate = get_dates_timeperiod(timeperiod)
if teamid != 0:
try:
theteam = Team.objects.get(id=teamid)
except Team.DoesNotExist:
theteam = False
else:
theteam = False
sps = get_sessions_manager(request.user,teamid=teamid,
enddate=enddate,
startdate=startdate)
rowers = []
for ps in sps:
rowers += ps.rower.all()
rowers = list(set(rowers))
statusdict = {}
for ps in sps:
rowerstatus = {}
for r in rowers:
ratio, status = is_session_complete(r,ps)
rowerstatus[r.id] = status
sessiondict = {
'results':rowerstatus,
'name': ps.name,
'startdate': ps.startdate,
'enddate': ps.enddate,
}
statusdict[ps.id] = sessiondict
unmatchedworkouts = []
for r in rowers:
unmatchedworkouts += Workout.objects.filter(
user=r,
plannedsession=None,
date__gte=startdate,date__lte=enddate)
myteams = Team.objects.filter(manager=request.user)
return render(request,'plannedsessionscoach.html',
{
'myteams':myteams,
'plannedsessions':sps,
'statusdict':statusdict,
'timeperiod':timeperiod,
'rowers':rowers,
'theteam':theteam,
'unmatchedworkouts':unmatchedworkouts,
'rower':getrower(request.user)
}
)
@login_required()
def plannedsessions_view(request,timeperiod='thisweek',rowerid=0):
@@ -12162,6 +12224,7 @@ def plannedsession_view(request,id=0,rowerid=0):
m = getrower(request.user)
if not rowerid:
r = m
else:
@@ -12176,8 +12239,11 @@ def plannedsession_view(request,id=0,rowerid=0):
if ps.manager != request.user and r not in ps.rower.all():
raise PermissionDenied("You do not have access to this session")
resultsdict = get_session_metrics(ps)
resultsdict = pd.DataFrame(resultsdict).transpose().to_dict()
psdict = my_dict_from_instance(ps,PlannedSession)
print psdict
ws = get_workouts_session(r,ps)
@@ -12196,7 +12262,8 @@ def plannedsession_view(request,id=0,rowerid=0):
'manager':m,
'rower':r,
'ratio':ratio,
'status':status
'status':status,
'results':resultsdict,
}
)
+2 -1
View File
@@ -139,9 +139,10 @@ cox {
.listtable tbody tr:nth-of-type(even) { background-color: #DDD; }
.listtable thead th {
font-weight: bold;
font-weight: bold;
}
.shortpadded td { padding: 3px 3px }
.paddedtable td { padding: 1px 20px }