mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2025-12-14 23:07:09 +00:00
TOTAL duration and colour highlighting
This commit is contained in:
@@ -239,6 +239,18 @@ class JobQueue:
|
|||||||
self.queue.append((label, func))
|
self.queue.append((label, func))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def compute_total(self,i):
|
||||||
|
"""Adds up the duration of each module of the database reset and reimport
|
||||||
|
for a specified run in the history"""
|
||||||
|
total = 0
|
||||||
|
for module in self.results_order:
|
||||||
|
if module in ["runlabel", "date", "test", "TOTAL"]:
|
||||||
|
continue
|
||||||
|
# print(i, module, f"length={len(self.results[module])} ")
|
||||||
|
if self.results[module][i]:
|
||||||
|
total += float(self.results[module][i])
|
||||||
|
return total
|
||||||
|
|
||||||
def loadprofiles(self):
|
def loadprofiles(self):
|
||||||
"""Load timings for previous imports for each data import type"""
|
"""Load timings for previous imports for each data import type"""
|
||||||
if os.path.isfile(self.tfile):
|
if os.path.isfile(self.tfile):
|
||||||
@@ -252,21 +264,15 @@ class JobQueue:
|
|||||||
print(f"FAILURE parsing JSON file {self.tfile}")
|
print(f"FAILURE parsing JSON file {self.tfile}")
|
||||||
# Python bug: https://github.com/ShinNoNoir/twitterwebsearch/issues/12
|
# Python bug: https://github.com/ShinNoNoir/twitterwebsearch/issues/12
|
||||||
f.close()
|
f.close()
|
||||||
self.results["TOTAL"] = []
|
self.results["TOTAL"] = []
|
||||||
for i in range(len(self.results["date"])):
|
for i in range(len(self.results["date"])):
|
||||||
total = 0
|
self.results["TOTAL"].append(self.compute_total(i))
|
||||||
for module in self.results_order:
|
|
||||||
if module in ["runlabel", "date", "test", "TOTAL"]:
|
|
||||||
continue
|
|
||||||
# print(i, module, f"length={len(self.results[module])} ")
|
|
||||||
if self.results[module][i]:
|
|
||||||
total += float(self.results[module][i])
|
|
||||||
self.results["TOTAL"].append(total)
|
|
||||||
|
|
||||||
|
|
||||||
for j in self.results_order:
|
for j in self.results_order:
|
||||||
|
# if j == "TOTAL":
|
||||||
|
# # do not append None to total as it has not been computed yet.
|
||||||
|
# continue
|
||||||
self.results[j].append(None) # append a placeholder
|
self.results[j].append(None) # append a placeholder
|
||||||
self.results["TOTAL"].append(None)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def dellastprofile(self):
|
def dellastprofile(self):
|
||||||
@@ -318,6 +324,10 @@ class JobQueue:
|
|||||||
|
|
||||||
jobend = time.time()
|
jobend = time.time()
|
||||||
jobduration = jobend - jobstart
|
jobduration = jobend - jobstart
|
||||||
|
self.results["TOTAL"].pop()
|
||||||
|
self.results["TOTAL"].append(self.compute_total(len(self.results["date"])-1))
|
||||||
|
#self.results["TOTAL"].append(None)
|
||||||
|
|
||||||
print(f"** Ended job {self.runlabel} - {jobduration:.1f} seconds total.")
|
print(f"** Ended job {self.runlabel} - {jobduration:.1f} seconds total.")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -347,11 +357,20 @@ class JobQueue:
|
|||||||
|
|
||||||
def showprofile(self):
|
def showprofile(self):
|
||||||
"""Prints out the time it took to run the jobqueue"""
|
"""Prints out the time it took to run the jobqueue"""
|
||||||
|
RED = '\033[31m'
|
||||||
|
YELLOW = '\033[33m'
|
||||||
|
BLUE = '\033[34m'
|
||||||
|
MAGENTA = '\033[35m'
|
||||||
|
RESET = '\033[0m'
|
||||||
for k in self.results_order:
|
for k in self.results_order:
|
||||||
if k == "test":
|
if k == "test":
|
||||||
break
|
continue
|
||||||
elif k == "date":
|
elif k == "date":
|
||||||
print(" days ago ", end=" ")
|
print(f"{YELLOW} days ago ", end=" ")
|
||||||
|
elif k == "runlabel":
|
||||||
|
print(f"{YELLOW} label ", end=" ")
|
||||||
|
elif k == "TOTAL":
|
||||||
|
print(f"{MAGENTA}%10s (s)" % k, end=" ")
|
||||||
else:
|
else:
|
||||||
print("%10s (s)" % k, end=" ")
|
print("%10s (s)" % k, end=" ")
|
||||||
percen = 0
|
percen = 0
|
||||||
@@ -387,14 +406,7 @@ class JobQueue:
|
|||||||
print(f"{percen:8.1f}%", end=" ")
|
print(f"{percen:8.1f}%", end=" ")
|
||||||
else:
|
else:
|
||||||
print(" - ", end=" ")
|
print(" - ", end=" ")
|
||||||
print("")
|
print(f"{RESET}")
|
||||||
print("\n TOTAL (s)", end=" ")
|
|
||||||
for t in self.results["TOTAL"]:
|
|
||||||
if t:
|
|
||||||
print(f"{t:8.1f}", end=" ")
|
|
||||||
# else:
|
|
||||||
# print(" - ", end=" ")
|
|
||||||
print("\n")
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@@ -506,7 +518,7 @@ if __name__ == "__main__":
|
|||||||
jq.dellastprofile() # twice because loadprofiles adds a dummy
|
jq.dellastprofile() # twice because loadprofiles adds a dummy
|
||||||
jq.showprofile()
|
jq.showprofile()
|
||||||
jq.saveprofiles()
|
jq.saveprofiles()
|
||||||
if runlabel == "delfirst":
|
elif runlabel == "delfirst":
|
||||||
jq.loadprofiles()
|
jq.loadprofiles()
|
||||||
jq.dellastprofile() # remove the dummy
|
jq.dellastprofile() # remove the dummy
|
||||||
jq.delfirstprofile()
|
jq.delfirstprofile()
|
||||||
|
|||||||
Reference in New Issue
Block a user