Example #1
0
def _iteration_parameters(image_rows,
                          image_cols,
                          row_block_size,
                          col_block_size,
                          y_overlap=0,
                          x_overlap=0,
                          bands=1):

    maximum_blocks = 0

    for i in range(0, image_rows, row_block_size - y_overlap):

        for j in range(0, image_cols, col_block_size - x_overlap):

            if bands > 1:
                for band in range(1, bands + 1):
                    maximum_blocks += 1
            else:
                maximum_blocks += 1

    progress_widgets = [
        ' Percent: ',
        widgets.Percentage(), ' ',
        widgets.Bar(marker='*', left='[', right=']'), ' ',
        widgets.ETA(), ' ',
        widgets.FileTransferSpeed()
    ]

    progress_bar = ProgressBar(widgets=progress_widgets, maxval=maximum_blocks)

    progress_bar.start()

    return 1, progress_bar
Example #2
0
def _iteration_parameters_values(value1, value2):

    # Set widget and pbar
    progress_widgets = [' Perc: ', widgets.Percentage(), ' ', \
                        widgets.Bar(marker='*', left='[', right=']'), ' ', \
                        widgets.ETA(), ' ', widgets.FileTransferSpeed()]

    progress_bar = ProgressBar(widgets=progress_widgets,
                               maxval=value1 * value2)

    progress_bar.start()

    return 1, progress_bar
Example #3
0
def main():
    decomposer = Decomposer()
    print("Loaded %d characters." % len(HANZI_CHARACTERS))
    if not is_made_of_radicals_only(u'我'):
        sys.exit('ERROR: 我 is not made of radicals, wtf?')
    total_characters = len(HANZI_CHARACTERS)
    matching_characters = 0
    pb = progressbar.ProgressBar(widgets=[PBW.Counter(), PBW.Bar(), PBW.ETA()])
    for char in pb(set(HANZI_CHARACTERS)):
        decomposition = decomposer.decompose(char)
        if is_made_of_radicals_only(decomposition):
            matching_characters = 1
    print("Matched %d characters out of %d" %
          (matching_characters, total_characters))
Example #4
0
 def __init__(self, prefix, max_value):
     ProgressBar.__init__(self,
                          prefix=prefix,
                          max_value=max_value,
                          is_terminal=True,
                          term_width=200)
     self.widgets = [
         widgets.Percentage(**self.widget_kwargs),
         ' ',
         widgets.SimpleProgress(format='(%s)' %
                                widgets.SimpleProgress.DEFAULT_FORMAT,
                                **self.widget_kwargs),
         ' ',
         widgets.Bar(**self.widget_kwargs),
         ' ',
         widgets.Timer(**self.widget_kwargs),
         ' ',
         widgets.ETA(**self.widget_kwargs),
     ]
Example #5
0
def download(url, filename):
    """Attempts to download url to filename unless the two files have the same size"""
    r = requests.get(url, stream=True)
    size = int(r.headers.get('Content-Length'))
    bname = basename(filename)

    if size and isfile(filename) and os.path.getsize(filename) == size:
        print('File %s already exists, skipping download' % bname, file=sys.stderr)
        return

    currdown = 0.0
    fmt = [
        'Downloading %s: ' % bname, widgets.Bar(), ' ',
        widgets.RotatingMarker(), ' ', widgets.Percentage(), ' ',
        widgets.FileTransferSpeed(), ' ', widgets.ETA()
    ]

    progress = ProgressBar(maxval=size or 100, widgets=fmt)
    progress.start()

    # https://stackoverflow.com/a/5137509
    mkdir_p(dirname(realpath(filename)))

    # https://stackoverflow.com/a/16696317
    with open(filename, 'wb') as f:
        for chunk in r.iter_content(chunk_size=65536):
            if chunk:
                f.write(chunk)

            currdown += len(chunk)

            if size:
                progress.update(currdown)
            else:
                progress.update(random.randint(0, 100))

    progress.finish()
Example #6
0
from .Logger import Logger

from .analyse.linecoverage import linecoverage

# The widgets used by the process bar
WIDGETS = [
    widgets.Percentage(),
    ' (',
    widgets.SimpleProgress(),
    ')',
    ' ',
    widgets.Bar("="),
    ' ',
    widgets.Timer(),
    ' ',
    widgets.ETA(),
]


class Macke:
    """
    Main container for all steps of the MACKE analysis
    """

    # static "constants"
    SYM_ONLY = 0
    FUZZ_ONLY = 1
    FLIPPER = 2

    def __init__(self,
                 bitcodefile,
Example #7
0
 else:
     shuffles = []
     indices = list(range(len(paired_results)))
     for iteration in range(num_tests):
         # Select randomly half of the results to shuffle
         to_shuffle = random.sample(indices, len(paired_results)/2)
         shuffled = [stats2 if i in to_shuffle else stats1
                         for i,(stats1,stats2) in enumerate(paired_results)]
         shuffles.append(shuffled)
     
 # Show a progress bar
 if not options.quiet:
     pbar = ProgressBar(widgets=["Shuffling: ", 
                                 widgets.Percentage(),
                                 " ", widgets.Bar(),
                                 ' ', widgets.ETA()], 
                             maxval=num_tests).start()
     # Don't update to often
     pb_update = max(1000, num_tests/100)
 
 # Do the shuffling
 f_matches = 0
 r_matches = 0
 p_matches = 0
 for iteration,shuffled in enumerate(shuffles):
     if not options.quiet and (iteration % pb_update) == 0:
         pbar.update(iteration)
     
     # Use the shuffled stats to compute an f-score for the pretend model
     recall, precision, fscore = _fscore(*zip(*shuffled))