aboutsummaryrefslogtreecommitdiff
path: root/tools/seqstat/seqstat.py
diff options
context:
space:
mode:
authorFranck Cuny <franck@fcuny.net>2022-10-15 12:32:28 -0700
committerFranck Cuny <franck@fcuny.net>2022-10-15 12:32:28 -0700
commitce39b5fd65a91e241b2edbb9fd6a9a12967a064d (patch)
treebd0ec3519ac3a41c55193023dc3f3bb2705114a1 /tools/seqstat/seqstat.py
parentci: update the flake once a week (diff)
downloadinfra-ce39b5fd65a91e241b2edbb9fd6a9a12967a064d.tar.gz
ref(seqstat): rewrite from go to python
This is a simple script, there's no benefit in having this in go. Having it Python makes it easier to extend with panda or other libraries in the future if I need more statistics too.
Diffstat (limited to 'tools/seqstat/seqstat.py')
-rwxr-xr-xtools/seqstat/seqstat.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/tools/seqstat/seqstat.py b/tools/seqstat/seqstat.py
new file mode 100755
index 0000000..8450ec8
--- /dev/null
+++ b/tools/seqstat/seqstat.py
@@ -0,0 +1,26 @@
+#!/usr/bin/env python3
+
+import argparse
+
+ticks = ["▁", "▂", "▃", "▄", "▅", "▆", "▇", "█"]
+
+parser = argparse.ArgumentParser()
+parser.add_argument(
+ "numbers", metavar="N", type=float, nargs="+", help="a number for the accumulator"
+)
+args = parser.parse_args()
+
+
+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]
+
+
+h = histogram(args.numbers)
+print("".join(h))