<reponame>computational-medicine/BMED360-2021<filename>Lab3-diffusion-MRI/utils.py
# utils.py
# A.L. 2020-02-27


#### BEGIN PROGRESS BAR #####
# https://stackoverflow.com/questions/3160699/python-progress-bar

import sys

def progressbar(it, prefix="", size=60, file=sys.stdout):
    """
    Usage:
    import time

    for i in progressbar(range(15), "Computing: ", 40):
        time.sleep(0.1) # any calculation you need
    
    Output:
    Computing: [################........................] 4/15
    """
    count = len(it)
    def show(j):
        x = int(size*j/count)
        file.write("%s[%s%s] %i/%i\r" % (prefix, "#"*x, "."*(size-x), j, count))
        file.flush()        
    show(0)
    for i, item in enumerate(it):
        yield item
        show(i+1)
    file.write("\n")
    file.flush()
   
#### END PROGRESS BAR #####
# utils.py
# A.L. 2020-02-27


#### BEGIN PROGRESS BAR #####
# https://stackoverflow.com/questions/3160699/python-progress-bar

import sys

def progressbar(it, prefix="", size=60, file=sys.stdout):
    """
    Usage:
    import time

    for i in progressbar(range(15), "Computing: ", 40):
        time.sleep(0.1) # any calculation you need
    
    Output:
    Computing: [################........................] 4/15
    """
    count = len(it)
    def show(j):
        x = int(size*j/count)
        file.write("%s[%s%s] %i/%i\r" % (prefix, "#"*x, "."*(size-x), j, count))
        file.flush()        
    show(0)
    for i, item in enumerate(it):
        yield item
        show(i+1)
    file.write("\n")
    file.flush()
   
#### END PROGRESS BAR #####
# utils.py # A.L. 2020-02-27 #### BEGIN PROGRESS BAR ##### # https://stackoverflow.com/questions/3160699/python-progress-bar Usage:     import time      for i in progressbar(range(15), "Computing: ", 40):         time.sleep(0.1) # any calculation you need          Output:     Computing: [################........................] 4/15 #### END PROGRESS BAR #####