more robust race form
This commit is contained in:
@@ -699,6 +699,15 @@ class WorkoutSessionSelectForm(forms.Form):
|
|||||||
)
|
)
|
||||||
|
|
||||||
class WorkoutRaceSelectForm(forms.Form):
|
class WorkoutRaceSelectForm(forms.Form):
|
||||||
|
evaluate_after = forms.TimeField(
|
||||||
|
input_formats=['%H:%M:%S.%f',
|
||||||
|
'%H:%M:%S',
|
||||||
|
'%H:%M:%S',
|
||||||
|
'%M:%S.%f',
|
||||||
|
'%M:%S',
|
||||||
|
'%M'],
|
||||||
|
label = 'Only Evaluate After:',
|
||||||
|
required=False)
|
||||||
|
|
||||||
def __init__(self, workoutdata, *args, **kwargs):
|
def __init__(self, workoutdata, *args, **kwargs):
|
||||||
|
|
||||||
@@ -710,7 +719,9 @@ class WorkoutRaceSelectForm(forms.Form):
|
|||||||
initial=workoutdata['initial'],
|
initial=workoutdata['initial'],
|
||||||
widget=forms.RadioSelect,
|
widget=forms.RadioSelect,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# self.fields['evaluate_after'] =
|
||||||
|
|
||||||
class PlannedSessionTeamForm(forms.Form):
|
class PlannedSessionTeamForm(forms.Form):
|
||||||
team = forms.ModelMultipleChoiceField(
|
team = forms.ModelMultipleChoiceField(
|
||||||
queryset=Team.objects.all(),
|
queryset=Team.objects.all(),
|
||||||
|
|||||||
@@ -1367,8 +1367,14 @@ class VirtualRaceForm(ModelForm):
|
|||||||
course = cd['course']
|
course = cd['course']
|
||||||
geocourse = GeoCourse.objects.get(id=course.id)
|
geocourse = GeoCourse.objects.get(id=course.id)
|
||||||
timezone_str = get_course_timezone(geocourse)
|
timezone_str = get_course_timezone(geocourse)
|
||||||
|
|
||||||
start_time = cd['start_time']
|
start_time = cd['start_time']
|
||||||
|
if start_time is None:
|
||||||
|
raise forms.ValidationError(
|
||||||
|
'Must have start time',
|
||||||
|
code='missing_yparam1'
|
||||||
|
)
|
||||||
|
|
||||||
start_date = cd['startdate']
|
start_date = cd['startdate']
|
||||||
startdatetime = datetime.datetime.combine(start_date,start_time)
|
startdatetime = datetime.datetime.combine(start_date,start_time)
|
||||||
startdatetime = pytz.timezone(timezone_str).localize(
|
startdatetime = pytz.timezone(timezone_str).localize(
|
||||||
@@ -1376,6 +1382,12 @@ class VirtualRaceForm(ModelForm):
|
|||||||
)
|
)
|
||||||
|
|
||||||
end_time = cd['end_time']
|
end_time = cd['end_time']
|
||||||
|
if end_time is None:
|
||||||
|
raise forms.ValidationError(
|
||||||
|
'Must have end time',
|
||||||
|
code='missing endtime'
|
||||||
|
)
|
||||||
|
|
||||||
end_date = cd['enddate']
|
end_date = cd['enddate']
|
||||||
enddatetime = datetime.datetime.combine(end_date,end_time)
|
enddatetime = datetime.datetime.combine(end_date,end_time)
|
||||||
enddatetime = pytz.timezone(timezone_str).localize(
|
enddatetime = pytz.timezone(timezone_str).localize(
|
||||||
|
|||||||
@@ -712,7 +712,7 @@ def remove_rower_race(r,race):
|
|||||||
return 1
|
return 1
|
||||||
|
|
||||||
# Low Level functions - to be called by higher level methods
|
# Low Level functions - to be called by higher level methods
|
||||||
def add_workout_race(ws,race,r):
|
def add_workout_race(ws,race,r,splitsecond=0):
|
||||||
result = 0
|
result = 0
|
||||||
comments = []
|
comments = []
|
||||||
errors = []
|
errors = []
|
||||||
@@ -750,6 +750,29 @@ def add_workout_race(ws,race,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,0
|
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
|
||||||
|
|
||||||
|
records = VirtualRaceResult.objects.filter(
|
||||||
|
userid=r.id,
|
||||||
|
race=race
|
||||||
|
)
|
||||||
|
|
||||||
|
record = records[0]
|
||||||
|
|
||||||
|
if ws[0].boattype != record.boattype:
|
||||||
|
errors.append('Your workout boat type did not match the boat type you registered')
|
||||||
|
return 0,comments,errors,0
|
||||||
|
|
||||||
|
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
|
# start adding sessions
|
||||||
for w in ws:
|
for w in ws:
|
||||||
if w.startdatetime>=startdatetime and w.startdatetime<=enddatetime:
|
if w.startdatetime>=startdatetime and w.startdatetime<=enddatetime:
|
||||||
@@ -762,30 +785,9 @@ def add_workout_race(ws,race,r):
|
|||||||
return result,comments,errors,0
|
return result,comments,errors,0
|
||||||
|
|
||||||
if result>0:
|
if result>0:
|
||||||
username = r.user.first_name+' '+r.user.last_name
|
|
||||||
if r.birthdate:
|
|
||||||
age = calculate_age(r.birthdate)
|
|
||||||
else:
|
|
||||||
age = None
|
|
||||||
|
|
||||||
records = VirtualRaceResult.objects.filter(
|
|
||||||
userid=r.id,
|
|
||||||
race=race
|
|
||||||
)
|
|
||||||
|
|
||||||
record = records[0]
|
|
||||||
|
|
||||||
if ws[0].boattype != record.boattype:
|
|
||||||
errors.append('Your workout boat type did not match the boat type you registered')
|
|
||||||
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,0
|
|
||||||
|
|
||||||
|
|
||||||
job = myqueue(queue,handle_check_race_course,ws[0].csvfilename,
|
job = myqueue(queue,handle_check_race_course,ws[0].csvfilename,
|
||||||
ws[0].id,race.course.id,record.id)
|
ws[0].id,race.course.id,record.id,splitsecond=splitsecond)
|
||||||
|
|
||||||
add_workouts_plannedsession(ws,race,r)
|
add_workouts_plannedsession(ws,race,r)
|
||||||
|
|
||||||
|
|||||||
@@ -210,6 +210,11 @@ def handle_check_race_course(self,
|
|||||||
else:
|
else:
|
||||||
debug = False
|
debug = False
|
||||||
|
|
||||||
|
if 'splitsecond' in kwargs:
|
||||||
|
splitsecond = kwargs['splitsecond']
|
||||||
|
else:
|
||||||
|
splitsecond = 0
|
||||||
|
|
||||||
mode = 'race'
|
mode = 'race'
|
||||||
if 'mode' in kwargs:
|
if 'mode' in kwargs:
|
||||||
mode = kwargs['mode']
|
mode = kwargs['mode']
|
||||||
@@ -236,10 +241,10 @@ def handle_check_race_course(self,
|
|||||||
' ElapsedTime (sec)': 'time',
|
' ElapsedTime (sec)': 'time',
|
||||||
}, inplace=True)
|
}, inplace=True)
|
||||||
|
|
||||||
|
|
||||||
rowdata.fillna(method='backfill',inplace=True)
|
rowdata.fillna(method='backfill',inplace=True)
|
||||||
|
|
||||||
rowdata['time'] = rowdata['time']-rowdata.ix[0,'time']
|
rowdata['time'] = rowdata['time']-rowdata.ix[0,'time']
|
||||||
|
rowdata = rowdata[rowdata['time']>splitsecond]
|
||||||
# we may want to expand the time (interpolate)
|
# we may want to expand the time (interpolate)
|
||||||
rowdata['dt'] = rowdata['time'].apply(
|
rowdata['dt'] = rowdata['time'].apply(
|
||||||
lambda x: timedelta(seconds=x)
|
lambda x: timedelta(seconds=x)
|
||||||
|
|||||||
@@ -31,17 +31,35 @@
|
|||||||
<p>Select one of the following workouts that you rowed within the race window</p>
|
<p>Select one of the following workouts that you rowed within the race window</p>
|
||||||
<table width="100%">
|
<table width="100%">
|
||||||
<tr>
|
<tr>
|
||||||
{% for field in w_form.hidden_fields %}
|
{% for field in w_form.hidden_fields %}
|
||||||
{{ field }}
|
|
||||||
{% endfor %}
|
|
||||||
{% for field in w_form.visible_fields %}
|
|
||||||
<td>
|
|
||||||
{{ field }}
|
{{ field }}
|
||||||
</td>
|
{% endfor %}
|
||||||
|
{% for field in w_form.visible_fields %}
|
||||||
|
<td>
|
||||||
|
{{ field.label }}
|
||||||
|
{{ field }}
|
||||||
|
</td>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="grid_6 omega">
|
||||||
|
<p>The "Only Evaluate After" field allows you to tell the site to
|
||||||
|
discard the first N minutes fo the workout. This is useful if you
|
||||||
|
paddled through the start polygon as part of your warming up.
|
||||||
|
Fill out the
|
||||||
|
time at which you want to start the evaluation, or leave empty to
|
||||||
|
evaluate the entire workout. </p>
|
||||||
|
<p>Use any of the following formats:
|
||||||
|
<ul>
|
||||||
|
<li>H:MM:SS.d, e.g. 1:45:00.0 for one hour and 45 minutes</li>
|
||||||
|
<li>H:MM:SS, e.g. 1:45:00 for one hour and 45 minutes</li>
|
||||||
|
<li>MM:SS.d, e.g. 30:00.0 for thirty minutes</li>
|
||||||
|
<li>MM, e.g. 30 for thirty minutes</li>
|
||||||
|
</ul>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="grid_2 prefix_2 suffix_8">
|
<div class="grid_2 prefix_2 suffix_8">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
|||||||
@@ -13797,22 +13797,30 @@ def virtualevent_submit_result_view(request,id=0):
|
|||||||
|
|
||||||
if w_form.is_valid():
|
if w_form.is_valid():
|
||||||
selectedworkout = w_form.cleaned_data['workouts']
|
selectedworkout = w_form.cleaned_data['workouts']
|
||||||
|
splittime = w_form.cleaned_data['evaluate_after']
|
||||||
|
if splittime is not None:
|
||||||
|
splitsecond = splittime.hour*3600
|
||||||
|
splitsecond += splittime.minute*60
|
||||||
|
splitsecond += splittime.second
|
||||||
|
splitsecond += splittime.microsecond/1.e6
|
||||||
|
else:
|
||||||
|
splitsecond = 0
|
||||||
else:
|
else:
|
||||||
selectedworkout = None
|
selectedworkout = None
|
||||||
|
|
||||||
|
|
||||||
for w in ws:
|
|
||||||
remove_workout_plannedsession(w,race)
|
|
||||||
|
|
||||||
if selectedworkout is not None:
|
if selectedworkout is not None:
|
||||||
|
|
||||||
for w in ws:
|
|
||||||
remove_workout_plannedsession(w,race)
|
|
||||||
delete_race_result(w,race)
|
|
||||||
|
|
||||||
workouts = Workout.objects.filter(id=selectedworkout)
|
workouts = Workout.objects.filter(id=selectedworkout)
|
||||||
|
|
||||||
result,comments,errors,jobid = add_workout_race(workouts,race,r)
|
result,comments,errors,jobid = add_workout_race(
|
||||||
|
workouts,race,r,
|
||||||
|
splitsecond=splitsecond)
|
||||||
|
if result:
|
||||||
|
for w in ws:
|
||||||
|
remove_workout_plannedsession(w,race)
|
||||||
|
delete_race_result(w,race)
|
||||||
|
|
||||||
for c in comments:
|
for c in comments:
|
||||||
messages.info(request,c)
|
messages.info(request,c)
|
||||||
|
|||||||
Reference in New Issue
Block a user