Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions progress_logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
class ProgressLogger:
"""A utility class to log output dynamically with a progress bar."""

def __init__(self, total_steps: int, prefix: str = "Progress:") -> None:
"""
Initialize the ProgressLogger instance.

:param total_steps: The total number of steps to track.
:param prefix: The prefix message to display before the progress bar.
"""
self.total_steps = total_steps
self.prefix = prefix
self.current_step = 0

def __str__(self) -> str:
"""
Return the progress bar as a string representation.

:return: The progress bar string.
"""
progress = int(self.current_step / self.total_steps * 50)
return (
f"{self.prefix} [{'>' * progress + '.' * (50 - progress)}] "
f"{self.current_step}/{self.total_steps}"
)

def update_progress(self, step: int) -> None:
"""
Update the progress bar and print the new status.

:param step: The current step to update.
"""
self.current_step = step
print(self, end="\r")

# Example usage:

def function_from_issue_12873():
progress_logger = ProgressLogger(100)
for i in range(100):
# Some long-running task...
progress_logger.update_progress(i + 1)

def function_from_issue_12836():
progress_logger = ProgressLogger(500)
for i in range(500):
# Some long-running task...
progress_logger.update_progress(i + 1)

def function_from_issue_12785():
progress_logger = ProgressLogger(1000)
for i in range(1000):
# Some long-running task...
progress_logger.update_progress(i + 1)

def function_from_issue_12723():
progress_logger = ProgressLogger(5000)
for i in range(5000):
# Some long-running task...
progress_logger.update_progress(i + 1)

def function_from_issue_12654():
progress_logger = ProgressLogger(10000)
for i in range(10000):
# Some long-running task...
progress_logger.update_progress(i + 1)