From 10e7081f9bc94b06aed10666eb1f9f27ab6ca9f3 Mon Sep 17 00:00:00 2001 From: chthollyphile <30263107+chthollyphile@users.noreply.github.com> Date: Tue, 16 Apr 2024 07:30:40 +0800 Subject: [PATCH 1/2] Add new column object: IterationSpeedColumn --- rich/progress.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/rich/progress.py b/rich/progress.py index 8810aeac4..a393daeab 100644 --- a/rich/progress.py +++ b/rich/progress.py @@ -911,6 +911,25 @@ def render(self, task: "Task") -> Text: return Text(f"{data_speed}/s", style="progress.data.speed") +class IterationSpeedColumn(ProgressColumn): + """Renders iterations per second, e.g. '1.14 it/s'.""" + + def render(self, task: Task) -> Text: + last_speed = task.last_speed if hasattr(task, 'last_speed') else None + if task.finished and last_speed is not None: + return Text(f"{last_speed} it/s", style="progress.data.speed") + if task.speed is None: + return Text("", style="progress.data.speed") + unit, suffix = filesize.pick_unit_and_suffix( + int(task.speed), + ["", "×10³", "×10⁶", "×10⁹", "×10¹²"], + 1000, + ) + data_speed = task.speed / unit + task.last_speed = f"{data_speed:.1f}{suffix}" + return Text(f"{task.last_speed} it/s", style="progress.data.speed") + + class ProgressSample(NamedTuple): """Sample of progress for a given time.""" From 2dfe61f2c3c2b8f61c16e2d51849d733f00ded3f Mon Sep 17 00:00:00 2001 From: chthollyphile <30263107+chthollyphile@users.noreply.github.com> Date: Tue, 16 Apr 2024 12:40:43 +0800 Subject: [PATCH 2/2] fix typo --- rich/progress.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rich/progress.py b/rich/progress.py index a393daeab..e47debe21 100644 --- a/rich/progress.py +++ b/rich/progress.py @@ -912,7 +912,7 @@ def render(self, task: "Task") -> Text: class IterationSpeedColumn(ProgressColumn): - """Renders iterations per second, e.g. '1.14 it/s'.""" + """Renders iterations per second, e.g. '11.4 it/s'.""" def render(self, task: Task) -> Text: last_speed = task.last_speed if hasattr(task, 'last_speed') else None