get the profile display working & bug fix

This commit is contained in:
Philip Sargent 2020-04-15 23:29:59 +01:00
parent 9db7d8e589
commit e5c288c764
2 changed files with 24 additions and 18 deletions

View File

@ -161,7 +161,7 @@ class JobQueue():
self.results = {} self.results = {}
self.results_order=[ self.results_order=[
"date","runlabel","reload", "caves", "people", "date","runlabel","reload", "caves", "people",
"logbooks", "surveyscans", "QMs", "survex" "logbooks", "scans", "QMs", "survex",
"tunnel", "surveys", "test", "makedirs", "redirect" ] "tunnel", "surveys", "test", "makedirs", "redirect" ]
for k in self.results_order: for k in self.results_order:
self.results[k]=[] self.results[k]=[]
@ -182,7 +182,7 @@ class JobQueue():
def run(self): def run(self):
import json import json
tfile = "import_times.json" tfile = "import_profile.json"
if os.path.isfile(tfile): if os.path.isfile(tfile):
try: try:
f = open(tfile, "r") f = open(tfile, "r")
@ -194,13 +194,17 @@ class JobQueue():
# Python bug: https://github.com/ShinNoNoir/twitterwebsearch/issues/12 # Python bug: https://github.com/ShinNoNoir/twitterwebsearch/issues/12
f.close() f.close()
for i in self.queue:
print i, self.results[i[0]]
self.results[i[0]].append(1.0)
print "** Running job ", self.runlabel print "** Running job ", self.runlabel
for i in self.queue: for i in self.queue:
#print "*- Running \"", i[0], "\"" #print "*- Running \"", i[0], "\""
start = time.time() start = time.time()
i[1]() i[1]()
duration = time.time()-start duration = time.time()-start
#print "\n*- Ended \"", i[0], "\"" print "\n*- Ended \"", i[0], "\" %.1f seconds" % duration
self.results[i[0]].append(duration) self.results[i[0]].append(duration)
self.results["date"].append(start) self.results["date"].append(start)
self.results["runlabel"].append(self.runlabel) self.results["runlabel"].append(self.runlabel)
@ -210,21 +214,21 @@ class JobQueue():
with open(tfile, 'w') as f: with open(tfile, 'w') as f:
json.dump(self.results, f) json.dump(self.results, f)
for i in self.results_order: for k in self.results_order:
percen=0 percen=0
if i == "runlabel": if k == "runlabel":
pass pass
if i =="date": if k =="date":
# Calculate dates as days before present to one decimal place # Calculate dates as days before present to one decimal place
pass pass
elif len(self.results[i])>0: elif len(self.results[k])>3:
lst = self.results[i] lst = self.results[k]
e = len(lst)-1 e = len(lst)-1
percen = 100* (lst[e] - lst[e-1])/lst[e-1] percen = 100* (lst[e] - lst[e-1])/lst[e-1]
if abs(percen) >0.1: if abs(percen) >0.1:
print '%15s %8.1f%%' % (i, percen) print '%15s %8.1f%%' % (k, percen)
else: else:
print '%15s ' % (i) print '%15s ' % (k)
return True return True
@ -238,14 +242,14 @@ def importtest():
return True return True
def usage(): def usage():
print("""Usage is 'python databaseReset.py <command>' print("""Usage is 'python databaseReset.py <command> [runlabel]'
where command is: where command is:
reset - this is normal usage, clear database and reread everything from files - time-consuming reset - this is normal usage, clear database and reread everything from files - time-consuming
caves - read in the caves caves - read in the caves
logbooks - read in just the logbooks logbooks - read in just the logbooks
people - read in the people from folk.csv people - read in the people from folk.csv
QMs - read in the QM files QMs - read in the QM csv files
reload_db - clear database i.e. delete everything reload_db - clear database (delete everything) and make empty tables
scans - NOT the scanned surveynotes ?! scans - NOT the scanned surveynotes ?!
survex - read in the survex files - all the survex blocks survex - read in the survex files - all the survex blocks
surveys - read in the scanned surveynotes surveys - read in the scanned surveynotes
@ -258,6 +262,9 @@ def usage():
autologbooks - read in autologbooks (what are these?) autologbooks - read in autologbooks (what are these?)
dumplogbooks - write out autologbooks (not working?) dumplogbooks - write out autologbooks (not working?)
test - testing... test - testing...
and [runlabel] is an optional string identifying this run of the script
in the stored profiling data 'import-profile.json'
""") """)
if __name__ == "__main__": if __name__ == "__main__":
@ -269,7 +276,6 @@ if __name__ == "__main__":
runlabel = sys.argv[len(sys.argv)-1] runlabel = sys.argv[len(sys.argv)-1]
jq = JobQueue(runlabel) jq = JobQueue(runlabel)
if "test" in sys.argv: if "test" in sys.argv:
jq.enq("test",importtest) jq.enq("test",importtest)
jq.enq("caves",importtest) jq.enq("caves",importtest)
@ -284,13 +290,13 @@ if __name__ == "__main__":
elif "QMs" in sys.argv: elif "QMs" in sys.argv:
jq.enq("QMs",import_QMs) jq.enq("QMs",import_QMs)
elif "reload_db" in sys.argv: elif "reload_db" in sys.argv:
jq.enq("reload_db",reload_db) jq.enq("reload",reload_db)
elif "reset" in sys.argv: elif "reset" in sys.argv:
jq.enq("reload",reload_db) jq.enq("reload",reload_db)
jq.enq("makedirs",make_dirs) jq.enq("makedirs",make_dirs)
jq.enq("redirect",pageredirects) jq.enq("redirect",pageredirects)
jq.enq("caves",import_caves) jq.enq("caves",import_caves)
jq.enq("logbooks",import_people) jq.enq("people",import_people)
jq.enq("scans",import_surveyscans) jq.enq("scans",import_surveyscans)
jq.enq("logbooks",import_logbooks) jq.enq("logbooks",import_logbooks)
jq.enq("QMs",import_QMs) jq.enq("QMs",import_QMs)

View File

@ -15,7 +15,7 @@ from datetime import datetime
line_leg_regex = re.compile(r"[\d\-+.]+$") line_leg_regex = re.compile(r"[\d\-+.]+$")
def LoadSurvexLineLeg(survexblock, stardata, sline, comment, cave): def LoadSurvexLineLeg(survexblock, stardata, sline, comment, cave):
# The try catches here need replacing as they are relativly expensive # The try catches here need replacing as they are relatively expensive
ls = sline.lower().split() ls = sline.lower().split()
ssfrom = survexblock.MakeSurvexStation(ls[stardata["from"]]) ssfrom = survexblock.MakeSurvexStation(ls[stardata["from"]])
ssto = survexblock.MakeSurvexStation(ls[stardata["to"]]) ssto = survexblock.MakeSurvexStation(ls[stardata["to"]])
@ -401,4 +401,4 @@ def LoadPos():
ss.z = float(z) ss.z = float(z)
ss.save() ss.save()
except: except:
print("%s not parsed in survex" % name) print("%s not parsed in survex %s" % (name, pos))