Private
Public Access
1
0

submission and show result fastest challenges

This commit is contained in:
Sander Roosendaal
2020-11-11 19:20:37 +01:00
parent cf16b2df0e
commit 1afd8b8d16
5 changed files with 42 additions and 19 deletions

View File

@@ -371,7 +371,7 @@ def add_workouts_plannedsession(ws,ps,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 in ['test','coursetest','race','fastest_distance','fastest_time']:
if len(ids)>1 and ps.sessiontype in ['test','coursetest','race']:
errors.append('For tests, you can only attach one workout')
return result,comments,errors
@@ -1571,19 +1571,6 @@ def add_workout_fastestrace(ws, race, r, recordid=0, doregister=False):
enddatetime
)
# check if all sessions have same date
dates = [w.date for w in ws]
if (not all(d == dates[0] for d in dates)) and race.sessiontype not in ['challenge','cycletarget']:
errors.append('For tests and training sessions, selected workouts must all be done on the same date')
return result,comments,errors,0
if len(ws)>1 and race.sessiontype == 'test':
errors.append('For tests, you can only attach one workout')
return result,comments,errors,0
ids = [w.id for w in ws]
ids = list(set(ids))
@@ -1671,7 +1658,7 @@ def add_workout_fastestrace(ws, race, r, recordid=0, doregister=False):
record.workoutid = ws[0].id
if race.sessiontype == 'fastest_distance':
df = dataprep.getsmallrowdata_db(['time','cumdist'],ids=[ws[0].id])
fastest_milliseconds = datautils.getfastest(df,race.sessionvalue,mode='distance')
fastest_milliseconds,startsecond,endsecond = datautils.getfastest(df,race.sessionvalue,mode='distance')
velo = race.sessionvalue/fastest_milliseconds
points = 100.*velo/record.referencespeed
@@ -1681,10 +1668,12 @@ def add_workout_fastestrace(ws, race, r, recordid=0, doregister=False):
record.duration = duration
record.distance = race.sessionvalue
record.points = points
record.startsecond = startsecond
record.endsecond = endsecond
record.save()
if race.sessiontype == 'fastest_time':
df = dataprep.getsmallrowdata_db(['time','cumdist'],ids=[ws[0].id])
fastest_meters = datautils.getfastest(df,race.sessionvalue,mode='time')
fastest_meters, startsecond, endsecond = datautils.getfastest(df,race.sessionvalue,mode='time')
velo = fastest_meters/(60.*race.sessionvalue)
points = 100.*velo/record.referencespeed
@@ -1694,6 +1683,8 @@ def add_workout_fastestrace(ws, race, r, recordid=0, doregister=False):
record.distance = fastest_meters
record.coursecompleted = True
record.points = points
record.startsecond = startsecond
record.endsecond = endsecond
record.save()