blob: 196fe560ea48cc32d639f24ebb100738a304dd3c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
#!/usr/bin/env python3
import click
ticks = ["▁", "▂", "▃", "▄", "▅", "▆", "▇", "█"]
def histogram(sequence):
min_val = min(sequence)
max_val = max(sequence)
scale = (int(max_val - min_val) << 8) / (len(ticks) - 1)
if scale < 1:
scale = 1
return [ticks[int((int(i - min_val) << 8) / scale)] for i in sequence]
@click.command()
@click.argument("numbers", nargs=-1, type=float)
def cli(numbers):
h = histogram(numbers)
print("".join(h))
if __name__ == "__main__":
cli()
|