Private
Public Access
1
0

better logging

This commit is contained in:
Sander Roosendaal
2020-07-07 18:15:31 +02:00
parent 001cf55591
commit 6a655960e5
2 changed files with 41 additions and 42 deletions

View File

@@ -40,23 +40,23 @@ def time_in_path(df,p,maxmin='max',getall=False,name='unknown',logfile=None):
if len(df[b==2]): if len(df[b==2]):
if logfile is not None: if logfile is not None:
t = time.localtime() t = time.localtime()
timestamp = time.strftime('%b-%d-%Y_%H%M', t) timestamp = bytes('{t}'.format(t=time.strftime('%b-%d-%Y_%H%M', t)),'utf-8')
with open(logfile,'ab') as f: with open(logfile,'ab') as f:
f.write('\n') f.write(b'\n')
f.write(timestamp) f.write(timestamp)
f.write(' ') f.write(b' ')
f.write(name) f.write(bytes(name,'utf-8'))
f.write(' ') f.write(b' ')
f.write(maxmin) f.write(bytes(maxmin,'utf-8'))
f.write(' ') f.write(b' ')
f.write(str(getall)) f.write(bytes(str(getall),'utf-8'))
f.write(' ') f.write(b' ')
f.write(str(len(df[b==2]))) f.write(bytes(str(len(df[b==2])),'utf-8'))
f.write(' ') f.write(b' ')
if len(df[b==2])>1: if len(df[b==2])>1:
f.write(' passes found') f.write(b' passes found')
else: else:
f.write(' pass found') f.write(b' pass found')
if getall: if getall:
return df[b==2]['time'],df[b==2]['cum_dist'] return df[b==2]['time'],df[b==2]['cum_dist']
else: else:
@@ -64,20 +64,20 @@ def time_in_path(df,p,maxmin='max',getall=False,name='unknown',logfile=None):
if logfile is not None: if logfile is not None:
t = time.localtime() t = time.localtime()
timestamp = time.strftime('%b-%d-%Y_%H%M', t) timestamp = bytes('{t}'.format(t=time.strftime('%b-%d-%Y_%H%M', t)),'utf-8')
with open(logfile,'ab') as f: with open(logfile,'ab') as f:
f.write('\n') f.write(b'\n')
f.write(timestamp) f.write(timestamp)
f.write(' ') f.write(b' ')
f.write(name) f.write(bytes(name,'utf-8'))
f.write(' ') f.write(b' ')
f.write(maxmin) f.write(bytes(maxmin,'utf-8'))
f.write(' ') f.write(b' ')
f.write(str(getall)) f.write(bytes(str(getall),'utf-8'))
f.write(' ') f.write(b' ')
f.write(str(len(df[b==2]))) f.write(bytes(str(len(df[b==2])),'utf-8'))
f.write(' ') f.write(b' ')
f.write(' pass not found') f.write(b' pass not found')
raise InvalidTrajectoryError("Trajectory doesn't go through path") raise InvalidTrajectoryError("Trajectory doesn't go through path")

View File

@@ -197,9 +197,9 @@ def handle_strava_sync(stravatoken,workoutid,filename,name,activity_type,descrip
except: except:
e = sys.exc_info()[0] e = sys.exc_info()[0]
t = time.localtime() t = time.localtime()
timestamp = time.strftime('%b-%d-%Y_%H%M', t) timestamp = bytes('{t}'.format(t=time.strftime('%b-%d-%Y_%H%M', t)),'utf-8')
with open('stravalog.log','ab') as f: with open('stravalog.log','ab') as f:
f.write('\n') f.write(b'\n')
f.write(timestamp) f.write(timestamp)
f.write(str(e)) f.write(str(e))
@@ -448,13 +448,13 @@ def handle_check_race_course(self,
name=polygons[0].name,logfile=logfile) name=polygons[0].name,logfile=logfile)
with open(logfile,'ab') as f: with open(logfile,'ab') as f:
t = time.localtime() t = time.localtime()
timestamp = time.strftime('%b-%d-%Y_%H%M', t) timestamp = bytes('{t}'.format(t=time.strftime('%b-%d-%Y_%H%M', t)),'utf-8')
f.write('\n') f.write(b'\n')
f.write('Course id {n}, Record id {m}'.format(n=courseid,m=recordid)) f.write(bytes('Course id {n}, Record id {m}'.format(n=courseid,m=recordid),'utf-8'))
f.write('\n') f.write(b'\n')
f.write(timestamp) f.write(timestamp)
f.write(' ') f.write(b' ')
f.write('Found {n} entrytimes'.format(n=len(entrytimes))) f.write(bytes('Found {n} entrytimes'.format(n=len(entrytimes)),'utf-8'))
except InvalidTrajectoryError: except InvalidTrajectoryError:
entrytimes = [] entrytimes = []
@@ -473,11 +473,11 @@ def handle_check_race_course(self,
for startt in entrytimes: for startt in entrytimes:
with open(logfile,'ab') as f: with open(logfile,'ab') as f:
t = time.localtime() t = time.localtime()
timestamp = time.strftime('%b-%d-%Y_%H%M', t) timestamp = bytes('{t}'.format(t=time.strftime('%b-%d-%Y_%H%M', t)),'utf-8')
f.write('\n') f.write(b'\n')
f.write(timestamp) f.write(timestamp)
f.write(' ') f.write(b' ')
f.write('Path starting at {t}'.format(t=startt)) f.write(bytes('Path starting at {t}'.format(t=startt),'utf-8'))
rowdata2 = rowdata[rowdata['time']>(startt-10.)] rowdata2 = rowdata[rowdata['time']>(startt-10.)]
( (
@@ -596,17 +596,16 @@ def handle_check_race_course(self,
# add times for all gates to log file # add times for all gates to log file
with open(logfile,'ab') as f: with open(logfile,'ab') as f:
t = time.localtime() t = time.localtime()
f.write('\n') f.write(b'\n')
f.write(timestamp) f.write(b' ')
f.write(' ') f.write(b'--- LOG of all gate times---')
f.write('--- LOG of all gate times---')
for path,polygon in zip(paths,polygons): for path,polygon in zip(paths,polygons):
( secs,meters,completed) = coursetime_paths(rowdata2, ( secs,meters,completed) = coursetime_paths(rowdata2,
[path],polygons=[polygon],logfile=logfile) [path],polygons=[polygon],logfile=logfile)
with open(logfile,'ab') as f: with open(logfile,'ab') as f:
line = " time: {t} seconds, distance: {m} meters".format(t=secs,m=meters) line = " time: {t} seconds, distance: {m} meters".format(t=secs,m=meters)
f.write(line) f.write(bytes(line,'utf-8'))
# send email # send email
handle_sendemail_coursefail( handle_sendemail_coursefail(