Quickly fix dodgy est. time remaining

This commit is contained in:
Erik Johnston 2015-04-28 12:55:29 +01:00
parent 18f8247701
commit a1d4813a54
1 changed files with 14 additions and 7 deletions

View File

@ -535,11 +535,20 @@ class CursesProgress(Progress):
self.finished = False self.finished = False
self.total_processed = 0
self.total_remaining = 0
super(CursesProgress, self).__init__() super(CursesProgress, self).__init__()
def update(self, table, num_done): def update(self, table, num_done):
super(CursesProgress, self).update(table, num_done) super(CursesProgress, self).update(table, num_done)
self.total_processed = 0
self.total_remaining = 0
for table, data in self.tables.items():
self.total_processed += data["num_done"] - data["start"]
self.total_remaining += data["total"] - data["num_done"]
self.render() self.render()
def render(self, force=False): def render(self, force=False):
@ -561,13 +570,11 @@ class CursesProgress(Progress):
if self.finished: if self.finished:
status = "Time spent: %s (Done!)" % (duration_str,) status = "Time spent: %s (Done!)" % (duration_str,)
else: else:
min_perc = min(
(v["num_done"] - v["start"]) * 100. / (v["total"] - v["start"]) if self.total_processed > 0:
if v["total"] - v["start"] else 100 left = float(self.total_remaining) / self.total_processed
for v in self.tables.values()
) est_remaining = (int(now) - self.start_time) * left
if min_perc > 0:
est_remaining = (int(now) - self.start_time) * 100 / min_perc
est_remaining_str = '%02dm %02ds remaining' % divmod(est_remaining, 60) est_remaining_str = '%02dm %02ds remaining' % divmod(est_remaining, 60)
else: else:
est_remaining_str = "Unknown" est_remaining_str = "Unknown"