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