crude version of results submit
This commit is contained in:
@@ -8,7 +8,7 @@ from django.db import IntegrityError
|
||||
import uuid
|
||||
from django.conf import settings
|
||||
import pytz
|
||||
from utils import myqueue
|
||||
from utils import myqueue,calculate_age,totaltime_sec_to_string
|
||||
|
||||
import django_rq
|
||||
queue = django_rq.get_queue('default')
|
||||
@@ -18,7 +18,7 @@ queuehigh = django_rq.get_queue('low')
|
||||
from rowers.models import (
|
||||
Rower, Workout,Team,
|
||||
GeoCourse, TrainingMicroCycle,TrainingMesoCycle,TrainingMacroCycle,
|
||||
TrainingPlan,PlannedSession,
|
||||
TrainingPlan,PlannedSession,VirtualRaceResult
|
||||
)
|
||||
|
||||
import metrics
|
||||
@@ -596,3 +596,95 @@ def remove_rower_race(r,race):
|
||||
race.rower.remove(r)
|
||||
|
||||
return 1
|
||||
|
||||
# Low Level functions - to be called by higher level methods
|
||||
def add_workout_race(ws,race,r):
|
||||
result = 0
|
||||
comments = []
|
||||
errors = []
|
||||
|
||||
start_time = race.start_time
|
||||
start_date = race.startdate
|
||||
startdatetime = datetime.combine(start_date,start_time)
|
||||
startdatetime = pytz.timezone(race.timezone).localize(
|
||||
startdatetime
|
||||
)
|
||||
|
||||
end_time = race.end_time
|
||||
end_date = race.enddate
|
||||
enddatetime = datetime.combine(end_date,end_time)
|
||||
enddatetime = pytz.timezone(race.timezone).localize(
|
||||
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
|
||||
|
||||
if len(ws)>1 and race.sessiontype == 'test':
|
||||
errors.append('For tests, you can only attach one workout')
|
||||
return result,comments,errors
|
||||
|
||||
|
||||
|
||||
wold = Workout.objects.filter(plannedsession=race,user=r)
|
||||
ids = [w.id for w in wold] + [w.id for w in ws]
|
||||
ids = list(set(ids))
|
||||
|
||||
if len(ids)>1 and race.sessiontype in ['test','coursetest']:
|
||||
errors.append('For tests, you can only attach one workout')
|
||||
return result,comments,errors
|
||||
|
||||
# start adding sessions
|
||||
for w in ws:
|
||||
if w.startdatetime>=startdatetime and w.startdatetime<=enddatetime:
|
||||
w.plannedsession = race
|
||||
w.save()
|
||||
result += 1
|
||||
|
||||
comments.append('Your result has been submitted')
|
||||
else:
|
||||
errors.append('Workout %i did not match the race window' % w.id)
|
||||
|
||||
if result>0:
|
||||
username = r.user.first_name+' '+r.user.last_name
|
||||
if r.birthdate:
|
||||
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')
|
||||
|
||||
duration = totaltime_sec_to_string(coursetime)
|
||||
|
||||
record = VirtualRaceResult(
|
||||
user=r,
|
||||
username=username,
|
||||
workout = ws[0],
|
||||
race = race,
|
||||
coursecompleted=coursecompleted,
|
||||
duration = duration,
|
||||
boattype = ws[0].boattype,
|
||||
sex = r.sex,
|
||||
age = age,
|
||||
)
|
||||
|
||||
record.save()
|
||||
|
||||
|
||||
|
||||
return result,comments,errors
|
||||
|
||||
def delete_race_result(workout,race):
|
||||
results = VirtualRaceResult.objects.filter(workout=workout,race=race)
|
||||
for r in results:
|
||||
r.delete()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user