-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathcounter.py
101 lines (82 loc) · 2.56 KB
/
counter.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
"""
Copyright (c) 2011,2012,2016,2017 Merck Sharp & Dohme Corp. a subsidiary of Merck & Co., Inc., Kenilworth, NJ, USA.
This file is part of the Deep Neural Network QSAR program.
Deep Neural Network QSAR is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
"""
Original version by George Dahl in Dec.11, 2012.
Last modified by Yuting Xu in Jul.6, 2016.
"""
from sys import stderr
class Counter:
def __init__(self, step=10):
self.cur = 0
self.step = step
def tick(self):
self.cur += 1
if self.cur % self.step == 0:
stderr.write( str(self.cur ) )
stderr.write( "\r" )
stderr.flush()
def done(self):
stderr.write( str(self.cur ) )
stderr.write( "\n" )
stderr.flush()
class Progress(object):
def __init__(self, numSteps):
self.total = numSteps
self.cur = 0
self.curPercent = 0
def tick(self):
self.cur += 1
newPercent = (100*self.cur)/self.total
if newPercent > self.curPercent:
self.curPercent = newPercent
stderr.write( str(self.curPercent)+"%" )
stderr.write( "\r" )
stderr.flush()
def done(self):
stderr.write( '100%' )
stderr.write( "\n" )
stderr.flush()
class DummyProgBar(object):
def __init__(self, *args): pass
def tick(self): pass
def done(self): pass
def ProgressLine(line):
stderr.write(line)
stderr.write( "\r" )
stderr.flush()
def main():
from time import sleep
print("Play with ProgressLine:")
for i in range(100):
s = str(2.0*i)
ProgressLine(s)
sleep(0.1)
print( "\n" )
print("Play with Counter:")
c = Counter(5)
for i in range(100):
c.tick()
sleep(.1)
c.done()
print( "\n" )
print("Play with Progress:")
p = Progress(100)
for i in range(100):
p.tick()
sleep(.1)
p.done()
print( "\n" )
if __name__ == "__main__":
main()