course check working but gives wrong result
This commit is contained in:
@@ -14,6 +14,7 @@ from matplotlib import path
|
|||||||
import xml.etree.ElementTree as et
|
import xml.etree.ElementTree as et
|
||||||
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
import dataprep
|
import dataprep
|
||||||
|
|
||||||
@@ -85,12 +86,12 @@ def course_coord_maxmin(course):
|
|||||||
return lat_min,lat_max,long_min,long_max
|
return lat_min,lat_max,long_min,long_max
|
||||||
|
|
||||||
def polygon_to_path(polygon):
|
def polygon_to_path(polygon):
|
||||||
points = GeoPoint.objects.filter(polygon==polygon).order_by("order_in_polygon")
|
points = GeoPoint.objects.filter(polygon=polygon).order_by("order_in_poly")
|
||||||
s = []
|
s = []
|
||||||
for point in points:
|
for point in points:
|
||||||
s.append([point.latitude,point.longitude])
|
s.append([point.latitude,point.longitude])
|
||||||
|
|
||||||
p = path.Path(np.array(s))
|
p = path.Path(s[:-1])
|
||||||
|
|
||||||
return p
|
return p
|
||||||
|
|
||||||
@@ -102,6 +103,10 @@ def coordinate_in_polygon(latitude,longitude, polygon):
|
|||||||
|
|
||||||
|
|
||||||
def time_in_polygon(df,polygon,maxmin='max'):
|
def time_in_polygon(df,polygon,maxmin='max'):
|
||||||
|
|
||||||
|
if df.empty:
|
||||||
|
return 0
|
||||||
|
|
||||||
# df has timestamp, latitude, longitude
|
# df has timestamp, latitude, longitude
|
||||||
p = polygon_to_path(polygon)
|
p = polygon_to_path(polygon)
|
||||||
|
|
||||||
@@ -112,10 +117,13 @@ def time_in_polygon(df,polygon,maxmin='max'):
|
|||||||
|
|
||||||
df['inpolygon'] = df.apply(f,axis=1)
|
df['inpolygon'] = df.apply(f,axis=1)
|
||||||
|
|
||||||
|
|
||||||
mask = df['inpolygon'] == True
|
mask = df['inpolygon'] == True
|
||||||
|
|
||||||
if df[mask].empty():
|
|
||||||
raise InvalidTrajectoryError
|
if df[mask].empty:
|
||||||
|
print polygon.name
|
||||||
|
raise InvalidTrajectoryError("Trajectory doesn't go through {name}".format(name=polygon.name))
|
||||||
|
|
||||||
if maxmin == 'max':
|
if maxmin == 'max':
|
||||||
time = df[mask]['time'].max()
|
time = df[mask]['time'].max()
|
||||||
@@ -237,6 +245,7 @@ def coursetime_polygons(data,polygons):
|
|||||||
try:
|
try:
|
||||||
entrytime = time_in_polygon(data,polygons[0],maxmin='min')
|
entrytime = time_in_polygon(data,polygons[0],maxmin='min')
|
||||||
coursecompleted = True
|
coursecompleted = True
|
||||||
|
print entrytime,polygons[0].name
|
||||||
except InvalidTrajectoryError:
|
except InvalidTrajectoryError:
|
||||||
entrytime = data['time'].max()
|
entrytime = data['time'].max()
|
||||||
coursecompleted = False
|
coursecompleted = False
|
||||||
@@ -245,6 +254,14 @@ def coursetime_polygons(data,polygons):
|
|||||||
if len(polygons) > 1:
|
if len(polygons) > 1:
|
||||||
try:
|
try:
|
||||||
time = time_in_polygon(data, polygons[0])
|
time = time_in_polygon(data, polygons[0])
|
||||||
|
data = data[data['time']>time]
|
||||||
|
data['time'] = data['time']-time
|
||||||
|
print time,polygons[0].name
|
||||||
|
timenext, coursecompleted = coursetime_polygons(data,polygons[1:])
|
||||||
|
return time+timenext, coursecompleted
|
||||||
|
except InvalidTrajectoryError:
|
||||||
|
entrytime = data['time'].max()
|
||||||
|
coursecompleted = False
|
||||||
|
|
||||||
return entrytime, coursecompleted
|
return entrytime, coursecompleted
|
||||||
|
|
||||||
@@ -253,16 +270,27 @@ def get_time_course(ws,course):
|
|||||||
coursecompleted = 0
|
coursecompleted = 0
|
||||||
|
|
||||||
w = ws[0]
|
w = ws[0]
|
||||||
columns = ['time','latitude','longitude']
|
columns = ['time',' latitude',' longitude']
|
||||||
rowdata = dataprep.getsmallrowdata_db(
|
rowdata = dataprep.getsmallrowdata_db(
|
||||||
columns,
|
columns,
|
||||||
ids = [w.id],
|
ids = [w.id],
|
||||||
|
doclean=True,
|
||||||
workstrokesonly=False
|
workstrokesonly=False
|
||||||
)
|
)
|
||||||
|
rowdata.rename(columns = {
|
||||||
|
' latitude':'latitude',
|
||||||
|
' longitude':'longitude',
|
||||||
|
}, inplace=True)
|
||||||
|
|
||||||
|
|
||||||
|
rowdata['time'] = rowdata['time']/1000.
|
||||||
|
|
||||||
|
rowdata.fillna(method='backfill',inplace=True)
|
||||||
|
|
||||||
|
rowdata['time'] = rowdata['time']-rowdata.ix[0,'time']
|
||||||
# we may want to expand the time (interpolate)
|
# we may want to expand the time (interpolate)
|
||||||
|
|
||||||
polygons = GeoPolygon.object.filter(course=course)
|
polygons = GeoPolygon.objects.filter(course=course)
|
||||||
|
|
||||||
coursetimeseconds,coursecompleted = coursetime_polygons(rowdata,polygons)
|
coursetimeseconds,coursecompleted = coursetime_polygons(rowdata,polygons)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user