-
Notifications
You must be signed in to change notification settings - Fork 0
/
SimpleProgress.py
31 lines (25 loc) · 1.03 KB
/
SimpleProgress.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
import time
class SimpleProgress:
def __init__(self, total):
self.total = total
def start_progress(self):
self.start_time = time.time()
def update(self, x):
if x>0:
elapsed = time.time()-self.start_time
percDone = x*100.0/self.total
estimatedTimeInSec=(elapsed*1.0/x)*self.total
return "%s %s percent\n%s Processed\nElapsed time: %s\nEstimated time: %s\n--------" % (self.bar(percDone), round(percDone, 2), x, self.form(elapsed), self.form(estimatedTimeInSec))
return ""
def expiring(self):
elapsed = time.time()-self.start_time
return elapsed/(60.0**2) > 71.
def form(self, t):
hour = int(t/(60.0*60.0))
minute = int(t/60.0 - hour*60)
sec = int(t-minute*60-hour*3600)
return "%s Hours, %s Minutes, %s Seconds" % (hour, minute, sec)
def bar(self, perc):
done = int(round(30*(perc/100.0)))
left = 30-done
return "[%s%s]" % ('|'*done, ':'*left)