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
async def show_progresses_offline(self): from progressbar import ProgressBar, widgets barformat_notfinalized = [ widgets.AnimatedMarker(), ' ', widgets.Counter(), ' ', widgets.BouncingBar(), ' ', widgets.Timer()] class LooseAdaptiveETA(widgets.AdaptiveETA): # Stabilize the ETA on results from large batches rushes in NUM_SAMPLES = 100 barformat_finalized = [ widgets.AnimatedMarker(), ' ', widgets.Percentage(), ' of ', widgets.FormatLabel('%(max)d'), ' ', widgets.Bar(), ' ', widgets.Timer('Elapsed: %s'), ' ', LooseAdaptiveETA()] self.pbar = ProgressBar(widgets=barformat_notfinalized) self.pbar.start() notfinalized = True while self.running: if notfinalized and self.scan_finished: notfinalized = False self.pbar = ProgressBar(maxval=self.reads_found, widgets=barformat_finalized) self.pbar.currval = self.reads_processed self.pbar.start() else: self.pbar.maxval = self.reads_found self.pbar.update(self.reads_processed) try: await asyncio.sleep(0.3) except CancelledError: break
def progressbar_count_widgets(pbar: ProgressBar): from progressbar import widgets if pbar.max_value: return [ widgets.Percentage(**pbar.widget_kwargs), ' ', widgets.SimpleProgress(format="({value:,} of {max_value:,})", new_style=True, **pbar.widget_kwargs), ' ', widgets.Bar(**pbar.widget_kwargs), ' ', widgets.Timer(**pbar.widget_kwargs), ] else: return [ widgets.AnimatedMarker(**pbar.widget_kwargs), ' ', widgets.BouncingBar(**pbar.widget_kwargs), ' ', widgets.Counter(**pbar.widget_kwargs), ' ', widgets.Timer(**pbar.widget_kwargs), ]
def __init__(self): self.status_label = pbwidgets.FormatLabel(status_string("")) self.pb = ProgressBar(1.0, widgets=[self.status_label, pbwidgets.Percentage(), ' ', pbwidgets.Bar(), pbwidgets.FormatLabel(" %(elapsed)s "), pbwidgets.AdaptiveETA(), ]) self.last_status = None self.pb.start()
def get_pbar(max_value): pbar = progressbar.ProgressBar(widgets=[ widgets.Percentage(), ' (', widgets.SimpleProgress(), ')', ' ', widgets.Bar(), ' ', widgets.Timer(), ' ', widgets.AdaptiveETA(), ' ', widgets.DynamicMessage('Accuracy') ], max_value=max_value) return pbar
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
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))
def DisplayProgressBar(self, ProcessingResults, ExpectedResultsSize, CheckInterval=1, type="minute"): ''' Display a progress bar for multiprocessing. This function should be used after pool.close(No need to use pool.join anymore). The call back function for pool.async should be set as CallbackForProgressBar. :param multiprocessing.pool.AsyncResult ProcessingResults: Processing results returned by pool.async. :param int ExpectedResultsSize: How many result you will reveive, i.e. the total length of progress bar. :param float CheckInterval: How many seconds will the progress bar be updated. When it's too large, the main program may hang there. :param String type: Three types: "minute", "hour", "second"; corresponds displaying iters/minute iters/hour and iters/second. ''' self.ProcessingResults = ProcessingResults ProgressBarWidgets = [ progressbar_widgets.Percentage(), ' ', progressbar_widgets.Bar(), ' ', progressbar_widgets.SimpleProgress(), ' ', progressbar_widgets.Timer(), ' ', progressbar_widgets.AdaptiveETA() ] self.ProgressBar = progressbar.ProgressBar(ExpectedResultsSize, ProgressBarWidgets) self.StartTime = time.time() PreviousNumberOfResults = 0 self.ProgressBar.start() while self.ProcessingResults.ready() == False: self.Update() time.sleep(CheckInterval) time.sleep(CheckInterval) self.Update() self.ProgressBar.finish() self.EndTime = time.time() print("Processing finished.") #print "Processing results: ", self.TotalResults print("Time Elapsed: %.2fs, or %.2fmins, or %.2fhours" % ((self.EndTime - self.StartTime), (self.EndTime - self.StartTime) / 60, (self.EndTime - self.StartTime) / 3600)) logger.info("Processing finished.") logger.info("Processing results: " + str(self.TotalResults)) logger.info("Time Elapsed: %.2fs, or %.2fmins, or %.2fhours" % ((self.EndTime - self.StartTime), (self.EndTime - self.StartTime) / 60, (self.EndTime - self.StartTime) / 3600)) return
def get_progressbar_widget_list(nepoch: int) -> BarWidgetsReturn: epoch_status_fmt_str: str = 'EPOCH: %(epoch_ix)d/%(nepoch)d' epoch_status = progressbar.FormatCustomText( epoch_status_fmt_str, dict(epoch_ix=0, nepoch=nepoch)) widgets_list: List[widgets.WidgetBase] = [ widgets.Percentage(), ' ', widgets.SimpleProgress(format='(%s)' % widgets.SimpleProgress.DEFAULT_FORMAT), ' ', epoch_status, ' ', widgets.Bar(), ' ', widgets.Timer(), ] return widgets_list, epoch_status
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), ]
def start(self, time_max): """ Start the simulation's progress bar Args: time_max (:obj:`float`): the simulation's end time """ if self.use: self.bar = ProgressBar(widgets=[ widgets.Percentage(), ' ', widgets.SimpleProgress( format='%(value)d/%(max_value)d (time_max)'), ' ', widgets.Bar(), ' ', widgets.Timer(), ' ', widgets.AdaptiveETA(), ], max_value=time_max).start()
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()
from .cgroups import get_cgroups from .Fuzzer import FuzzManager 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
parser.add_argument("-f", "--filter", default="_01.jpg", help="Filter applied to the list of files") parser.add_argument( "--img-shape", default=(128, 128, 1), type=lambda strin: tuple(int(val) for val in strin.split('x')), help= "Expected image shape in the form 'WxHxD', W=width, H=height, D=depth") args = vars(parser.parse_args()) # Progress bar widgets pbwidg = [ widgets.SimpleProgress(format=u'%(value_s)s/%(max_value_s)s'), ' ', widgets.Bar(marker=u'\u2588'), ' ', widgets.Timer(), ' ', widgets.AdaptiveETA() ] # Name the input arguments t_level = 0.3 in_abs_dir = os.path.abspath(args["in"]) out_abs_dir = os.path.abspath(args["out"]) img_shape = args["img_shape"] # Scan the directory to find the proper files _, thumbs_files = scan_dir(in_abs_dir, args["filter"]) num_classes = len(thumbs_files) print("Found", num_classes, "people") # Take the directory name as database name db_name = os.path.basename(in_abs_dir)
shuffles = _shuffle(paired_results) 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))