-
Notifications
You must be signed in to change notification settings - Fork 16
/
progress_timer.py
46 lines (37 loc) · 1.19 KB
/
progress_timer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# -*- coding: utf-8 -*-
"""
Created on Thu Apr 12 10:00:05 2018
@author: phamh
"""
#import libraries
import progressbar as pb
#define progress timer class
class progress_timer:
def __init__(self, n_iter, description="Something"):
self.n_iter = n_iter
self.iter = 0
self.description = description + ': '
self.timer = None
self.initialize()
def initialize(self):
#initialize timer
widgets = [self.description, pb.Percentage(), ' ',
pb.Bar('=', '[', ']'), ' ', pb.ETA()]
self.timer = pb.ProgressBar(widgets=widgets, maxval=self.n_iter).start()
def update(self, q=1):
#update timer
self.timer.update(self.iter)
self.iter += q
def finish(self):
#end timer
self.timer.finish()
# =============================================================================
# #initialize
# pt = progress_timer(description= 'For loop example', n_iter=1000000)
# #for loop example
# for i in range(0,1000000):
# #update
# pt.update()
# #finish
# pt.finish()
# =============================================================================