MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / bar_chart

Function bar_chart

crates/bench/hyper_cmp.py:30–55  ·  view source on GitHub ↗
(data: list)

Source from the content-addressed store, hash-verified

28
29
30def bar_chart(data: list):
31 max_value = max(count for _, count in data.items())
32 increment = max_value / 25
33
34 longest_label_length = max(len(label) for label, _ in data.items())
35
36 for label, count in data.items():
37
38 # The ASCII block elements come in chunks of 8, so we work out how
39 # many fractions of 8 we need.
40 # https://en.wikipedia.org/wiki/Block_Elements
41 bar_chunks, remainder = divmod(int(count * 8 / increment), 8)
42
43 # First draw the full width chunks
44 bar = '█' * bar_chunks
45
46 # Then add the fractional part. The Unicode code points for
47 # block elements are (8/8), (7/8), (6/8), ... , so we need to
48 # work backwards.
49 if remainder > 0:
50 bar += chr(ord('█') + (8 - remainder))
51
52 # If the bar is empty, add a left one-eighth block
53 bar = bar or '▏'
54
55 print(f'{label.rjust(longest_label_length)} ▏ {count:#4f} {bar}')
56
57
58class Report:

Callers 1

print_mkdownFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…