Files

28 lines
1.1 KiB
Python

#!/usr/bin/env python3
"""Counts of the status column of the step ledger table (offline tool, stdlib only): per status and per owner.
ledger_counts.py [LEDGER.md]
"""
import collections
import re
import sys
if len(sys.argv) < 2:
sys.exit("usage: ledger_counts.py LEDGER.md (the ledger now lives in the LeaseVibe documentation, not in the repository)")
path = sys.argv[1]
by_status, by_owner = collections.Counter(), collections.Counter()
for line in open(path, encoding="utf-8"):
cells = [c.strip() for c in line.strip().strip("|").split("|")]
labelled = re.search(r"\(([A-Z]\d+[a-z]?)\)$", cells[0])
if len(cells) < 6 or not (labelled or re.fullmatch(r"[A-Z]\d+[a-z]?", cells[0])):
continue
status = cells[-1].split(" ")[0].split("(")[0]
by_status[status] += 1
by_owner[(cells[-2], status)] += 1
total = sum(by_status.values())
print("rows: %d" % total)
for s in ("open", "fixing", "fixed", "proved-equal"):
print(" %-13s %d" % (s, by_status[s]))
for o in sorted({k[0] for k in by_owner}):
print("owner %-10s " % o + ", ".join("%s %d" % (s, by_owner[(o, s)]) for s in ("open", "fixing", "fixed", "proved-equal")))