Created
April 2, 2021 13:35
-
-
Save mwielondek/cf5f99b1064d6ed6e596ca198a8f6a66 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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