#!/usr/bin/env python3 """Counts of the status column of docs/experiments/step-ledger.md (offline tool, stdlib only): per status and per owner. ledger_counts.py [LEDGER.md] """ import collections import re import sys path = sys.argv[1] if len(sys.argv) > 1 else "docs/experiments/step-ledger.md" 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")))