Display progress bar and user info. Args: progress (float): progress [0, 1], negative for halt, and >=1 for done. info (str): a string for user provided info to be displayed.
(progress, info)
| 25 | |
| 26 | |
| 27 | def update_progress(progress, info): |
| 28 | """Display progress bar and user info. |
| 29 | |
| 30 | Args: |
| 31 | progress (float): progress [0, 1], negative for halt, and >=1 for done. |
| 32 | info (str): a string for user provided info to be displayed. |
| 33 | """ |
| 34 | barLength = 20 # bar length |
| 35 | status = "" |
| 36 | if isinstance(progress, int): |
| 37 | progress = float(progress) |
| 38 | if not isinstance(progress, float): |
| 39 | progress = 0 |
| 40 | status = "error: progress var must be float. " |
| 41 | if progress < 0: |
| 42 | progress = 0 |
| 43 | status = "Halt. " |
| 44 | if progress >= 1: |
| 45 | progress = 1 |
| 46 | status = "Done. " |
| 47 | status = status + info |
| 48 | block = int(round(barLength * progress)) |
| 49 | text = "[{0}] {1:3.1f}% {2}".format("." * block + " " * (barLength - block), |
| 50 | progress * 100, status) |
| 51 | sys.stdout.write(text) |
| 52 | sys.stdout.write('\b' * (9 + barLength + len(status))) |
| 53 | sys.stdout.flush() |
| 54 | |
| 55 | |
| 56 | def handle_odd_pad_fwd(x, odd_padding, is_pool=False): |