summaryrefslogtreecommitdiffstats
path: root/databaseReset.py
diff options
context:
space:
mode:
Diffstat (limited to 'databaseReset.py')
-rw-r--r--databaseReset.py56
1 files changed, 34 insertions, 22 deletions
diff --git a/databaseReset.py b/databaseReset.py
index c75e2db..85961d2 100644
--- a/databaseReset.py
+++ b/databaseReset.py
@@ -239,6 +239,18 @@ class JobQueue:
self.queue.append((label, func))
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):
"""Load timings for previous imports for each data import type"""
if os.path.isfile(self.tfile):
@@ -252,21 +264,15 @@ class JobQueue:
print(f"FAILURE parsing JSON file {self.tfile}")
# Python bug: https://github.com/ShinNoNoir/twitterwebsearch/issues/12
f.close()
- self.results["TOTAL"] = []
+ self.results["TOTAL"] = []
for i in range(len(self.results["date"])):
- 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])
- self.results["TOTAL"].append(total)
-
+ self.results["TOTAL"].append(self.compute_total(i))
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["TOTAL"].append(None)
return True
def dellastprofile(self):
@@ -318,6 +324,10 @@ class JobQueue:
jobend = time.time()
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.")
return True
@@ -347,11 +357,20 @@ class JobQueue:
def showprofile(self):
"""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:
if k == "test":
- break
+ continue
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:
print("%10s (s)" % k, end=" ")
percen = 0
@@ -387,14 +406,7 @@ class JobQueue:
print(f"{percen:8.1f}%", end=" ")
else:
print(" - ", end=" ")
- print("")
- print("\n TOTAL (s)", end=" ")
- for t in self.results["TOTAL"]:
- if t:
- print(f"{t:8.1f}", end=" ")
- # else:
- # print(" - ", end=" ")
- print("\n")
+ print(f"{RESET}")
return True
@@ -506,7 +518,7 @@ if __name__ == "__main__":
jq.dellastprofile() # twice because loadprofiles adds a dummy
jq.showprofile()
jq.saveprofiles()
- if runlabel == "delfirst":
+ elif runlabel == "delfirst":
jq.loadprofiles()
jq.dellastprofile() # remove the dummy
jq.delfirstprofile()