diff --git a/src/stopwatch.py b/src/stopwatch.py index bdb5e76af83efea92cbeae4d3c3fcee458c44c52..6829b6068ae5db9db90fae27d1f93d4e4e29fcbd 100644 --- a/src/stopwatch.py +++ b/src/stopwatch.py @@ -1,3 +1,4 @@ +from __future__ import division import time import pytools @@ -46,6 +47,26 @@ class Job: else: return self.Name in VISIBLE_JOBS + + + +class EtaEstimator: + def __init__(self, total_steps): + self.stopwatch = StopWatch().start() + self.total_steps = total_steps + assert total_steps > 0 + + def estimate(self, done): + fraction_done = done/self.total_steps + time_spent = self.stopwatch.elapsed() + if fraction_done > 1e-5: + return time_spent/fraction_done-time_spent + else: + return None + + + + def print_job_summary(): for key in JOB_TIMES: print key, " " * (50-len(key)), JOB_TIMES[key]