courses defined by spline and other improvements
This commit is contained in:
@@ -43,6 +43,8 @@ from courses import (
|
|||||||
polygon_coord_center
|
polygon_coord_center
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from rowers.models import course_spline
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import math
|
import math
|
||||||
import numpy as np
|
import numpy as np
|
||||||
@@ -853,6 +855,8 @@ def course_map(course):
|
|||||||
latmean,lonmean,coordinates = course_coord_center(course)
|
latmean,lonmean,coordinates = course_coord_center(course)
|
||||||
lat_min, lat_max, long_min, long_max = course_coord_maxmin(course)
|
lat_min, lat_max, long_min, long_max = course_coord_maxmin(course)
|
||||||
|
|
||||||
|
coordinates = course_spline(coordinates)
|
||||||
|
|
||||||
scoordinates = "["
|
scoordinates = "["
|
||||||
|
|
||||||
for index,row in coordinates.iterrows():
|
for index,row in coordinates.iterrows():
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ import twitter
|
|||||||
import re
|
import re
|
||||||
import pytz
|
import pytz
|
||||||
|
|
||||||
|
from scipy.interpolate import splprep, splev, CubicSpline
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
@@ -377,6 +380,32 @@ def coordinate_in_path(latitude,longitude, p):
|
|||||||
|
|
||||||
return p.contains_points([(latitude,longitude)])[0]
|
return p.contains_points([(latitude,longitude)])[0]
|
||||||
|
|
||||||
|
def course_spline(coordinates):
|
||||||
|
latitudes = coordinates['latitude'].values
|
||||||
|
longitudes = coordinates['longitude'].values
|
||||||
|
|
||||||
|
# spline parameters
|
||||||
|
s = 1.0
|
||||||
|
k = min([5,len(latitudes)-1])
|
||||||
|
nest = -1
|
||||||
|
|
||||||
|
t = np.linspace(0,1,len(latitudes))
|
||||||
|
tnew = np.linspace(0,1,100)
|
||||||
|
|
||||||
|
latnew = CubicSpline(t,latitudes,bc_type='clamped')(tnew)
|
||||||
|
lonnew = CubicSpline(t,longitudes,bc_type='clamped')(tnew)
|
||||||
|
# latnew = CubicSpline(t,latitudes,bc_type='natural')(tnew)
|
||||||
|
# lonnew = CubicSpline(t,longitudes,bc_type='natural')(tnew)
|
||||||
|
|
||||||
|
# tckp,u = splprep([t,latitudes,longitudes],s=s,k=k,nest=nest)
|
||||||
|
# tnew,latnew,lonnew = splev(np.linspace(0,1,100),tckp)
|
||||||
|
|
||||||
|
newcoordinates = pd.DataFrame({
|
||||||
|
'latitude':latnew,
|
||||||
|
'longitude':lonnew,
|
||||||
|
})
|
||||||
|
|
||||||
|
return newcoordinates
|
||||||
|
|
||||||
def course_coord_center(course):
|
def course_coord_center(course):
|
||||||
|
|
||||||
@@ -393,11 +422,13 @@ def course_coord_center(course):
|
|||||||
latitude = pd.Series(latitudes).median()
|
latitude = pd.Series(latitudes).median()
|
||||||
longitude = pd.Series(longitudes).median()
|
longitude = pd.Series(longitudes).median()
|
||||||
|
|
||||||
|
|
||||||
coordinates = pd.DataFrame({
|
coordinates = pd.DataFrame({
|
||||||
'latitude':latitudes,
|
'latitude':latitudes,
|
||||||
'longitude':longitudes,
|
'longitude':longitudes,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
return latitude,longitude,coordinates
|
return latitude,longitude,coordinates
|
||||||
|
|
||||||
def course_coord_maxmin(course):
|
def course_coord_maxmin(course):
|
||||||
@@ -868,7 +899,7 @@ class GeoPolygon(models.Model):
|
|||||||
|
|
||||||
return u'{coursename} - {name}'.format(
|
return u'{coursename} - {name}'.format(
|
||||||
name=name,
|
name=name,
|
||||||
course=coursename
|
coursename=coursename
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -1157,9 +1188,12 @@ registerchoices = (
|
|||||||
|
|
||||||
class VirtualRace(PlannedSession):
|
class VirtualRace(PlannedSession):
|
||||||
# has_registration = models.BooleanField(default=False)
|
# has_registration = models.BooleanField(default=False)
|
||||||
registration_form = models.CharField(max_length=100,
|
registration_form = models.CharField(
|
||||||
default='windowstart',
|
max_length=100,
|
||||||
choices=registerchoices)
|
default='windowstart',
|
||||||
|
choices=registerchoices,
|
||||||
|
verbose_name='Registration Closure Quick Selector'
|
||||||
|
)
|
||||||
registration_closure = models.DateTimeField(blank=True,null=True)
|
registration_closure = models.DateTimeField(blank=True,null=True)
|
||||||
evaluation_closure = models.DateTimeField(blank=True,null=True)
|
evaluation_closure = models.DateTimeField(blank=True,null=True)
|
||||||
start_time = models.TimeField(blank=True,null=True)
|
start_time = models.TimeField(blank=True,null=True)
|
||||||
@@ -1348,6 +1382,12 @@ class VirtualRaceForm(ModelForm):
|
|||||||
if startdatetime > enddatetime:
|
if startdatetime > enddatetime:
|
||||||
raise forms.ValidationError("The Start of the Race Window should be before the End of the Race Window")
|
raise forms.ValidationError("The Start of the Race Window should be before the End of the Race Window")
|
||||||
|
|
||||||
|
try:
|
||||||
|
evaluation_closure = cd['evaluation_closure']
|
||||||
|
except KeyError:
|
||||||
|
evaluation_closure = enddatetime+datetime.timedelta(days=1)
|
||||||
|
cd['evaluation_closure'] = evaluation_closure
|
||||||
|
|
||||||
if cd['evaluation_closure'] <= enddatetime:
|
if cd['evaluation_closure'] <= enddatetime:
|
||||||
raise forms.ValidationError("Evaluation closure deadline should be after the Race Window closes")
|
raise forms.ValidationError("Evaluation closure deadline should be after the Race Window closes")
|
||||||
|
|
||||||
@@ -1355,7 +1395,7 @@ class VirtualRaceForm(ModelForm):
|
|||||||
raise forms.ValidationError("Evaluation closure cannot be in the past")
|
raise forms.ValidationError("Evaluation closure cannot be in the past")
|
||||||
|
|
||||||
|
|
||||||
return cleaned_data
|
return cd
|
||||||
|
|
||||||
class PlannedSessionFormSmall(ModelForm):
|
class PlannedSessionFormSmall(ModelForm):
|
||||||
|
|
||||||
|
|||||||
@@ -253,8 +253,9 @@ def isbreakthrough(delta,cpvalues,p0,p1,p2,p3,ratio):
|
|||||||
pwr *= ratio
|
pwr *= ratio
|
||||||
|
|
||||||
|
|
||||||
delta = delta.values
|
delta = delta.values.astype(int)
|
||||||
cpvalues = cpvalues.values
|
cpvalues = cpvalues.values.astype(int)
|
||||||
|
pwr = pwr.astype(int)
|
||||||
|
|
||||||
res = np.sum(cpvalues>pwr)
|
res = np.sum(cpvalues>pwr)
|
||||||
res2 = np.sum(cpvalues>pwr2)
|
res2 = np.sum(cpvalues>pwr2)
|
||||||
|
|||||||
Reference in New Issue
Block a user