From bbe94a112491761bf771e06b3c6304f50067c1f5 Mon Sep 17 00:00:00 2001 From: Midgard Date: Tue, 26 Jan 2021 12:40:07 +0100 Subject: [PATCH] Initial commit --- hist.py | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100755 hist.py diff --git a/hist.py b/hist.py new file mode 100755 index 0000000..2ac4595 --- /dev/null +++ b/hist.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python3 + +import sys +import re + +unknown = 0 +skipped = 0 +hours = [0] * 24 + +for line in sys.stdin: + m = re.match(r'([0-9]*):.*,([0-9])', line.strip()) + assert m + if m.group(2) == "0": + skipped += 1 + elif m.group(2) == "2": + unknown += 1 + else: + assert m.group(2) == "1" + hours[int(m.group(1))] += 1 + +BLOCKS = "▁▂▃▄▅▆▇█" +HEIGHT = 20 + +max_val = max([*hours, unknown, skipped]) + +hours_norm = [h / max_val for h in hours] +unknown_norm = unknown / max_val +skipped_norm = skipped / max_val + +def print_block(value, row): + height_value = value * HEIGHT - (HEIGHT - row) + if height_value >= 0.99: + print(BLOCKS[-1], end=" ") + elif height_value < 0.01: + if HEIGHT - 1 == row and value > 0: + print("⎯", end=" ") + else: + print(" ", end=" ") + else: + print(BLOCKS[int(height_value * len(BLOCKS))], end=" ") + +cutoff = 12 +hour_indices = [*range(cutoff, 24), *range(0, cutoff)] + +for row in range(HEIGHT): + print("", end=" ") + + for h in hour_indices: + print_block(hours_norm[h], row) + + print("", end=" ") + print_block(skipped_norm, row) + print("", end=" ") + print_block(unknown_norm, row) + print() + +for h in hour_indices[::2]: + print(f"{h: >2}", end=" ") +print(" skp unk")