Merge branch 'feature/betterdistance' into develop
This commit is contained in:
+6
-15
@@ -28,9 +28,12 @@ from rowers.models import (
|
|||||||
Rower, Workout,
|
Rower, Workout,
|
||||||
GeoPoint,GeoPolygon, GeoCourse,
|
GeoPoint,GeoPolygon, GeoCourse,
|
||||||
course_length,course_coord_center,course_coord_maxmin,
|
course_length,course_coord_center,course_coord_maxmin,
|
||||||
polygon_coord_center,PlannedSession
|
polygon_coord_center,PlannedSession,
|
||||||
|
polygon_to_path,coordinate_in_path
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from utils import geo_distance
|
||||||
|
|
||||||
# low level methods
|
# low level methods
|
||||||
class InvalidTrajectoryError(Exception):
|
class InvalidTrajectoryError(Exception):
|
||||||
def __init__(self,value):
|
def __init__(self,value):
|
||||||
@@ -39,6 +42,7 @@ class InvalidTrajectoryError(Exception):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return repr(self.value)
|
return repr(self.value)
|
||||||
|
|
||||||
|
|
||||||
def get_course_timezone(course):
|
def get_course_timezone(course):
|
||||||
polygons = GeoPolygon.objects.filter(course = course)
|
polygons = GeoPolygon.objects.filter(course = course)
|
||||||
points = GeoPoint.objects.filter(polygon = polygons[0])
|
points = GeoPoint.objects.filter(polygon = polygons[0])
|
||||||
@@ -58,19 +62,6 @@ def get_course_timezone(course):
|
|||||||
|
|
||||||
return timezone_str
|
return timezone_str
|
||||||
|
|
||||||
def polygon_to_path(polygon):
|
|
||||||
points = GeoPoint.objects.filter(polygon=polygon).order_by("order_in_poly")
|
|
||||||
s = []
|
|
||||||
for point in points:
|
|
||||||
s.append([point.latitude,point.longitude])
|
|
||||||
|
|
||||||
p = path.Path(s[:-1])
|
|
||||||
|
|
||||||
return p
|
|
||||||
|
|
||||||
def coordinate_in_path(latitude,longitude, p):
|
|
||||||
|
|
||||||
return p.contains_points([(latitude,longitude)])[0]
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -293,7 +284,7 @@ def get_time_course(ws,course):
|
|||||||
rowdata = rowdata.resample('100ms',on='dt').mean()
|
rowdata = rowdata.resample('100ms',on='dt').mean()
|
||||||
rowdata = rowdata.interpolate()
|
rowdata = rowdata.interpolate()
|
||||||
|
|
||||||
polygons = GeoPolygon.objects.filter(course=course)
|
polygons = GeoPolygon.objects.filter(course=course).order_by("order_in_course")
|
||||||
paths = []
|
paths = []
|
||||||
for polygon in polygons:
|
for polygon in polygons:
|
||||||
path = polygon_to_path(polygon)
|
path = polygon_to_path(polygon)
|
||||||
|
|||||||
+91
-4
@@ -32,7 +32,7 @@ from collections import OrderedDict
|
|||||||
from timezonefinder import TimezoneFinder
|
from timezonefinder import TimezoneFinder
|
||||||
|
|
||||||
import types
|
import types
|
||||||
|
from matplotlib import path
|
||||||
|
|
||||||
from rowsandall_app.settings import (
|
from rowsandall_app.settings import (
|
||||||
TWEET_ACCESS_TOKEN_KEY,
|
TWEET_ACCESS_TOKEN_KEY,
|
||||||
@@ -363,6 +363,19 @@ def polygon_coord_center(polygon):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def polygon_to_path(polygon):
|
||||||
|
points = GeoPoint.objects.filter(polygon=polygon).order_by("order_in_poly")
|
||||||
|
s = []
|
||||||
|
for point in points:
|
||||||
|
s.append([point.latitude,point.longitude])
|
||||||
|
|
||||||
|
p = path.Path(s[:-1])
|
||||||
|
|
||||||
|
return p
|
||||||
|
|
||||||
|
def coordinate_in_path(latitude,longitude, p):
|
||||||
|
|
||||||
|
return p.contains_points([(latitude,longitude)])[0]
|
||||||
|
|
||||||
|
|
||||||
def course_coord_center(course):
|
def course_coord_center(course):
|
||||||
@@ -407,6 +420,62 @@ def course_coord_maxmin(course):
|
|||||||
|
|
||||||
return lat_min,lat_max,long_min,long_max
|
return lat_min,lat_max,long_min,long_max
|
||||||
|
|
||||||
|
def get_dir_vector(polygon1,polygon2):
|
||||||
|
lat1,lon1 = polygon_coord_center(polygon1)
|
||||||
|
lat2,lon2 = polygon_coord_center(polygon2)
|
||||||
|
|
||||||
|
return [lat2-lat1,lon2-lon1]
|
||||||
|
|
||||||
|
def get_delta(vector,polygon):
|
||||||
|
x = pd.Series(range(10000))/9999.
|
||||||
|
vlat = vector[0]
|
||||||
|
vlon = vector[1]
|
||||||
|
|
||||||
|
lat1,lon1 = polygon_coord_center(polygon)
|
||||||
|
|
||||||
|
lat = x.apply(lambda x:lat1+x*vlat)
|
||||||
|
lon = x.apply(lambda x:lon1+x*vlon)
|
||||||
|
|
||||||
|
totdist,bearing = geo_distance(lat1,lon1,lat1+vlat,lon1+vlon)
|
||||||
|
|
||||||
|
dist = x*totdist
|
||||||
|
|
||||||
|
p = polygon_to_path(polygon)
|
||||||
|
|
||||||
|
f = lambda x: coordinate_in_path(x['lat'],x['lon'],p)
|
||||||
|
|
||||||
|
df = pd.DataFrame({'x':x,
|
||||||
|
'lat':lat,
|
||||||
|
'lon':lon,
|
||||||
|
'dist':dist,
|
||||||
|
})
|
||||||
|
|
||||||
|
df['inpolygon'] = df.apply(f,axis=1)
|
||||||
|
|
||||||
|
|
||||||
|
b = (~df['inpolygon']).shift(-1)+df['inpolygon']
|
||||||
|
|
||||||
|
|
||||||
|
if len(df[b==2]):
|
||||||
|
return 1.0e3*df[b==2]['dist'].min()
|
||||||
|
|
||||||
|
else:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
def get_delta_start(course):
|
||||||
|
polygons = GeoPolygon.objects.filter(course=course).order_by("order_in_course")
|
||||||
|
vector = get_dir_vector(polygons[0],polygons[1])
|
||||||
|
delta = get_delta(vector,polygons[0])
|
||||||
|
|
||||||
|
return delta
|
||||||
|
|
||||||
|
def get_delta_finish(course):
|
||||||
|
polygons = GeoPolygon.objects.filter(course=course).order_by("-order_in_course")
|
||||||
|
vector = get_dir_vector(polygons[0],polygons[1])
|
||||||
|
delta = get_delta(vector,polygons[0])
|
||||||
|
|
||||||
|
return delta
|
||||||
|
|
||||||
def course_length(course):
|
def course_length(course):
|
||||||
polygons = GeoPolygon.objects.filter(course=course).order_by("order_in_course")
|
polygons = GeoPolygon.objects.filter(course=course).order_by("order_in_course")
|
||||||
@@ -421,7 +490,14 @@ def course_length(course):
|
|||||||
|
|
||||||
totaldist += 1000.*dist[0]
|
totaldist += 1000.*dist[0]
|
||||||
|
|
||||||
return int(totaldist)
|
vector = get_dir_vector(polygons[0],polygons[1])
|
||||||
|
deltastart = get_delta(vector,polygons[0])
|
||||||
|
|
||||||
|
polygons = polygons.reverse()
|
||||||
|
vector = get_dir_vector(polygons[0],polygons[1])
|
||||||
|
deltafinish = get_delta(vector,polygons[0])
|
||||||
|
|
||||||
|
return int(totaldist-deltastart-deltafinish)
|
||||||
|
|
||||||
sexcategories = (
|
sexcategories = (
|
||||||
('male','male'),
|
('male','male'),
|
||||||
@@ -766,9 +842,10 @@ class GeoCourse(models.Model):
|
|||||||
name = self.name
|
name = self.name
|
||||||
country = self.country
|
country = self.country
|
||||||
|
|
||||||
return u'{country} - {name}'.format(
|
return u'{country} - {name} - {d}m'.format(
|
||||||
name=name,
|
name=name,
|
||||||
country=country
|
country=country,
|
||||||
|
d = course_length(self)
|
||||||
)
|
)
|
||||||
|
|
||||||
class GeoCourseEditForm(ModelForm):
|
class GeoCourseEditForm(ModelForm):
|
||||||
@@ -785,6 +862,16 @@ class GeoPolygon(models.Model):
|
|||||||
course = models.ForeignKey(GeoCourse, blank=True)
|
course = models.ForeignKey(GeoCourse, blank=True)
|
||||||
order_in_course = models.IntegerField(default=0)
|
order_in_course = models.IntegerField(default=0)
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
name = self.name
|
||||||
|
coursename = self.course.name
|
||||||
|
|
||||||
|
return u'{coursename} - {name}'.format(
|
||||||
|
name=name,
|
||||||
|
course=coursename
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# Need error checking to insert new polygons into existing course (all later polygons
|
# Need error checking to insert new polygons into existing course (all later polygons
|
||||||
# increase there order_in_course number
|
# increase there order_in_course number
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
{% load staticfiles %}
|
{% load staticfiles %}
|
||||||
{% load rowerfilters %}
|
{% load rowerfilters %}
|
||||||
|
|
||||||
{% block title %}New Virtual Race{% endblock %}
|
{% block title %}Rowsandall Virtual Race{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user