From 7e7e76ab65d06bb8b8dd7438d1a3933ad7015d8f Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Fri, 18 Jan 2008 21:23:21 -0500 Subject: [PATCH] Add ETA estimator. --- src/log.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/log.py b/src/log.py index 004b3ab..9be0f7f 100644 --- a/src/log.py +++ b/src/log.py @@ -692,6 +692,27 @@ class CPUTime(LogQuantity): +class ETA(LogQuantity): + """Records an estimate of how long the computation will still take.""" + def __init__(self, total_steps, name="t_eta"): + LogQuantity.__init__(self, name, "s", "Estimated remaining duration") + + self.steps = 0 + self.total_steps = total_steps + self.start = time() + + def __call__(self): + fraction_done = self.steps/self.total_steps + self.steps += 1 + time_spent = time()-self.start + if fraction_done > 1e-9: + return time_spent/fraction_done-time_spent + else: + return 0 + + + + def add_general_quantities(mgr): """Add generally applicable L{LogQuantity} objects to C{mgr}.""" -- GitLab