upload workout to fastest challenge now works
This commit is contained in:
@@ -15,7 +15,7 @@ from rowers.rows import validate_file_extension,must_be_csv,validate_image_exten
|
||||
from django.contrib.auth.forms import UserCreationForm
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.admin.widgets import AdminDateWidget
|
||||
from django.forms.widgets import SelectDateWidget
|
||||
from django.forms.widgets import SelectDateWidget,HiddenInput
|
||||
#from django.forms.extras.widgets import SelectDateWidget
|
||||
from django.utils import timezone,translation
|
||||
from django.forms import ModelForm, Select
|
||||
@@ -410,6 +410,8 @@ class UploadOptionsForm(forms.Form):
|
||||
initial='workout_edit_view',
|
||||
label='After Upload, go to')
|
||||
|
||||
raceid = forms.IntegerField(initial=0,widget=HiddenInput())
|
||||
|
||||
class Meta:
|
||||
fields = ['make_plot','plottype','upload_toc2','makeprivate']
|
||||
|
||||
@@ -448,6 +450,7 @@ class UploadOptionsForm(forms.Form):
|
||||
|
||||
if int(raceid) in [r.id for r in races]:
|
||||
therace = VirtualRace.objects.get(id=raceid)
|
||||
self.fields['raceid'].initial = therace.id
|
||||
if therace.sessiontype == 'race':
|
||||
registrations = VirtualRaceResult.objects.filter(race=therace,userid=r.id)
|
||||
else:
|
||||
|
||||
@@ -1498,23 +1498,33 @@ def default_class(r,w,race):
|
||||
boatclass=boatclass,
|
||||
adaptiveclass=adaptiveclass,
|
||||
boattype=boattype,
|
||||
sex=sex,
|
||||
).order_by(
|
||||
"agemax","-agemin","boattype","sex","weightclass",
|
||||
"referencespeed"
|
||||
)
|
||||
if standards.count()==0:
|
||||
# omit adaptive class
|
||||
standards = CourseStandard.objects.filter(
|
||||
agemin__lt=age,agemax__gt=age,
|
||||
boattype=boattype
|
||||
boattype=boattype,sex=sex,
|
||||
).order_by(
|
||||
"agemax","-agemin","boattype","sex",
|
||||
"weightclass","referencespeed")
|
||||
if standards.count()==0:
|
||||
# omit boattype
|
||||
standards = CourseStandard.objects.filter(
|
||||
agemin__lt=age,agemax__gt=age
|
||||
agemin__lt=age,agemax__gt=age,sex=sex,
|
||||
).order_by(
|
||||
"agemax","-agemin","boattype","sex",
|
||||
"weightclass","referencespeed")
|
||||
if standards.count()==0:
|
||||
# omit boattype
|
||||
standards = CourseStandard.objects.filter(
|
||||
agemin__lt=age,agemax__gt=age,sex='male',
|
||||
).order_by(
|
||||
"agemax","-agemin","boattype","sex",
|
||||
"weightclass","referencespeed")
|
||||
|
||||
if standards.count()==0:
|
||||
# boolean, boattype, boatclass, adaptiveclass, weightclass, sex, coursestandard,
|
||||
@@ -1648,22 +1658,28 @@ def add_workout_fastestrace(ws, race, r, recordid=0, doregister=False):
|
||||
if race.sessiontype == 'fastest_distance':
|
||||
df = dataprep.getsmallrowdata_db(['time','cumdist'],ids=[ws[0].id])
|
||||
fastest_milliseconds = datautils.getfastest(df,race.sessionvalue,mode='distance')
|
||||
velo = race.sessionvalue/fastest_milliseconds
|
||||
points = 100.*velo/record.referencespeed
|
||||
|
||||
if fastest_milliseconds > 0:
|
||||
duration = to_time(1000.*fastest_milliseconds)
|
||||
record.coursecompleted = True
|
||||
record.duration = duration
|
||||
record.distance = race.sessionvalue
|
||||
record.points = points
|
||||
record.save()
|
||||
if race.sessiontype == 'fastest_time':
|
||||
df = dataprep.getsmallrowdata_db(['time','cumdist'],ids=[w.id])
|
||||
fastest_meters = datautils.getfastest(df,ps.sessionvalue,mode='time')
|
||||
df = dataprep.getsmallrowdata_db(['time','cumdist'],ids=[ws[0].id])
|
||||
fastest_meters = datautils.getfastest(df,race.sessionvalue,mode='time')
|
||||
velo = fastest_meters/(60.*race.sessionvalue)
|
||||
points = 100.*velo/record.referencespeed
|
||||
|
||||
if fastest_meters > 0:
|
||||
duration = dt.time(0,ps.sessionvalue)
|
||||
duration = dt.time(0,race.sessionvalue)
|
||||
record.duration = duration
|
||||
record.distance = fastest_meters
|
||||
record.coursecompleted = True
|
||||
record.points = points
|
||||
record.save()
|
||||
|
||||
|
||||
@@ -1674,6 +1690,8 @@ def add_workout_fastestrace(ws, race, r, recordid=0, doregister=False):
|
||||
comments.append('Workouts submitted to virtual events have to be public. We have changed the workout to a public workout.')
|
||||
|
||||
record.save()
|
||||
else:
|
||||
errors.append('Could not find a valid interval in this workout')
|
||||
|
||||
return result, comments, errors, 0
|
||||
|
||||
|
||||
@@ -5017,7 +5017,7 @@ def workout_upload_view(request,
|
||||
response = {}
|
||||
if request.method == 'POST':
|
||||
form = DocumentsForm(request.POST,request.FILES)
|
||||
optionsform = UploadOptionsForm(request.POST,request=request,raceid=raceid)
|
||||
optionsform = UploadOptionsForm(request.POST,request=request)
|
||||
|
||||
if form.is_valid():
|
||||
# f = request.FILES['file']
|
||||
@@ -5058,6 +5058,7 @@ def workout_upload_view(request,
|
||||
upload_to_tp = optionsform.cleaned_data['upload_to_TrainingPeaks']
|
||||
makeprivate = optionsform.cleaned_data['makeprivate']
|
||||
landingpage = optionsform.cleaned_data['landingpage']
|
||||
raceid = optionsform.cleaned_data['raceid']
|
||||
|
||||
try:
|
||||
registrationid = optionsform.cleaned_data['submitrace']
|
||||
@@ -5285,11 +5286,27 @@ def workout_upload_view(request,
|
||||
messages.info(request,c)
|
||||
for er in errors:
|
||||
messages.error(request,er)
|
||||
elif race.sessiontype in ['fastest_time','fastest_distance']:
|
||||
result,comments,errors,jobid = add_workout_fastestrace(
|
||||
[w], race,r,doregister=True,
|
||||
)
|
||||
if result:
|
||||
messages.info(request,"We have submitted your workout to the race")
|
||||
for c in comments:
|
||||
messages.info(request,c)
|
||||
for er in errors:
|
||||
messages.error(request,er)
|
||||
|
||||
if int(registrationid)>0:
|
||||
races = VirtualRace.objects.filter(
|
||||
registration_closure__gt=timezone.now()
|
||||
)
|
||||
if raceid != 0:
|
||||
races = VirtualRace.objects.filter(
|
||||
registration_closure__gt=timezone.now(),
|
||||
id=raceid,
|
||||
)
|
||||
|
||||
registrations = IndoorVirtualRaceResult.objects.filter(
|
||||
race__in = races,
|
||||
id=registrationid,
|
||||
@@ -5306,8 +5323,13 @@ def workout_upload_view(request,
|
||||
registrations = registrations.filter(id=registrationid)
|
||||
if registrations:
|
||||
race = registrations[0].race
|
||||
result,comments,errors,jobid = add_workout_indoorrace(
|
||||
[w],race,r,recordid=registrations[0].id
|
||||
if race.sessiontype == 'indoorrace':
|
||||
result,comments,errors,jobid = add_workout_indoorrace(
|
||||
[w],race,r,recordid=registrations[0].id
|
||||
)
|
||||
elif race.sessiontype in ['fastest_time','fastest_distance']:
|
||||
result,comments, errors,jobid = add_workout_fastestrace(
|
||||
[w],race,r,recordid=registrations[0].id
|
||||
)
|
||||
|
||||
if result:
|
||||
@@ -5326,9 +5348,14 @@ def workout_upload_view(request,
|
||||
registrations = registrations2.filter(id=registrationid)
|
||||
if registrations:
|
||||
race = registrations[0].race
|
||||
result,comments,errors,jobid = add_workout_race(
|
||||
[w], race,r,recordid=registrations[0].id
|
||||
)
|
||||
if race.sessiontype == 'race':
|
||||
result,comments,errors,jobid = add_workout_race(
|
||||
[w], race,r,recordid=registrations[0].id
|
||||
)
|
||||
elif race.sessiontype in ['fastest_time','fastest_distance']:
|
||||
result, comments, errors, jobid = add_workout_fastestrace(
|
||||
[w],race,r,recordid=registrations[0].id
|
||||
)
|
||||
if result:
|
||||
messages.info(
|
||||
request,
|
||||
|
||||
Reference in New Issue
Block a user