Private
Public Access
1
0

logging of validaitons

This commit is contained in:
Sander Roosendaal
2020-06-20 11:05:02 +02:00
parent f89ddd57b8
commit 49a2a55206
3 changed files with 66 additions and 16 deletions

View File

@@ -2,7 +2,7 @@ from __future__ import absolute_import
from __future__ import division from __future__ import division
from __future__ import print_function from __future__ import print_function
from __future__ import unicode_literals from __future__ import unicode_literals
import time
@@ -19,7 +19,7 @@ class InvalidTrajectoryError(Exception):
def __str__(self): def __str__(self):
return repr(self.value) 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: if df.empty:
return 0 return 0
@@ -43,20 +43,38 @@ def time_in_path(df,p,maxmin='max',getall=False):
else: else:
return df[b==2]['time'].min(),df[b==2]['cum_dist'].min() 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") raise InvalidTrajectoryError("Trajectory doesn't go through path")
return 0 return 0
def coursetime_first(data,paths): def coursetime_first(data,paths,polygons=[],logfile=None):
entrytime = data['time'].max() entrytime = data['time'].max()
entrydistance = data['cum_dist'].max() entrydistance = data['cum_dist'].max()
coursecompleted = False coursecompleted = False
if len(polygons) == 0:
polygons = [(0,str(i)) for i in range(len(paths))]
try: 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 coursecompleted = True
except InvalidTrajectoryError: except InvalidTrajectoryError:
entrytime = data['time'].max() entrytime = data['time'].max()
@@ -64,12 +82,15 @@ def coursetime_first(data,paths):
coursecompleted = False coursecompleted = False
return entrytime, entrydistance, coursecompleted 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() entrytime = data['time'].max()
entrydistance = data['cum_dist'].max() entrydistance = data['cum_dist'].max()
coursecompleted = False coursecompleted = False
if len(polygons) == 0:
polygons = [(0,str(i)) for i in range(len(paths))]
# corner case - empty list of paths # corner case - empty list of paths
if len(paths) == 0: if len(paths) == 0:
return 0,True return 0,True
@@ -80,7 +101,7 @@ def coursetime_paths(data,paths,finalmaxmin='min'):
( (
entrytime, entrytime,
entrydistance 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 coursecompleted = True
except InvalidTrajectoryError: except InvalidTrajectoryError:
entrytime = data['time'].max() entrytime = data['time'].max()
@@ -90,7 +111,7 @@ def coursetime_paths(data,paths,finalmaxmin='min'):
if len(paths) > 1: if len(paths) > 1:
try: 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 = data[data['time']>time]
data['time'] = data['time']-time data['time'] = data['time']-time
data['cum_dist'] = data['cum_dist']-dist data['cum_dist'] = data['cum_dist']-dist
@@ -98,7 +119,7 @@ def coursetime_paths(data,paths,finalmaxmin='min'):
timenext, timenext,
distnext, distnext,
coursecompleted coursecompleted
) = coursetime_paths(data,paths[1:]) ) = coursetime_paths(data,paths[1:],polygons=polygons[1:],logfile=logfile)
return time+timenext, dist+distnext,coursecompleted return time+timenext, dist+distnext,coursecompleted
except InvalidTrajectoryError: except InvalidTrajectoryError:
entrytime = data['time'].max() entrytime = data['time'].max()

View File

@@ -349,6 +349,8 @@ def handle_check_race_course(self,
recordid,useremail,userfirstname, recordid,useremail,userfirstname,
**kwargs): **kwargs):
logfile = 'courselog_{workoutid}_{courseid}.log'.format(workoutid=workoutid,courseid=courseid)
if 'debug' in kwargs: if 'debug' in kwargs:
debug = kwargs['debug'] debug = kwargs['debug']
else: else:
@@ -420,10 +422,11 @@ def handle_check_race_course(self,
engine = create_engine(database_url, echo=False) engine = create_engine(database_url, echo=False)
# get polygons # get polygons
query = "SELECT id FROM rowers_geopolygon WHERE course_id = {courseid} ORDER BY order_in_course ASC".format( query = "SELECT id,name FROM rowers_geopolygon WHERE course_id = {courseid} ORDER BY order_in_course ASC".format(
courseid=courseid courseid=courseid
) )
with engine.connect() as conn, conn.begin(): with engine.connect() as conn, conn.begin():
result = conn.execute(query) result = conn.execute(query)
polygons = result.fetchall() polygons = result.fetchall()
@@ -441,7 +444,16 @@ def handle_check_race_course(self,
# check how many times went through start polygon # check how many times went through start polygon
try: try:
entrytimes,entrydistances = time_in_path(rowdata,paths[0],maxmin='max',getall=True) entrytimes,entrydistances = time_in_path(rowdata,paths[0],maxmin='max',getall=True,
name=polygons[0].name,logfile=logfile)
with open(logfile,'a') as f:
t = time.localtime()
timestamp = time.strftime('%b-%d-%Y_%H%M', t)
f.write('\n')
f.write(timestamp)
f.write(' ')
f.write('Found {n} entrytimes'.format(n=len(entrytimes)))
except InvalidTrajectoryError: except InvalidTrajectoryError:
entrytimes = [] entrytimes = []
entrydistances = [] entrydistances = []
@@ -457,7 +469,13 @@ def handle_check_race_course(self,
endseconds = [] endseconds = []
for startt in entrytimes: for startt in entrytimes:
with open(logfile,'a') as f:
t = time.localtime()
timestamp = time.strftime('%b-%d-%Y_%H%M', t)
f.write('\n')
f.write(timestamp)
f.write(' ')
f.write('Path starting at {t}'.format(t=startt))
rowdata2 = rowdata[rowdata['time']>(startt-10.)] rowdata2 = rowdata[rowdata['time']>(startt-10.)]
( (
@@ -465,13 +483,13 @@ def handle_check_race_course(self,
coursemeters, coursemeters,
coursecompleted, coursecompleted,
) = coursetime_paths(rowdata2,paths) ) = coursetime_paths(rowdata2,paths,polygons=polygons,logfile=logfile)
( (
coursetimefirst, coursetimefirst,
coursemetersfirst, coursemetersfirst,
firstcompleted firstcompleted
) = coursetime_first( ) = coursetime_first(
rowdata2,paths) rowdata2,paths,polygons=polygons,logfile=logfile)
@@ -541,6 +559,8 @@ def handle_check_race_course(self,
conn.close() conn.close()
engine.dispose() engine.dispose()
os.remove(logfile)
return 1 return 1
else: else:
@@ -574,9 +594,11 @@ def handle_check_race_course(self,
# send email # send email
handle_sendemail_coursefail( handle_sendemail_coursefail(
useremail,userfirstname, useremail,userfirstname,logfile
) )
os.remove(logfile)
return 2 return 2
return 0 return 0
@@ -1168,7 +1190,7 @@ def handle_sendemail_raceregistration(
return 1 return 1
def handle_sendemail_coursefail( def handle_sendemail_coursefail(
useremail, username, **kwargs): useremail, username, logfile, **kwargs):
if 'debug' in kwargs: if 'debug' in kwargs:
debug = kwargs['debug'] debug = kwargs['debug']
@@ -1186,7 +1208,10 @@ def handle_sendemail_coursefail(
res = send_template_email(from_email,[useremail], res = send_template_email(from_email,[useremail],
subject, subject,
'trajectoryfailemail.html', 'trajectoryfailemail.html',
d,**kwargs) d,
cc=['info@rowsandall.com'],
attach_file=logfile,
**kwargs)
return 1 return 1

View File

@@ -16,6 +16,10 @@
contact me by reply to this email. contact me by reply to this email.
</p> </p>
<p>
The attachment contains debugging information for the site owners.
</p>
<p> <p>
Best Regards, the Rowsandall Team Best Regards, the Rowsandall Team
</p> </p>