half way through doing course_adherence
This commit is contained in:
@@ -15,6 +15,8 @@ import xml.etree.ElementTree as et
|
||||
|
||||
import pandas as pd
|
||||
|
||||
import dataprep
|
||||
|
||||
ns = {'opengis': 'http://www.opengis.net/kml/2.2'}
|
||||
|
||||
|
||||
@@ -202,6 +204,11 @@ def createcourse(
|
||||
if i==0 and j==0:
|
||||
loc = geolocator.reverse((point['latitude'],point['longitude']))
|
||||
country = loc.raw['address']['country']
|
||||
if isinstance(country,unicode):
|
||||
country = country.encode('utf8')
|
||||
elif isinstance(country, str):
|
||||
country = country.decode('utf8')
|
||||
|
||||
c.country = country
|
||||
c.save()
|
||||
obj = GeoPoint(
|
||||
@@ -215,3 +222,48 @@ def createcourse(
|
||||
i += 1
|
||||
|
||||
return c
|
||||
|
||||
def coursetime_polygons(data,polygons):
|
||||
|
||||
entrytime = data['time'].max()
|
||||
coursecompleted = False
|
||||
|
||||
# corner case - empty list of polygons
|
||||
if len(polygons) == 0:
|
||||
return 0,True
|
||||
|
||||
# end - just the Finish polygon
|
||||
if len(polygons) == 1:
|
||||
try:
|
||||
entrytime = time_in_polygon(data,polygons[0],maxmin='min')
|
||||
coursecompleted = True
|
||||
except InvalidTrajectoryError:
|
||||
entrytime = data['time'].max()
|
||||
coursecompleted = False
|
||||
return entrytime,coursecompleted
|
||||
|
||||
if len(polygons) > 1:
|
||||
try:
|
||||
time = time_in_polygon(data, polygons[0])
|
||||
|
||||
return entrytime, coursecompleted
|
||||
|
||||
def get_time_course(ws,course):
|
||||
coursetimeseconds = 0.0
|
||||
coursecompleted = 0
|
||||
|
||||
w = ws[0]
|
||||
columns = ['time','latitude','longitude']
|
||||
rowdata = dataprep.getsmallrowdata_db(
|
||||
columns,
|
||||
ids = [w.id],
|
||||
workstrokesonly=False
|
||||
)
|
||||
|
||||
# we may want to expand the time (interpolate)
|
||||
|
||||
polygons = GeoPolygon.object.filter(course=course)
|
||||
|
||||
coursetimeseconds,coursecompleted = coursetime_polygons(rowdata,polygons)
|
||||
|
||||
return coursetimeseconds,coursecompleted
|
||||
|
||||
Reference in New Issue
Block a user