Private
Public Access
1
0

initial incomplete version

This commit is contained in:
Sander Roosendaal
2018-11-27 17:49:02 +01:00
parent f403d1bf16
commit 8162b2fc45
10 changed files with 815 additions and 52 deletions

View File

@@ -20,7 +20,7 @@ from rowers.models import (
Rower, Workout,Team,
GeoCourse, TrainingMicroCycle,TrainingMesoCycle,TrainingMacroCycle,
TrainingPlan,PlannedSession,VirtualRaceResult,CourseTestResult,
get_course_timezone
get_course_timezone, IndoorVirtualRaceResult
)
from rowers.courses import get_time_course
@@ -574,6 +574,56 @@ def update_plannedsession(ps,cd):
return 1,'Planned Session Updated'
def update_indoorvirtualrace(ps,cd):
for attr, value in cd.items():
if attr == 'comment':
value.replace("\r\n", "&#10");
value.replace("\n", "&#10");
setattr(ps, attr, value)
timezone_str = cd['timezone']
# correct times
startdatetime = datetime.combine(cd['startdate'],cd['start_time'])
enddatetime = datetime.combine(cd['enddate'],cd['end_time'])
startdatetime = pytz.timezone(timezone_str).localize(
startdatetime
)
enddatetime = pytz.timezone(timezone_str).localize(
enddatetime
)
ps.evaluation_closure = pytz.timezone(timezone_str).localize(
ps.evaluation_closure.replace(tzinfo=None)
)
registration_form = cd['registration_form']
registration_closure = cd['registration_closure']
if registration_form == 'manual':
try:
registration_closure = pytz.timezone(
timezone_str
).localize(
registration_closure.replace(tzinfo=None)
)
except AttributeError:
registration_closure = startdatetime
elif registration_form == 'windowstart':
registration_closure = startdatetime
elif registration_form == 'windowend':
registration_closure = enddatetime
else:
registration_closure = ps.evaluation_closure
ps.registration_closure = registration_closure
ps.timezone = timezone_str
ps.save()
return 1,'Virtual Race Updated'
def update_virtualrace(ps,cd):
for attr, value in cd.items():
if attr == 'comment':
@@ -708,6 +758,10 @@ def race_can_resubmit(r,race):
return False
def race_can_adddiscipline(r,race):
if race.sessiontype != 'race':
return False
records = VirtualRaceResult.objects.filter(
userid=r.id,
race=race)
@@ -813,6 +867,116 @@ def remove_rower_race(r,race,recordid=None):
return 1
# Low Level functions - to be called by higher level methods
def add_workout_indoorrace(ws,race,r,recordid=0):
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,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))
if len(ids)>1 and race.sessiontype in ['test','coursetest','race','indoorrace']:
errors.append('For tests, you can only attach one workout')
return result,comments,errors,0
username = r.user.first_name+' '+r.user.last_name
if r.birthdate:
age = calculate_age(r.birthdate)
else:
age = None
record = IndoorVirtualRaceResult.objects.get(
userid=r.id,
race=race,
id=recordid
)
records = IndoorVirtualRaceResult.objects.filter(
userid=r.id,
race=race,
workoutid = ws[0].id
)
if not record:
errors.append("Couldn't find this entry")
return result,comments,errors,0
if race.sessionmode == 'distance':
if ws[0].distance != race.sessionvalue:
errors.append('Your workout did not have the correct distance')
return 0,comments, errors, 0
else:
record.distance = ws[0].distance
record.duration = ws[0].duration
else:
t = ws[0].duration
seconds = t.second+t.minute*60.+t.hour*3600.+t.microsecond/1.e6
if seconds != race.sessionvalue*60.:
errors.append('Your workout did not have the correct duration')
return 0, comments, errors, 0
else:
record.distance = ws[0].distance
record.duration = ws[0].duration
if ws[0].weightcategory != record.weightcategory:
errors.append('Your workout weight category did not match the weight category you registered')
return 0,comments, errors,0
# start adding sessions
if ws[0].startdatetime>=startdatetime and ws[0].startdatetime<=enddatetime:
ws[0].plannedsession = race
ws[0].save()
result += 1
else:
errors.append('Workout %i did not match the race window' % ws[0].id)
return result,comments,errors,0
if result>0:
for otherrecord in records:
otherrecord.workoutid = None
otherrecord.coursecompleted = False
otherrecord.save()
record.coursecompleted = True
record.workoutid = ws[0].id
record.save()
add_workouts_plannedsession(ws,race,r)
return result,comments,errors,0
def add_workout_race(ws,race,r,splitsecond=0,recordid=0):
result = 0
comments = []
@@ -895,7 +1059,6 @@ def add_workout_race(ws,race,r,splitsecond=0,recordid=0):
if result>0:
for otherrecord in records:
print otherrecord
otherrecord.workoutid = None
otherrecord.coursecompleted = False
otherrecord.save()