-
-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathdynamic_message.py
More file actions
35 lines (26 loc) · 858 Bytes
/
Copy pathdynamic_message.py
File metadata and controls
35 lines (26 loc) · 858 Bytes
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
"""``DynamicMessage`` is the original name for ``Variable``.
Same widget, kept as an alias for code written against the old name;
prefer ``Variable`` in new code. Shown here in its classic role: a live
training metric climbing toward its target, reported next to the bar.
"""
import random
import time
import progressbar
random.seed(0)
STEPS = 24
def main() -> None:
widgets = [
progressbar.Percentage(),
' ',
progressbar.Bar(),
' ',
progressbar.DynamicMessage('accuracy'),
]
with progressbar.ProgressBar(max_value=STEPS, widgets=widgets) as bar:
accuracy = 0.5
for step in range(STEPS):
accuracy += (1 - accuracy) * (0.05 + random.random() * 0.05)
bar.update(step + 1, accuracy=accuracy)
time.sleep(0.005)
if __name__ == '__main__':
main()