@@ -439,6 +439,29 @@ def init_timers():
439439 return time (), time ()
440440
441441
442+ # -- Utils --
443+ def report_progress (current , total , chunk_size , cnt , t0 , t1 ):
444+ eta = get_eta (current , total , chunk_size , t1 )
445+ runtime = get_runtime (current , total , chunk_size , t0 , t1 )
446+ progress_bar2 (current , total , eta = eta , runtime = runtime )
447+ return cnt + 1 , time ()
448+
449+
450+ def get_eta (current , total , chunk_size , t0 , return_str = True ):
451+ chunk_runtime = time () - t0
452+ remaining = total - current
453+ eta = remaining * (chunk_runtime / chunk_size )
454+ t , unit = time_writer (eta )
455+ return f"{ round (t , 4 )} { unit } " if return_str else eta
456+
457+
458+ def get_runtime (current , total , chunk_size , t0 , t1 ):
459+ eta = get_eta (current , total , chunk_size , t1 , return_str = False )
460+ total_runtime = time () - t0 + eta
461+ t , unit = time_writer (total_runtime )
462+ return f"{ round (t , 4 )} { unit } "
463+
464+
442465def progress_bar (current , total , bar_length = 50 ):
443466 """
444467 Reports the progress of completing some process.
@@ -462,3 +485,11 @@ def progress_bar(current, total, bar_length=50):
462485 f"[{ '=' * progress } { ' ' * (bar_length - progress )} ] { current } /{ total } "
463486 )
464487 print (f"\r { bar } " , end = "" , flush = True )
488+
489+ def progress_bar2 (current , total , bar_length = 50 , eta = None , runtime = None ):
490+ progress = int (current / total * bar_length )
491+ n_completed = f"Completed: { current } /{ total } "
492+ bar = f"[{ '=' * progress } { ' ' * (bar_length - progress )} ]"
493+ eta = f"Time Remaining: { eta } " if eta else ""
494+ runtime = f"Estimated Total Runtime: { runtime } " if runtime else ""
495+ print (f"\r { bar } { n_completed } | { eta } | { runtime } " , end = "" , flush = True )
0 commit comments