Private
Public Access
1
0

coverage related changes

This commit is contained in:
Sander Roosendaal
2021-04-26 17:48:22 +02:00
parent 7626554ba9
commit 9e2a97e721
17 changed files with 1534 additions and 144 deletions

View File

@@ -13,15 +13,15 @@ def coordinate_in_path(latitude,longitude, p):
return p.contains_points([(latitude,longitude)])[0]
class InvalidTrajectoryError(Exception):
def __init__(self,value):
def __init__(self,value): # pragma: no cover
self.value=value
def __str__(self):
def __str__(self): # pragma: no cover
return repr(self.value)
def time_in_path(df,p,maxmin='max',getall=False,name='unknown',logfile=None):
if df.empty:
if df.empty: # pragma: no cover
return 0
latitude = df.latitude
@@ -33,12 +33,12 @@ def time_in_path(df,p,maxmin='max',getall=False,name='unknown',logfile=None):
if maxmin=='max':
b = (~df['inpolygon']).shift(-1)+df['inpolygon']
else:
else: # pragma: no cover
b = (~df['inpolygon']).shift(1)+df['inpolygon']
if len(df[b==2]):
if logfile is not None:
if logfile is not None: # pragma: no cover
t = time.localtime()
timestamp = bytes('{t}'.format(t=time.strftime('%b-%d-%Y_%H%M', t)),'utf-8')
with open(logfile,'ab') as f:
@@ -57,12 +57,12 @@ def time_in_path(df,p,maxmin='max',getall=False,name='unknown',logfile=None):
f.write(b' passes found')
else:
f.write(b' pass found')
if getall:
if getall: # pragma: no cover
return df[b==2]['time'],df[b==2]['cum_dist']
else:
return df[b==2]['time'].min(),df[b==2]['cum_dist'].min()
if logfile is not None:
if logfile is not None: # pragma: no cover
t = time.localtime()
timestamp = bytes('{t}'.format(t=time.strftime('%b-%d-%Y_%H%M', t)),'utf-8')
with open(logfile,'ab') as f:
@@ -78,10 +78,10 @@ def time_in_path(df,p,maxmin='max',getall=False,name='unknown',logfile=None):
f.write(bytes(str(len(df[b==2])),'utf-8'))
f.write(b' ')
f.write(b' pass not found')
raise InvalidTrajectoryError("Trajectory doesn't go through path")
raise InvalidTrajectoryError("Trajectory doesn't go through path") # pragma: no cover
return 0
return 0 # pragma: no cover
def coursetime_first(data,paths,polygons=[],logfile=None):
@@ -97,7 +97,7 @@ def coursetime_first(data,paths,polygons=[],logfile=None):
try:
entrytime,entrydistance = time_in_path(data,paths[0],maxmin='max',name=polygons[0][1],logfile=logfile)
coursecompleted = True
except InvalidTrajectoryError:
except InvalidTrajectoryError: # pragma: no cover
entrytime = data['time'].max()
entrydistance = data['cum_dist'].max()
coursecompleted = False
@@ -113,8 +113,8 @@ def coursetime_paths(data,paths,finalmaxmin='min',polygons=[],logfile=None):
polygons = [(0,str(i)) for i in range(len(paths))]
# corner case - empty list of paths
if len(paths) == 0:
return 0,True
if len(paths) == 0: # pragma: no cover
return 0,0,True
# end - just the Finish polygon
if len(paths) == 1:
@@ -124,7 +124,7 @@ def coursetime_paths(data,paths,finalmaxmin='min',polygons=[],logfile=None):
entrydistance
) = time_in_path(data,paths[0],maxmin=finalmaxmin,name = polygons[0][1],logfile=logfile)
coursecompleted = True
except InvalidTrajectoryError:
except InvalidTrajectoryError: # pragma: no cover
entrytime = data['time'].max()
entrydistance = data['cum_dist'].max()
coursecompleted = False
@@ -142,9 +142,9 @@ def coursetime_paths(data,paths,finalmaxmin='min',polygons=[],logfile=None):
coursecompleted
) = coursetime_paths(data,paths[1:],polygons=polygons[1:],logfile=logfile)
return time+timenext, dist+distnext,coursecompleted
except InvalidTrajectoryError:
except InvalidTrajectoryError: # pragma: no cover
entrytime = data['time'].max()
entrydistance = data['cum_dist'].max()
coursecompleted = False
return entrytime, entrydistance, coursecompleted
return entrytime, entrydistance, coursecompleted # pragma: no cover