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

Class FractionColumn

pager_lib/tqdm/rich.py:21–43  ·  view source on GitHub ↗

Renders completed/total, e.g. '0.5/2.3 G'.

Source from the content-addressed store, hash-verified

19
20
21class FractionColumn(ProgressColumn):
22 """Renders completed/total, e.g. '0.5/2.3 G'."""
23 def __init__(self, unit_scale=False, unit_divisor=1000):
24 self.unit_scale = unit_scale
25 self.unit_divisor = unit_divisor
26 super().__init__()
27
28 def render(self, task):
29 """Calculate common unit for completed and total."""
30 completed = int(task.completed)
31 total = int(task.total)
32 if self.unit_scale:
33 unit, suffix = filesize.pick_unit_and_suffix(
34 total,
35 ["", "K", "M", "G", "T", "P", "E", "Z", "Y"],
36 self.unit_divisor,
37 )
38 else:
39 unit, suffix = filesize.pick_unit_and_suffix(total, [""], 1)
40 precision = 0 if unit == 1 else 1
41 return Text(
42 f"{completed/unit:,.{precision}f}/{total/unit:,.{precision}f} {suffix}",
43 style="progress.download")
44
45
46class RateColumn(ProgressColumn):

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected