v0.1 of testcourse working (plannedsession)
This commit is contained in:
@@ -120,7 +120,7 @@ def time_in_path(df,p,maxmin='max'):
|
||||
b = (~df['inpolygon']).shift(1)+df['inpolygon']
|
||||
|
||||
if len(df[b==2]):
|
||||
return df[b==2]['time'].min()
|
||||
return df[b==2]['time'].min(),df[b==2]['cum_dist'].min()
|
||||
|
||||
raise InvalidTrajectoryError("Trajectory doesn't go through path")
|
||||
|
||||
@@ -230,19 +230,22 @@ def createcourse(
|
||||
def coursetime_first(data,paths):
|
||||
|
||||
entrytime = data['time'].max()
|
||||
entrydistance = data['cum_dist'].max()
|
||||
coursecompleted = False
|
||||
|
||||
try:
|
||||
entrytime = time_in_path(data,paths[0],maxmin='max')
|
||||
entrytime,entrydistance = time_in_path(data,paths[0],maxmin='max')
|
||||
coursecompleted = True
|
||||
except InvalidTrajectoryError:
|
||||
entrytime = data['time'].max()
|
||||
entrydistance = data['cum_dist'].max()
|
||||
coursecompleted = False
|
||||
return entrytime, coursecompleted
|
||||
return entrytime, entrydistance, coursecompleted
|
||||
|
||||
def coursetime_paths(data,paths,finalmaxmin='min'):
|
||||
|
||||
entrytime = data['time'].max()
|
||||
entrydistance = data['cum_dist'].max()
|
||||
coursecompleted = False
|
||||
|
||||
# corner case - empty list of paths
|
||||
@@ -252,32 +255,42 @@ def coursetime_paths(data,paths,finalmaxmin='min'):
|
||||
# end - just the Finish polygon
|
||||
if len(paths) == 1:
|
||||
try:
|
||||
entrytime = time_in_path(data,paths[0],maxmin=finalmaxmin)
|
||||
(
|
||||
entrytime,
|
||||
entrydistance
|
||||
) = time_in_path(data,paths[0],maxmin=finalmaxmin)
|
||||
coursecompleted = True
|
||||
except InvalidTrajectoryError:
|
||||
entrytime = data['time'].max()
|
||||
entrydistance = data['cum_dist'].max()
|
||||
coursecompleted = False
|
||||
return entrytime,coursecompleted
|
||||
return entrytime,entrydistance,coursecompleted
|
||||
|
||||
if len(paths) > 1:
|
||||
try:
|
||||
time = time_in_path(data, paths[0])
|
||||
time,dist = time_in_path(data, paths[0])
|
||||
data = data[data['time']>time]
|
||||
data['time'] = data['time']-time
|
||||
timenext, coursecompleted = coursetime_paths(data,paths[1:])
|
||||
return time+timenext, coursecompleted
|
||||
data['cum_dist'] = data['cum_dist']-dist
|
||||
(
|
||||
timenext,
|
||||
distnext,
|
||||
coursecompleted
|
||||
) = coursetime_paths(data,paths[1:])
|
||||
return time+timenext, dist+distnext,coursecompleted
|
||||
except InvalidTrajectoryError:
|
||||
entrytime = data['time'].max()
|
||||
entrydistance = data['cum_dist'].max()
|
||||
coursecompleted = False
|
||||
|
||||
return entrytime, coursecompleted
|
||||
return entrytime, entrydistance, coursecompleted
|
||||
|
||||
def get_time_course(ws,course):
|
||||
coursetimeseconds = 0.0
|
||||
coursecompleted = 0
|
||||
|
||||
w = ws[0]
|
||||
columns = ['time',' latitude',' longitude']
|
||||
columns = ['time',' latitude',' longitude','cum_dist']
|
||||
rowdata = dataprep.getsmallrowdata_db(
|
||||
columns,
|
||||
ids = [w.id],
|
||||
@@ -303,10 +316,20 @@ def get_time_course(ws,course):
|
||||
path = polygon_to_path(polygon)
|
||||
paths.append(path)
|
||||
|
||||
coursetimeseconds,coursecompleted = coursetime_paths(rowdata,paths)
|
||||
coursetimefirst,firstcompleted = coursetime_first(
|
||||
(
|
||||
coursetimeseconds,
|
||||
coursemeters,
|
||||
coursecompleted,
|
||||
|
||||
) = coursetime_paths(rowdata,paths)
|
||||
(
|
||||
coursetimefirst,
|
||||
coursemetersfirst,
|
||||
firstcompleted
|
||||
) = coursetime_first(
|
||||
rowdata,paths)
|
||||
|
||||
coursetimeseconds = coursetimeseconds-coursetimefirst
|
||||
coursemeters = coursemeters-coursemetersfirst
|
||||
|
||||
return coursetimeseconds,coursecompleted
|
||||
return coursetimeseconds,coursemeters,coursecompleted
|
||||
|
||||
Reference in New Issue
Block a user