diff --git a/rowers/models.py b/rowers/models.py index 2eca5a37..0b5ed03f 100644 --- a/rowers/models.py +++ b/rowers/models.py @@ -2252,7 +2252,7 @@ class VirtualRace(PlannedSession): validators=[validate_email],blank=True) coursestandards = models.ForeignKey(StandardCollection,null=True,on_delete=models.SET_NULL, - verbose_name='Standard Times') + verbose_name='Standard Times',blank=True) def __str__(self): @@ -2954,6 +2954,7 @@ class VirtualRaceResult(models.Model): startsecond = models.FloatField(default=0) endsecond = models.FloatField(default=0) + referencespeed = models.FloatField(default=5.0) entrycategory = models.ForeignKey(CourseStandard,null=True,on_delete=models.SET_NULL, verbose_name='Group') diff --git a/rowers/plannedsessions.py b/rowers/plannedsessions.py index 4c859b65..5201c279 100644 --- a/rowers/plannedsessions.py +++ b/rowers/plannedsessions.py @@ -1514,6 +1514,7 @@ def add_workout_race(ws,race,r,splitsecond=0,recordid=0): return 0,comments,errors,0 if ws[0].workouttype != record.boatclass: + print(ws[0].workouttype,record.boatclass) errors.append('Your workout boat class is different than on your race registration') return 0,comments,errors,0 @@ -1551,7 +1552,8 @@ def add_workout_race(ws,race,r,splitsecond=0,recordid=0): comments.append('Workouts submitted to virtual events have to be public. We have changed the workout to a public workout.') job = myqueue(queue,handle_check_race_course,ws[0].csvfilename, - ws[0].id,race.course.id,record.id,splitsecond=splitsecond) + ws[0].id,race.course.id,record.id,splitsecond=splitsecond, + referencespeed=record.referencespeed) diff --git a/rowers/scoring.py b/rowers/scoring.py index 915a799b..38cba81a 100644 --- a/rowers/scoring.py +++ b/rowers/scoring.py @@ -17,6 +17,10 @@ def save_scoring(name,user,filename,id=0,notes=""): collection.name = name collection.notes = notes collection.save() + standards = CourseStandard.objects.filter(standardcollection=collection) + for standard in standards: + print(standard,collection) + standard.delete() except StandardCollection.DoesNotExist: return 0 @@ -56,6 +60,20 @@ def save_scoring(name,user,filename,id=0,notes=""): try: boatclass = row['BoatClass'] + if boatclass.lower() in ['standard','olympic','normal']: + boatclass = 'water' + elif boatclass.lower() in ['erg','c2','concept','static']: + boatclass = 'rower' + elif boatclass.lower() in ['dynamic']: + boatclass = 'dynamic' + elif boatclass.lower() in ['slides','slide','slider','sliders']: + boatclass = 'slides' + elif boatclass.lower() in ['c','c-boat']: + boatclass = 'c-boat' + elif boatclass.lower() in ['coastal','coast']: + boatclass = 'coastal' + elif boatclass.lower() in ['church','churchboat','finnish','finland']: + boatclass = 'churchboat' except KeyError: boatclass = 'water' diff --git a/rowers/tasks.py b/rowers/tasks.py index 71eca7bb..f2408632 100644 --- a/rowers/tasks.py +++ b/rowers/tasks.py @@ -353,6 +353,16 @@ def handle_check_race_course(self, else: splitsecond = 0 + if 'referencespeed' in kwargs: + referencespeed = kwargs['referencespeed'] + else: + referencespeed = 5.0 + + if 'coursedistance' in kwargs: + coursedistance = kwargs['coursedistance'] + else: + coursedistance = 0 + mode = 'race' if 'mode' in kwargs: mode = kwargs['mode'] @@ -479,22 +489,28 @@ def handle_check_race_course(self, else: coursecompleted = False - + points = 0 if coursecompleted: - query = 'UPDATE rowers_virtualraceresult SET coursecompleted = 1, duration = "{duration}", distance = {distance}, workoutid = {workoutid}, startsecond = {startsecond}, endsecond = {endsecond} WHERE id={recordid}'.format( + if coursedistance == 0: + coursedistance = coursemeters + velo = coursedistance/coursetimeseconds + points = int(100*(2.-referencespeed/velo)) + query = 'UPDATE rowers_virtualraceresult SET coursecompleted = 1, duration = "{duration}", distance = {distance}, workoutid = {workoutid}, startsecond = {startsecond}, endsecond = {endsecond}, points={points} WHERE id={recordid}'.format( recordid=recordid, duration=totaltime_sec_to_string(coursetimeseconds), distance=int(coursemeters), + points=points, workoutid=workoutid, startsecond=startsecond, endsecond=endsecond, ) if mode == 'coursetest': - query = 'UPDATE rowers_coursetestresult SET coursecompleted = 1, duration = "{duration}", distance = {distance}, workoutid = {workoutid}, startsecond = {startsecond}, endsecond = {endsecond} WHERE id={recordid}'.format( + query = 'UPDATE rowers_coursetestresult SET coursecompleted = 1, duration = "{duration}", distance = {distance}, workoutid = {workoutid}, startsecond = {startsecond}, endsecond = {endsecond}, points={points} WHERE id={recordid}'.format( recordid=recordid, duration=totaltime_sec_to_string(coursetimeseconds), distance=int(coursemeters), + points=points, workoutid=workoutid, startsecond=startsecond, endsecond=endsecond, diff --git a/rowers/templates/standard_form.html b/rowers/templates/standard_form.html index 777c1857..2e8c2314 100644 --- a/rowers/templates/standard_form.html +++ b/rowers/templates/standard_form.html @@ -187,7 +187,7 @@ $.ajax({ data: data, type: $(this).attr('method'), - url: '/rowers/standards/upload/', + url: window.location.pathname, contentType: false, processData: false, error: function(result) { diff --git a/rowers/templates/virtualevent.html b/rowers/templates/virtualevent.html index 3589b469..cd8c6ccc 100644 --- a/rowers/templates/virtualevent.html +++ b/rowers/templates/virtualevent.html @@ -268,7 +268,9 @@