some UI improvements on planned sessions
This commit is contained in:
@@ -350,6 +350,79 @@ from utils import (
|
||||
defaultleft,defaultmiddle,landingpages
|
||||
)
|
||||
|
||||
from utils import geo_distance
|
||||
|
||||
def polygon_coord_center(polygon):
|
||||
|
||||
points = GeoPoint.objects.filter(polygon=polygon).order_by("order_in_poly")
|
||||
|
||||
latitudes = pd.Series([p.latitude for p in points])
|
||||
longitudes = pd.Series([p.longitude for p in points])
|
||||
|
||||
return latitudes.mean(), longitudes.mean()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def course_coord_center(course):
|
||||
|
||||
polygons = GeoPolygon.objects.filter(course=course).order_by("order_in_course")
|
||||
|
||||
latitudes = []
|
||||
longitudes = []
|
||||
|
||||
for p in polygons:
|
||||
latitude,longitude = polygon_coord_center(p)
|
||||
latitudes.append(latitude)
|
||||
longitudes.append(longitude)
|
||||
|
||||
latitude = pd.Series(latitudes).median()
|
||||
longitude = pd.Series(longitudes).median()
|
||||
|
||||
coordinates = pd.DataFrame({
|
||||
'latitude':latitudes,
|
||||
'longitude':longitudes,
|
||||
})
|
||||
|
||||
return latitude,longitude,coordinates
|
||||
|
||||
def course_coord_maxmin(course):
|
||||
|
||||
polygons = GeoPolygon.objects.filter(course=course).order_by("order_in_course")
|
||||
|
||||
latitudes = []
|
||||
longitudes = []
|
||||
|
||||
for p in polygons:
|
||||
latitude,longitude = polygon_coord_center(p)
|
||||
latitudes.append(latitude)
|
||||
longitudes.append(longitude)
|
||||
|
||||
lat_min = pd.Series(latitudes).min()
|
||||
lat_max = pd.Series(latitudes).max()
|
||||
long_min = pd.Series(longitudes).min()
|
||||
long_max = pd.Series(longitudes).max()
|
||||
|
||||
|
||||
return lat_min,lat_max,long_min,long_max
|
||||
|
||||
|
||||
def course_length(course):
|
||||
polygons = GeoPolygon.objects.filter(course=course).order_by("order_in_course")
|
||||
|
||||
totaldist = 0
|
||||
for i in range(len(polygons)-1):
|
||||
latitude1,longitude1 = polygon_coord_center(polygons[i])
|
||||
latitude2,longitude2 = polygon_coord_center(polygons[i+1])
|
||||
|
||||
dist = geo_distance(latitude1,longitude1,
|
||||
latitude2,longitude2,)
|
||||
|
||||
totaldist += 1000.*dist[0]
|
||||
|
||||
return int(totaldist)
|
||||
|
||||
# Extension of User with rowing specific data
|
||||
class Rower(models.Model):
|
||||
weightcategories = (
|
||||
@@ -677,7 +750,7 @@ class GeoCourse(models.Model):
|
||||
class GeoCourseEditForm(ModelForm):
|
||||
class Meta:
|
||||
model = GeoCourse
|
||||
fields = ['name','notes']
|
||||
fields = ['name','country','notes']
|
||||
|
||||
widgets = {
|
||||
'notes': forms.Textarea,
|
||||
@@ -941,6 +1014,11 @@ class PlannedSession(models.Model):
|
||||
self.sessionmode = 'distance'
|
||||
self.sessionunit = 'm'
|
||||
self.criterium = 'none'
|
||||
if self.course == None:
|
||||
self.course = GeoCourse.objects.all()[0]
|
||||
self.sessionvalue = course_length(self.course)
|
||||
elif self.sessiontype != 'coursetest':
|
||||
self.course = None
|
||||
|
||||
super(PlannedSession,self).save(*args, **kwargs)
|
||||
|
||||
@@ -977,8 +1055,7 @@ class PlannedSessionForm(ModelForm):
|
||||
|
||||
def __init__(self,*args,**kwargs):
|
||||
super(PlannedSessionForm, self).__init__(*args, **kwargs)
|
||||
if self.instance.sessiontype != 'coursetest':
|
||||
del self.fields['course']
|
||||
self.fields['course'].queryset = GeoCourse.objects.all().order_by("country","name")
|
||||
|
||||
class PlannedSessionFormSmall(ModelForm):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user