diff --git a/rowers/courses.py b/rowers/courses.py index eb8967be..59048cd1 100644 --- a/rowers/courses.py +++ b/rowers/courses.py @@ -22,6 +22,74 @@ import xml.etree.ElementTree as et from xml.etree.ElementTree import Element, SubElement, Comment, tostring from xml.dom import minidom +# distance of course from lat_lon in km +def howfaris(lat_lon,course): + coords = course.coord + distance = geo_distance(lat_lon[0],lat_lon[1],coords[0],coords[1])[0] + + return distance + +#whatisnear = 150 + +# get nearest races +def getnearestraces(lat_lon,races,whatisnear=150): + newlist = [] + counter = 0 + for race in races: + if race.course is None: # pragma: no cover + newlist.append(race) + else: + c = race.course + coords = c.coord + distance = howfaris(lat_lon,c) + if distance < whatisnear: + newlist.append(race) + counter += 1 + + if counter>0: + races = newlist + else: + courseraces = races.exclude(course__isnull=True) + orders = [(c.id,howfaris(lat_lon,c.course)) for c in courseraces] + orders = sorted(orders,key = lambda tup:tup[1]) + ids = [id for id,distance in orders[0:4]] + for id, distance in orders[5:]: # pragma: no cover + if distance0: + courses = newlist + else: + orders = [(c.id,howfaris(lat_lon,c)) for c in courses] + orders = sorted(orders,key = lambda tup:tup[1]) + ids = [id for id,distance in orders[0:4]] + for id, distance in orders[5:]: + if distance 0 and longitude.std() > 0: + return True, latmean,lonmean + + return False, latmean,lonmean + + def workout_summary_to_df( rower, startdate=datetime.datetime(1970,1,1), diff --git a/rowers/forms.py b/rowers/forms.py index 7e18b393..6f27093e 100644 --- a/rowers/forms.py +++ b/rowers/forms.py @@ -1128,27 +1128,28 @@ class PlanSelectForm(forms.Form): "price","shortname" ) - class CourseSelectForm(forms.Form): course = forms.ModelChoiceField(queryset=GeoCourse.objects.filter()) def __init__(self, *args, **kwargs): # pragma: no cover course = kwargs.pop('course',None) manager = kwargs.pop('manager',None) + choices = kwargs.pop('choices',[]) super(CourseSelectForm,self).__init__(*args,**kwargs) + if len(choices)>0: + self.fields['course'].queryset = GeoCourse.objects.filter(id__in=[c.id for c in choices]) if course is not None: d_min = 0.5*course.distance d_max = 2*course.distance country = course.country countries = ['unknown',country] - print(countries) + self.fields['course'].queryset = self.fields['course'].queryset.filter( distance__gt = d_min,distance__lt = d_max, country__in = countries ).exclude(id=course.id) if manager is not None: self.fields['course'].queryset = self.fields['course'].queryset.filter(manager=manager) - print(self.fields['course'].queryset) class WorkoutSingleSelectForm(forms.Form): workout = forms.ModelChoiceField( diff --git a/rowers/models.py b/rowers/models.py index 82349291..b7b2e6f2 100644 --- a/rowers/models.py +++ b/rowers/models.py @@ -3408,7 +3408,8 @@ class VirtualRaceResult(models.Model): verbose_name="Adaptive Class") skillclass = models.CharField(default="Open",max_length=50, verbose_name="Skill Class") - race = models.ForeignKey(VirtualRace,on_delete=models.CASCADE,related_name='entries') + race = models.ForeignKey(VirtualRace,on_delete=models.CASCADE,related_name='entries', + blank=True,null=True) duration = models.TimeField(default=datetime.time(1,0)) distance = models.IntegerField(default=0) points = models.FloatField(default=0) @@ -3448,6 +3449,10 @@ class VirtualRaceResult(models.Model): return False if self.skillclass != other.skillclass: return False + if self.race is None and other.race is not None: + return False + if self.rae is not None and other.race is None: + return False if self.race != other.race: return False if self.boatclass != other.boatclass: @@ -3522,7 +3527,7 @@ class IndoorVirtualRaceResult(models.Model): verbose_name="Adaptive Class") skillclass = models.CharField(default="Open",max_length=50, verbose_name="Skill Class") - race = models.ForeignKey(VirtualRace,on_delete=models.CASCADE) + race = models.ForeignKey(VirtualRace,on_delete=models.CASCADE,null=True,blank=True) duration = models.TimeField(default=datetime.time(1,0)) distance = models.IntegerField(default=0) referencespeed = models.FloatField(default=5.0) @@ -3554,6 +3559,10 @@ class IndoorVirtualRaceResult(models.Model): endsecond = models.FloatField(default=0) def isduplicate(self,other): # pragma: no cover + if self.race is None and other.race is not None: + return False + if self.race is not None and other.race is None: + return False if self.userid != other.userid: return False if self.weightcategory != other.weightcategory: diff --git a/rowers/templates/summary_edit.html b/rowers/templates/summary_edit.html index ee84aaa6..5b9a473a 100644 --- a/rowers/templates/summary_edit.html +++ b/rowers/templates/summary_edit.html @@ -158,7 +158,7 @@

A typical interval is described as "10min/5min", with the work part before the "/" and the rest part after it. A zero rest can be omitted, so a single 1000m piece could be described either as "1km" or "1000m". The basic units can be combined with "+" and "Nx". You can use parentheses as in the example below.

-

Here are a few examples.

+

Here are a few examples

@@ -182,6 +182,23 @@
8x500m/2min8 times 500m with 2 minutes rest
+ {% if courses %} +
  • +

    Interval by Course

    +

    + This functionality allows you to record a time on a set course that you've rowed during the workout. + The summary will be updated to show time on course, and you can compare this with other + attempts. +

    +
    + + {{ courseselectform.as_table }} +
    + {% csrf_token %} + +
    +
  • + {% endif %} {% endblock %} diff --git a/rowers/views/racesviews.py b/rowers/views/racesviews.py index 7d73abca..48a1cc55 100644 --- a/rowers/views/racesviews.py +++ b/rowers/views/racesviews.py @@ -11,72 +11,7 @@ from django.contrib.gis.geoip2 import GeoIP2 from django import forms from rowers.plannedsessions import timefield_to_seconds_duration -# distance of course from lat_lon in km -def howfaris(lat_lon,course): - coords = course.coord - distance = geo_distance(lat_lon[0],lat_lon[1],coords[0],coords[1])[0] - - return distance - -whatisnear = 150 - -# get nearest races -def getnearestraces(lat_lon,races): - newlist = [] - counter = 0 - for race in races: - if race.course is None: # pragma: no cover - newlist.append(race) - else: - c = race.course - coords = c.coord - distance = howfaris(lat_lon,c) - if distance < whatisnear: - newlist.append(race) - counter += 1 - - if counter>0: - races = newlist - else: - courseraces = races.exclude(course__isnull=True) - orders = [(c.id,howfaris(lat_lon,c.course)) for c in courseraces] - orders = sorted(orders,key = lambda tup:tup[1]) - ids = [id for id,distance in orders[0:4]] - for id, distance in orders[5:]: # pragma: no cover - if distance0: - courses = newlist - else: - orders = [(c.id,howfaris(lat_lon,c)) for c in courses] - orders = sorted(orders,key = lambda tup:tup[1]) - ids = [id for id,distance in orders[0:4]] - for id, distance in orders[5:]: - if distance