courses defined by spline and other improvements
This commit is contained in:
@@ -43,6 +43,8 @@ from courses import (
|
||||
polygon_coord_center
|
||||
)
|
||||
|
||||
from rowers.models import course_spline
|
||||
|
||||
import datetime
|
||||
import math
|
||||
import numpy as np
|
||||
@@ -853,6 +855,8 @@ def course_map(course):
|
||||
latmean,lonmean,coordinates = course_coord_center(course)
|
||||
lat_min, lat_max, long_min, long_max = course_coord_maxmin(course)
|
||||
|
||||
coordinates = course_spline(coordinates)
|
||||
|
||||
scoordinates = "["
|
||||
|
||||
for index,row in coordinates.iterrows():
|
||||
|
||||
@@ -18,6 +18,9 @@ import twitter
|
||||
import re
|
||||
import pytz
|
||||
|
||||
from scipy.interpolate import splprep, splev, CubicSpline
|
||||
import numpy as np
|
||||
|
||||
from django.conf import settings
|
||||
from sqlalchemy import create_engine
|
||||
import sqlalchemy as sa
|
||||
@@ -376,7 +379,33 @@ def polygon_to_path(polygon):
|
||||
def coordinate_in_path(latitude,longitude, p):
|
||||
|
||||
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):
|
||||
|
||||
@@ -393,10 +422,12 @@ def course_coord_center(course):
|
||||
latitude = pd.Series(latitudes).median()
|
||||
longitude = pd.Series(longitudes).median()
|
||||
|
||||
|
||||
coordinates = pd.DataFrame({
|
||||
'latitude':latitudes,
|
||||
'longitude':longitudes,
|
||||
})
|
||||
|
||||
|
||||
return latitude,longitude,coordinates
|
||||
|
||||
@@ -868,7 +899,7 @@ class GeoPolygon(models.Model):
|
||||
|
||||
return u'{coursename} - {name}'.format(
|
||||
name=name,
|
||||
course=coursename
|
||||
coursename=coursename
|
||||
)
|
||||
|
||||
|
||||
@@ -1157,9 +1188,12 @@ registerchoices = (
|
||||
|
||||
class VirtualRace(PlannedSession):
|
||||
# has_registration = models.BooleanField(default=False)
|
||||
registration_form = models.CharField(max_length=100,
|
||||
default='windowstart',
|
||||
choices=registerchoices)
|
||||
registration_form = models.CharField(
|
||||
max_length=100,
|
||||
default='windowstart',
|
||||
choices=registerchoices,
|
||||
verbose_name='Registration Closure Quick Selector'
|
||||
)
|
||||
registration_closure = models.DateTimeField(blank=True,null=True)
|
||||
evaluation_closure = models.DateTimeField(blank=True,null=True)
|
||||
start_time = models.TimeField(blank=True,null=True)
|
||||
@@ -1348,6 +1382,12 @@ class VirtualRaceForm(ModelForm):
|
||||
if startdatetime > enddatetime:
|
||||
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:
|
||||
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")
|
||||
|
||||
|
||||
return cleaned_data
|
||||
return cd
|
||||
|
||||
class PlannedSessionFormSmall(ModelForm):
|
||||
|
||||
|
||||
@@ -253,8 +253,9 @@ def isbreakthrough(delta,cpvalues,p0,p1,p2,p3,ratio):
|
||||
pwr *= ratio
|
||||
|
||||
|
||||
delta = delta.values
|
||||
cpvalues = cpvalues.values
|
||||
delta = delta.values.astype(int)
|
||||
cpvalues = cpvalues.values.astype(int)
|
||||
pwr = pwr.astype(int)
|
||||
|
||||
res = np.sum(cpvalues>pwr)
|
||||
res2 = np.sum(cpvalues>pwr2)
|
||||
|
||||
Reference in New Issue
Block a user