[Bf-extensions-cvs] [acef94f] master: Timing info added to the progress report system.

Lukas Tönne noreply at git.blender.org
Mon Dec 15 14:58:27 CET 2014


Commit: acef94fe99587564e10cf2c4d7ee064f472d0afe
Author: Lukas Tönne
Date:   Mon Dec 15 14:58:00 2014 +0100
Branches: master
https://developer.blender.org/rBACacef94fe99587564e10cf2c4d7ee064f472d0afe

Timing info added to the progress report system.

===================================================================

M	object_physics_meadow/patch.py
M	object_physics_meadow/util.py

===================================================================

diff --git a/object_physics_meadow/patch.py b/object_physics_meadow/patch.py
index 888c70d..1270a18 100644
--- a/object_physics_meadow/patch.py
+++ b/object_physics_meadow/patch.py
@@ -253,34 +253,10 @@ def bake_all(context, progress_reporter):
     total = count_bakeable(context)
     
     with progress_reporter("Bake Blob", 0, total):
-        """
-        num = 0
-        """
         for ob in patch_objects(context):
             for psys in ob.particle_systems:
-                """
-                sys.stdout.write("Baking blob {}/{} ... ".format(str(num).rjust(5), str(total).ljust(5)))
-                sys.stdout.flush()
-                
-                start_time = time.time()
-                """
-                
                 progress_add(1)
                 bake_psys(context, ob, psys)
-                
-                """
-                duration = time.time() - start_time
-                total_time += duration
-                avg_time = total_time / float(num + 1)
-                
-                time_string = lambda x: time.strftime("%H:%M:%S", time.gmtime(x)) + ".%02d" % (int(x * 100.0) % 100)
-                durstr = time_string(duration)
-                avgstr = time_string(avg_time) if avg_time > 0.0 else "--:--:--"
-                etastr = time_string(avg_time * (total - num)) if avg_time > 0.0 else "--:--:--"
-                sys.stdout.write("{} (avg. {}, ETA {})\n".format(durstr, avgstr, etastr))
-                sys.stdout.flush()
-                num += 1
-                """
 
 def patch_objects_rebake(context, progress_reporter=DummyProgressContext):
     settings = _settings.get(context)
diff --git a/object_physics_meadow/util.py b/object_physics_meadow/util.py
index b709b65..5f2127a 100644
--- a/object_physics_meadow/util.py
+++ b/object_physics_meadow/util.py
@@ -99,6 +99,12 @@ def set_object_parent(ob, parent):
 
 _progress_context = None
 
+def get_time_string(x):
+    if x >= 0.0:
+        return time.strftime("%H:%M:%S", time.gmtime(x)) + ".%02d" % (int(x * 100.0) % 100)
+    else:
+        return "??:??:??.??"
+
 def make_progress_reporter(show_progress_bar=True, show_stdout=False):
 
     # internal class returned by the function, bound to output args
@@ -113,12 +119,17 @@ def make_progress_reporter(show_progress_bar=True, show_stdout=False):
             self.pcur = pmin
             self.perc_show = -2.0 # last displayed percentage, init to make sure we show the first time
 
+            self.duration = 0.0
+            self.start_time = 0.0
+
         def __enter__(self):
             global _progress_context
 
             assert(_progress_context is None)
             _progress_context = self
             
+            self.start_time = time.time()
+
             if show_progress_bar:
                 wm = bpy.context.window_manager
                 # always use 0..100 percentage on the progress counter,
@@ -133,6 +144,11 @@ def make_progress_reporter(show_progress_bar=True, show_stdout=False):
                 wm.progress_end()
 
             if show_stdout:
+                # make a final report
+                done = self.pcur - self.pmin
+                sys.stdout.write("\r>> {}: {}/{}, {}".format(self.name,
+                                                                    str(done).rjust(len(str(self.tot))), str(self.tot),
+                                                                    get_time_string(self.duration)))
                 # clean newline
                 sys.stdout.write("\n")
                 sys.stdout.flush()
@@ -140,6 +156,13 @@ def make_progress_reporter(show_progress_bar=True, show_stdout=False):
             assert(_progress_context is self)
             _progress_context = None
 
+        def estimate_total_duration(self):
+            done = self.pcur - self.pmin
+            if done > 0:
+                return self.duration * self.tot / done
+            else:
+                return -1.0
+
         def set_progress(self, value, message):
             self.pcur = value
             done = value - self.pmin
@@ -149,14 +172,25 @@ def make_progress_reporter(show_progress_bar=True, show_stdout=False):
             # avoids overhead for very frequent updates
             if perc > self.perc_show + 1.0:
                 self.perc_show = perc
-                perc = min(max(int(perc), 0), 100)
+                perc = min(max(perc, 0), 100)
+
+                self.duration = time.time() - self.start_time
 
                 if show_progress_bar:
                     wm = bpy.context.window_manager
                     wm.progress_update(perc)
 
                 if show_stdout:
-                    sys.stdout.write("\r>> {}: {}/{} [{}{}] {}".format(self.name, str(done).rjust(len(str(self.tot))), str(self.tot), '.' * perc, ' ' * (100 - perc), message))
+                    bar = 50
+                    filled = int(bar * done * self.norm)
+
+                    eta = self.estimate_total_duration()
+
+                    sys.stdout.write("\r>> {}: {}/{} [{}{}] {}/{} | {}".format(self.name,
+                                                                               str(done).rjust(len(str(self.tot))), str(self.tot),
+                                                                               '.' * filled, ' ' * (bar - filled),
+                                                                               get_time_string(self.duration), get_time_string(eta),
+                                                                               message))
                     sys.stdout.flush()
 
     return ProgressContext



More information about the Bf-extensions-cvs mailing list