diff --git a/atpbar/main.py b/atpbar/main.py index 8d06900..e6dc2a1 100644 --- a/atpbar/main.py +++ b/atpbar/main.py @@ -1,6 +1,5 @@ import contextlib import logging -import time import uuid from collections.abc import Iterable, Iterator from typing import Generic, Optional, TypeVar @@ -11,12 +10,7 @@ T = TypeVar('T') -def atpbar( - iterable: Iterable[T], - /, - name: Optional[str] = None, - time_track: Optional[bool] = False, -) -> Iterable[T]: +def atpbar(iterable: Iterable[T], /, name: Optional[str] = None) -> Iterable[T]: """returns an instance of `Atpbar` Parameters @@ -44,7 +38,7 @@ def atpbar( if name is None: name = repr(iterable) - return Atpbar(iterable, name=name, len_=len_, time_track=time_track) + return Atpbar(iterable, name=name, len_=len_) class Atpbar(Generic[T]): @@ -65,18 +59,11 @@ class Atpbar(Generic[T]): """ - def __init__( - self, - iterable: Iterable[T], - name: str, - len_: int, - time_track: Optional[bool] = False, - ): + def __init__(self, iterable: Iterable[T], name: str, len_: int): self.iterable = iterable self.name = name self.len_ = len_ self.id_ = uuid.uuid4() - self.time_track = time_track def __iter__(self) -> Iterator[T]: with fetch_reporter() as reporter: @@ -95,8 +82,6 @@ def _report_start(self) -> None: return try: report = Report(taskid=self.id_, name=self.name, done=0, total=self.len_) - if self.time_track: - report["start_time"] = time.time() self.reporter.report(report) except BaseException: pass diff --git a/atpbar/presentation/barjupyter.py b/atpbar/presentation/barjupyter.py index 476ca68..4c9e2e8 100755 --- a/atpbar/presentation/barjupyter.py +++ b/atpbar/presentation/barjupyter.py @@ -88,24 +88,9 @@ def _update_widget(self, report: Report) -> None: bar = (":" * int(percent * 40)).ljust(40, " ") percent = round(percent * 100, 2) name = report["name"][0:name_field_length] - if "start_time" in report.keys(): - elapsed_str, remaining_str = self._get_time_track( - report["start_time"], percent - ) - label.value = ( - "
 | {:8d} / {:8d}  ({:s} / {:s}) |: {:<{}s}
".format( - report["done"], - report["total"], - elapsed_str, - remaining_str, - name, - name_field_length, - ) - ) - else: - label.value = "
 | {:8d} / {:8d} |: {:<{}s}
".format( - report["done"], report["total"], name, name_field_length - ) + label.value = "
 | {:8d} / {:8d} |: {:<{}s}
".format( + report["done"], report["total"], name, name_field_length + ) def _reorder_widgets(self, report: Report) -> None: for taskid in self._finishing_taskids: diff --git a/atpbar/presentation/bartty.py b/atpbar/presentation/bartty.py index 466388d..5b0bdfd 100755 --- a/atpbar/presentation/bartty.py +++ b/atpbar/presentation/bartty.py @@ -87,12 +87,6 @@ def _compose_bar_from_report(self, report: Report) -> str: format = " {percent:6.2f}% {bar:s} | {done:8d} / {total:8d} |: {name} " - if "start_time" in report.keys(): - elapsed_str, remaining_str = self._get_time_track( - report["start_time"], percent - ) - format += " | [{:s} / {:s}]".format(elapsed_str, remaining_str) - ret = format.format( percent=percent, bar=bar, diff --git a/atpbar/presentation/base.py b/atpbar/presentation/base.py index 343bf7a..cdd348a 100755 --- a/atpbar/presentation/base.py +++ b/atpbar/presentation/base.py @@ -107,27 +107,6 @@ def _need_to_present(self) -> bool: return False - def _get_time_track(self, start_time, percent): - """Format seconds as hours, minutes and seconds.""" - time_elapsed = time.time() - start_time - time_remaining = ( - (time_elapsed * (100 / percent)) - time_elapsed if percent > 0 else 0 - ) - - return self._time_to_str(time_elapsed), self._time_to_str(time_remaining) - - def _time_to_str(self, t): - mins = t // 60 - s = int(t % 60) - - h = int(mins // 60) - m = int(mins % 60) - - if h: - return "{0:d}:{1:02d}:{2:02d}".format(h, m, s) - else: - return "{0:02d}:{1:02d}".format(m, s) - def stdout_write(self, s: str) -> None: with self.lock: self._stdout_write(s) diff --git a/tests/presentation/test_presentation.py b/tests/presentation/test_presentation.py index 7e15a62..46f1e1d 100644 --- a/tests/presentation/test_presentation.py +++ b/tests/presentation/test_presentation.py @@ -1,5 +1,3 @@ -import time - import pytest has_jupyter_notebook = False @@ -48,7 +46,6 @@ def test_presentation(Class): @pytest.mark.parametrize("Class", classes, ids=classe_ids) def test_time_track(Class): - start_time = time.time() obj = Class() repr(obj) obj.active() @@ -60,7 +57,6 @@ def test_time_track(Class): taskid=1, first=True, last=False, - start_time=start_time, ) ) obj.present( @@ -71,7 +67,6 @@ def test_time_track(Class): taskid=1, first=False, last=False, - start_time=start_time, ) ) obj.present( @@ -82,7 +77,6 @@ def test_time_track(Class): taskid=1, first=False, last=True, - start_time=start_time, ) ) obj.active()