Skip to main content
Version: 0.5.x

ProgressBar

Display a console progress bar to track an algorithm's progress.

This class builds a progress bar in the format {description}{bar*slots}{suffix} and, when calling the finish method, print the final progress bar along with the total time elapsed since the class was instance.

Module: aisp.utils.display
Import: from aisp.utils.display import ProgressBar


Constructor Parameters

NameTypeDefaultDescription
totalint-Total number of iterations.
suffixstr''Optional text displayed after the progress bar.
descriptionstr''Optional text displayed before the progress bar.
slotsint10Number of character slots used to represent the bar.
verboseboolTrueIf False, prints nothing to the terminal.

Raises

ExceptionDescription
ValueErrorIf the total or slots is less than or equal to zero.

Public Methods

set_description

def set_description(self, description: str) -> None:
...

Update the description before the progress bar.

Parameters

NameTypeDefaultDescription
descriptionstr-New description.

update

def update(self, increment: int = 1) -> None:
...

Increment the progress bar.

Parameters

NameTypeDefaultDescription
incrementint1Number of completed iterations to add to the current progress.

Raises

ExceptionDescription
ValueErrorIf the increment is negative.

finish

def finish(self) -> None:
...

End the progress display and print the total elapsed time.