submit race result now starts async process
This commit is contained in:
@@ -26,6 +26,8 @@ import numpy as np
|
||||
import dataprep
|
||||
import courses
|
||||
|
||||
from rowers.tasks import handle_check_race_course
|
||||
|
||||
# Low Level functions - to be called by higher level methods
|
||||
def add_workouts_plannedsession(ws,ps,r):
|
||||
result = 0
|
||||
@@ -660,11 +662,11 @@ def add_workout_race(ws,race,r):
|
||||
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
|
||||
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
|
||||
return result,comments,errors,0
|
||||
|
||||
|
||||
|
||||
@@ -673,7 +675,7 @@ def add_workout_race(ws,race,r):
|
||||
|
||||
if len(ids)>1 and race.sessiontype in ['test','coursetest','race']:
|
||||
errors.append('For tests, you can only attach one workout')
|
||||
return result,comments,errors
|
||||
return result,comments,errors,0
|
||||
|
||||
# start adding sessions
|
||||
for w in ws:
|
||||
@@ -682,10 +684,9 @@ def add_workout_race(ws,race,r):
|
||||
w.save()
|
||||
result += 1
|
||||
|
||||
comments.append('Your result has been submitted')
|
||||
else:
|
||||
errors.append('Workout %i did not match the race window' % w.id)
|
||||
return result,comments,errors
|
||||
return result,comments,errors,0
|
||||
|
||||
if result>0:
|
||||
username = r.user.first_name+' '+r.user.last_name
|
||||
@@ -693,16 +694,6 @@ def add_workout_race(ws,race,r):
|
||||
age = calculate_age(r.birthdate)
|
||||
else:
|
||||
age = None
|
||||
(
|
||||
coursetime,
|
||||
coursemeters,
|
||||
coursecompleted
|
||||
) = courses.get_time_course(ws,race.course)
|
||||
if not coursecompleted:
|
||||
errors.append('Your trajectory did not match the race course')
|
||||
return result,comments,errors
|
||||
|
||||
duration = totaltime_sec_to_string(coursetime)
|
||||
|
||||
records = VirtualRaceResult.objects.filter(
|
||||
userid=r.id,
|
||||
@@ -713,22 +704,20 @@ def add_workout_race(ws,race,r):
|
||||
|
||||
if ws[0].boattype != record.boattype:
|
||||
errors.append('Your workout boat type did not match the boat type you registered')
|
||||
return result,comments,errors
|
||||
return result,comments,errors,0
|
||||
|
||||
if ws[0].weightcategory != record.weightcategory:
|
||||
errors.append('Your workout weight category did not match the weight category you registered')
|
||||
return result,comments, errors
|
||||
return result,comments, errors,0
|
||||
|
||||
record.coursecompleted=coursecompleted
|
||||
record.distance = int(coursemeters)
|
||||
record.workoutid=ws[0].id
|
||||
record.duration = duration
|
||||
record.save()
|
||||
|
||||
job = myqueue(queue,handle_check_race_course,ws[0].csvfilename,
|
||||
ws[0].id,race.course.id,record.id)
|
||||
|
||||
add_workouts_plannedsession(ws,race,r)
|
||||
|
||||
|
||||
return result,comments,errors
|
||||
return result,comments,errors,job.id
|
||||
|
||||
def delete_race_result(workout,race):
|
||||
results = VirtualRaceResult.objects.filter(workoutid=workout.id,race=race)
|
||||
|
||||
Reference in New Issue
Block a user