From 37df27031ec84e47e440b7ad2e04cc32352e28cd Mon Sep 17 00:00:00 2001
From: Andreas Kloeckner <inform@tiker.net>
Date: Thu, 15 Nov 2007 00:45:00 -0600
Subject: [PATCH] Add ETA estimator.

---
 src/stopwatch.py | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/src/stopwatch.py b/src/stopwatch.py
index bdb5e76..6829b60 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]
-- 
GitLab