fixed team session coach view
This commit is contained in:
@@ -42,8 +42,8 @@ def add_workouts_plannedsession(ws,ps,r):
|
|||||||
errors.append('For tests, you can only attach one workout')
|
errors.append('For tests, you can only attach one workout')
|
||||||
return result,comments,errors
|
return result,comments,errors
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
wold = Workout.objects.filter(plannedsession=ps,user=r)
|
wold = Workout.objects.filter(plannedsession=ps,user=r)
|
||||||
ids = [w.id for w in wold] + [w.id for w in ws]
|
ids = [w.id for w in wold] + [w.id for w in ws]
|
||||||
ids = list(set(ids))
|
ids = list(set(ids))
|
||||||
@@ -51,7 +51,7 @@ def add_workouts_plannedsession(ws,ps,r):
|
|||||||
if len(ids)>1 and ps.sessiontype in ['test','coursetest']:
|
if len(ids)>1 and ps.sessiontype in ['test','coursetest']:
|
||||||
errors.append('For tests, you can only attach one workout')
|
errors.append('For tests, you can only attach one workout')
|
||||||
return result,comments,errors
|
return result,comments,errors
|
||||||
|
|
||||||
# start adding sessions
|
# start adding sessions
|
||||||
for w in ws:
|
for w in ws:
|
||||||
if w.date>=ps.startdate and w.date<=ps.enddate:
|
if w.date>=ps.startdate and w.date<=ps.enddate:
|
||||||
@@ -63,7 +63,7 @@ def add_workouts_plannedsession(ws,ps,r):
|
|||||||
errors.append('Workout %i did not match session dates' % w.id)
|
errors.append('Workout %i did not match session dates' % w.id)
|
||||||
|
|
||||||
return result,comments,errors
|
return result,comments,errors
|
||||||
|
|
||||||
|
|
||||||
def remove_workout_plannedsession(w,ps):
|
def remove_workout_plannedsession(w,ps):
|
||||||
if w.plannedsession == ps:
|
if w.plannedsession == ps:
|
||||||
@@ -98,7 +98,7 @@ def get_session_metrics(ps):
|
|||||||
status = []
|
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
|
||||||
@@ -113,7 +113,7 @@ 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)[0]
|
rscorev += dataprep.workout_rscore(w)[0]
|
||||||
|
|
||||||
ratio,statusv,completiondate = is_session_complete_ws(ws,ps)
|
ratio,statusv,completiondate = is_session_complete_ws(ws,ps)
|
||||||
try:
|
try:
|
||||||
completedatev = completiondate.strftime('%Y-%m-%d')
|
completedatev = completiondate.strftime('%Y-%m-%d')
|
||||||
@@ -139,7 +139,7 @@ def get_session_metrics(ps):
|
|||||||
'rscore':rscore,
|
'rscore':rscore,
|
||||||
'trimp':trimp,
|
'trimp':trimp,
|
||||||
'completedate':completedate,
|
'completedate':completedate,
|
||||||
'status':status,
|
'status':status,
|
||||||
}
|
}
|
||||||
|
|
||||||
return thedict
|
return thedict
|
||||||
@@ -154,7 +154,7 @@ def is_session_complete_ws(ws,ps):
|
|||||||
return ratio,status,None
|
return ratio,status,None
|
||||||
else:
|
else:
|
||||||
return 0,'not done',None
|
return 0,'not done',None
|
||||||
|
|
||||||
value = ps.sessionvalue
|
value = ps.sessionvalue
|
||||||
if ps.sessionunit == 'min':
|
if ps.sessionunit == 'min':
|
||||||
value *= 60.
|
value *= 60.
|
||||||
@@ -171,7 +171,7 @@ def is_session_complete_ws(ws,ps):
|
|||||||
cratiomin = 0.9167
|
cratiomin = 0.9167
|
||||||
cratiomax = 1.0833
|
cratiomax = 1.0833
|
||||||
|
|
||||||
|
|
||||||
score = 0
|
score = 0
|
||||||
completiondate = None
|
completiondate = None
|
||||||
for w in ws:
|
for w in ws:
|
||||||
@@ -236,7 +236,7 @@ def is_session_complete_ws(ws,ps):
|
|||||||
else:
|
else:
|
||||||
if not completiondate:
|
if not completiondate:
|
||||||
completiondate = ws.reverse()[0].date
|
completiondate = ws.reverse()[0].date
|
||||||
return ratio,'partial',completiondate
|
return ratio,'partial',completiondate
|
||||||
elif ps.sessiontype == 'coursetest':
|
elif ps.sessiontype == 'coursetest':
|
||||||
if ps.course:
|
if ps.course:
|
||||||
(
|
(
|
||||||
@@ -274,19 +274,19 @@ def is_session_complete_ws(ws,ps):
|
|||||||
if not completiondate:
|
if not completiondate:
|
||||||
completiondate = ws.reverse()[0].date
|
completiondate = ws.reverse()[0].date
|
||||||
return ratio,status,completiondate
|
return ratio,status,completiondate
|
||||||
|
|
||||||
|
|
||||||
def is_session_complete(r,ps):
|
def is_session_complete(r,ps):
|
||||||
status = 'not done'
|
status = 'not done'
|
||||||
|
|
||||||
if r not in ps.rower.all():
|
if r not in ps.rower.all():
|
||||||
return 0,'not assigned',None
|
return 0,'not assigned',None
|
||||||
|
|
||||||
ws = Workout.objects.filter(user=r,plannedsession=ps)
|
ws = Workout.objects.filter(user=r,plannedsession=ps)
|
||||||
|
|
||||||
return is_session_complete_ws(ws,ps)
|
return is_session_complete_ws(ws,ps)
|
||||||
|
|
||||||
|
|
||||||
def rank_results(ps):
|
def rank_results(ps):
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
@@ -299,7 +299,7 @@ def add_team_session(t,ps):
|
|||||||
def add_rower_session(r,ps):
|
def add_rower_session(r,ps):
|
||||||
ps.rower.add(r)
|
ps.rower.add(r)
|
||||||
ps.save()
|
ps.save()
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
def remove_team_session(t,ps):
|
def remove_team_session(t,ps):
|
||||||
@@ -364,8 +364,11 @@ def get_sessions_manager(m,teamid=0,startdate=date.today(),
|
|||||||
enddate=date.today()+timezone.timedelta(+1000)):
|
enddate=date.today()+timezone.timedelta(+1000)):
|
||||||
if teamid:
|
if teamid:
|
||||||
t = Team.objects.get(id=teamid)
|
t = Team.objects.get(id=teamid)
|
||||||
|
rs = Rower.objects.filter(
|
||||||
|
team__in=[t]
|
||||||
|
).distinct()
|
||||||
sps = PlannedSession.objects.filter(
|
sps = PlannedSession.objects.filter(
|
||||||
team__in=[t],
|
rower__in=rs,
|
||||||
manager=m,
|
manager=m,
|
||||||
startdate__lte=enddate,
|
startdate__lte=enddate,
|
||||||
enddate__gte=startdate,
|
enddate__gte=startdate,
|
||||||
@@ -376,9 +379,9 @@ def get_sessions_manager(m,teamid=0,startdate=date.today(),
|
|||||||
startdate__lte=enddate,
|
startdate__lte=enddate,
|
||||||
enddate__gte=startdate,
|
enddate__gte=startdate,
|
||||||
).order_by("preferreddate","startdate","enddate")
|
).order_by("preferreddate","startdate","enddate")
|
||||||
|
|
||||||
return sps
|
return sps
|
||||||
|
|
||||||
def get_sessions(r,startdate=date.today(),
|
def get_sessions(r,startdate=date.today(),
|
||||||
enddate=date.today()+timezone.timedelta(+1000)):
|
enddate=date.today()+timezone.timedelta(+1000)):
|
||||||
|
|
||||||
@@ -387,7 +390,7 @@ def get_sessions(r,startdate=date.today(),
|
|||||||
startdate__lte=enddate,
|
startdate__lte=enddate,
|
||||||
enddate__gte=startdate,
|
enddate__gte=startdate,
|
||||||
).order_by("preferreddate","startdate","enddate")
|
).order_by("preferreddate","startdate","enddate")
|
||||||
|
|
||||||
return sps
|
return sps
|
||||||
|
|
||||||
def get_workouts_session(r,ps):
|
def get_workouts_session(r,ps):
|
||||||
|
|||||||
Reference in New Issue
Block a user