logging of validaitons
This commit is contained in:
@@ -2,7 +2,7 @@ from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import time
|
||||
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ class InvalidTrajectoryError(Exception):
|
||||
def __str__(self):
|
||||
return repr(self.value)
|
||||
|
||||
def time_in_path(df,p,maxmin='max',getall=False):
|
||||
def time_in_path(df,p,maxmin='max',getall=False,name='unknown',logfile=None):
|
||||
|
||||
if df.empty:
|
||||
return 0
|
||||
@@ -43,20 +43,38 @@ def time_in_path(df,p,maxmin='max',getall=False):
|
||||
else:
|
||||
return df[b==2]['time'].min(),df[b==2]['cum_dist'].min()
|
||||
|
||||
if logfile is not None:
|
||||
t = time.localtime()
|
||||
timestamp = time.strftime('%b-%d-%Y_%H%M', t)
|
||||
with open(logfile,'a') as f:
|
||||
f.write('\n')
|
||||
f.write(timestamp)
|
||||
f.write(' ')
|
||||
f.write(name)
|
||||
f.write(' ')
|
||||
f.write(maxmin)
|
||||
f.write(' ')
|
||||
f.write(str(getall))
|
||||
f.write(' ')
|
||||
f.write(str(len(df[b==2])))
|
||||
raise InvalidTrajectoryError("Trajectory doesn't go through path")
|
||||
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
def coursetime_first(data,paths):
|
||||
def coursetime_first(data,paths,polygons=[],logfile=None):
|
||||
|
||||
entrytime = data['time'].max()
|
||||
entrydistance = data['cum_dist'].max()
|
||||
coursecompleted = False
|
||||
|
||||
if len(polygons) == 0:
|
||||
polygons = [(0,str(i)) for i in range(len(paths))]
|
||||
|
||||
|
||||
try:
|
||||
entrytime,entrydistance = time_in_path(data,paths[0],maxmin='max')
|
||||
entrytime,entrydistance = time_in_path(data,paths[0],maxmin='max',name=polygons[0][1],logfile=logfile)
|
||||
coursecompleted = True
|
||||
except InvalidTrajectoryError:
|
||||
entrytime = data['time'].max()
|
||||
@@ -64,12 +82,15 @@ def coursetime_first(data,paths):
|
||||
coursecompleted = False
|
||||
return entrytime, entrydistance, coursecompleted
|
||||
|
||||
def coursetime_paths(data,paths,finalmaxmin='min'):
|
||||
def coursetime_paths(data,paths,finalmaxmin='min',polygons=[],logfile=None):
|
||||
|
||||
entrytime = data['time'].max()
|
||||
entrydistance = data['cum_dist'].max()
|
||||
coursecompleted = False
|
||||
|
||||
if len(polygons) == 0:
|
||||
polygons = [(0,str(i)) for i in range(len(paths))]
|
||||
|
||||
# corner case - empty list of paths
|
||||
if len(paths) == 0:
|
||||
return 0,True
|
||||
@@ -80,7 +101,7 @@ def coursetime_paths(data,paths,finalmaxmin='min'):
|
||||
(
|
||||
entrytime,
|
||||
entrydistance
|
||||
) = time_in_path(data,paths[0],maxmin=finalmaxmin)
|
||||
) = time_in_path(data,paths[0],maxmin=finalmaxmin,name = polygons[0][1],logfile=logfile)
|
||||
coursecompleted = True
|
||||
except InvalidTrajectoryError:
|
||||
entrytime = data['time'].max()
|
||||
@@ -90,7 +111,7 @@ def coursetime_paths(data,paths,finalmaxmin='min'):
|
||||
|
||||
if len(paths) > 1:
|
||||
try:
|
||||
time,dist = time_in_path(data, paths[0])
|
||||
time,dist = time_in_path(data, paths[0],name=polygons[0][1],logfile=logfile)
|
||||
data = data[data['time']>time]
|
||||
data['time'] = data['time']-time
|
||||
data['cum_dist'] = data['cum_dist']-dist
|
||||
@@ -98,7 +119,7 @@ def coursetime_paths(data,paths,finalmaxmin='min'):
|
||||
timenext,
|
||||
distnext,
|
||||
coursecompleted
|
||||
) = coursetime_paths(data,paths[1:])
|
||||
) = coursetime_paths(data,paths[1:],polygons=polygons[1:],logfile=logfile)
|
||||
return time+timenext, dist+distnext,coursecompleted
|
||||
except InvalidTrajectoryError:
|
||||
entrytime = data['time'].max()
|
||||
|
||||
Reference in New Issue
Block a user