Files

29 lines
1.3 KiB
Python

"""From an output of perlabel.py: per family, labels, labels found (at least one instant, or a hole), events flagged, events
wholly wrong (no instant in a label of its family).
Usage: python3 table.py <perlabel output>
"""
import re
import sys
lab, found, flag, wrong = {}, {}, {}, {}
part = None
for line in open(sys.argv[1], encoding="utf-8"):
if line.startswith("== "):
part = line.strip()[3:]
continue
if part == "labels":
m = re.match(r"\S+\s+\S+ → \S+ (.+?)\s+found (\d+)/(\d+)", line)
fam, f, n = m.group(1).strip(), int(m.group(2)), int(m.group(3))
if n == 0 and "others: {}" in line and fam != "No data":
continue # no instant on the range (a label starting at its very end)
lab[fam] = lab.get(fam, 0) + 1
found[fam] = found.get(fam, 0) + (f > 0 or n == 0)
elif part == "events":
m = re.match(r"\S+ → \S+ (.+?)\s{2,}.*?(\d+) instants, wrong\s+(\d+)", line)
fam = m.group(1).strip()
flag[fam] = flag.get(fam, 0) + 1
wrong[fam] = wrong.get(fam, 0) + (m.group(2) == m.group(3))
print("| Family | labelled | found | flagged | wrongly |\n|---|---|---|---|---|")
for k in sorted(set(lab) | set(flag)):
print(f"| {k} | {lab.get(k, 0)} | {found.get(k, 0)} | {flag.get(k, 0)} | {wrong.get(k, 0)} |")