MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / RateColumn

Class RateColumn

pager_lib/tqdm/rich.py:46–69  ·  view source on GitHub ↗

Renders human readable transfer speed.

Source from the content-addressed store, hash-verified

44
45
46class RateColumn(ProgressColumn):
47 """Renders human readable transfer speed."""
48 def __init__(self, unit="", unit_scale=False, unit_divisor=1000):
49 self.unit = unit
50 self.unit_scale = unit_scale
51 self.unit_divisor = unit_divisor
52 super().__init__()
53
54 def render(self, task):
55 """Show data transfer speed."""
56 speed = task.speed
57 if speed is None:
58 return Text(f"? {self.unit}/s", style="progress.data.speed")
59 if self.unit_scale:
60 unit, suffix = filesize.pick_unit_and_suffix(
61 speed,
62 ["", "K", "M", "G", "T", "P", "E", "Z", "Y"],
63 self.unit_divisor,
64 )
65 else:
66 unit, suffix = filesize.pick_unit_and_suffix(speed, [""], 1)
67 precision = 0 if unit == 1 else 1
68 return Text(f"{speed/unit:,.{precision}f} {suffix}{self.unit}/s",
69 style="progress.data.speed")
70
71
72class tqdm_rich(std_tqdm): # pragma: no cover

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected