Skip to content

Instantly share code, notes, and snippets.

@mwielondek
Created April 2, 2021 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mwielondek/cf5f99b1064d6ed6e596ca198a8f6a66 to your computer and use it in GitHub Desktop.
Save mwielondek/cf5f99b1064d6ed6e596ca198a8f6a66 to your computer and use it in GitHub Desktop.
class ProgressBar:
def __init__(self, n):
self.total = n
self.counter = 0
self.prev_time = time()
self.time_deltas = []
def next(self):
self.counter += 1
left = self.total - self.counter
time_delta = time() - self.prev_time
self.prev_time = time()
self.time_deltas.append(time_delta)
est_time_left = left * np.median(self.time_deltas)
timer_str = "est time left: {:5.0f}s".format(est_time_left)
progress_str = "Progress: {}{} | {}".format("#"*self.counter, "-"*(left), timer_str)
print('\r'+progress_str, end='')
if self.counter == self.total:
print(' ✔︎')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment