Add explanatory comments across codebase
This commit is contained in:
@@ -4,29 +4,37 @@
|
||||
"""Quality gate for meeting reports. uv run --script review.py <name> [<name>...]; exit 1 if any fails. No network/LLM."""
|
||||
import base64, json, re, struct, sys
|
||||
import db
|
||||
# Shared helpers from report.py: ticket regex, key normaliser, name similarity.
|
||||
from report import TICKET, _key, _sim
|
||||
from shots import CONTENT_KINDS
|
||||
|
||||
# Stopwords used by english() to tell English from Italian text.
|
||||
ENG = {"the", "and", "of", "with", "is", "shows", "showing", "screenshot", "meeting", "displays"}
|
||||
ITA = {"il", "la", "di", "che", "con", "della", "viene", "mostra", "sono", "per"}
|
||||
|
||||
|
||||
# True if text is mostly English: at least 3 English stopwords and more than Italian ones.
|
||||
def english(s):
|
||||
w = re.findall(r"[a-zà-ú]+", str(s).lower())
|
||||
e, i = sum(x in ENG for x in w), sum(x in ITA for x in w)
|
||||
return e >= 3 and e > i
|
||||
|
||||
|
||||
# Read image width from the JPEG SOF marker (0 if not found).
|
||||
def jpeg_w(p):
|
||||
b = p.read_bytes(); i = 2
|
||||
while i < len(b):
|
||||
# Skip non-marker bytes.
|
||||
if b[i] != 0xFF: i += 1; continue
|
||||
m = b[i + 1]
|
||||
# SOF0-SOF2: frame header holds height, then width (2 bytes each).
|
||||
if m in (0xC0, 0xC1, 0xC2): return struct.unpack(">H", b[i + 7:i + 9])[0]
|
||||
# Jump over this segment using its length field.
|
||||
i += 2 + struct.unpack(">H", b[i + 2:i + 4])[0]
|
||||
return 0
|
||||
|
||||
|
||||
# Run all quality rules on one meeting's outputs; print failures; True if none.
|
||||
def review(name):
|
||||
d = db.out_dir(name)
|
||||
rep = json.loads((d / "report.json").read_text(encoding="utf-8"))
|
||||
@@ -36,31 +44,41 @@ def review(name):
|
||||
docs = json.loads((d / "docs.json").read_text(encoding="utf-8")) if (d / "docs.json").exists() else None
|
||||
items = (docs or {}).get("items", [])
|
||||
fails = []
|
||||
# Record a failure with its rule code (R1-R12).
|
||||
F = lambda code, detail: fails.append(f"FAIL {code} {str(detail)[:200]}")
|
||||
|
||||
# R1: no generic 'Speaker N' labels left in the report.
|
||||
for m in re.finditer(r"\bSpeaker \d+\b", md): F("R1", md[max(0, m.start() - 40):m.end() + 40].replace("\n", " "))
|
||||
|
||||
# R2: topic count between dur/900 and dur/150 (min 3 / 4), so long calls get more topics.
|
||||
T, dur = rep["topics"], rep["duration_s"]
|
||||
if not max(3, dur / 900) <= len(T) <= max(4, dur / 150): F("R2", f"{len(T)} topics for {dur / 60:.0f} min")
|
||||
# R2: every topic except the last must span at least 2 min.
|
||||
for t in T[:-1]:
|
||||
if t["end_s"] - t["start_s"] < 120: F("R2", f"short topic {t['title']} {t['end_s'] - t['start_s']}s")
|
||||
for t in T:
|
||||
for x in t["shown"]:
|
||||
# R3: each shown timestamp must fall inside the topic span (+/-30 s).
|
||||
m = re.search(r"(\d\d):(\d\d)", x)
|
||||
if not m or not t["start_s"] - 30 <= int(m[1]) * 60 + int(m[2]) <= t["end_s"] + 30: F("R3", f"{t['title']}: {x}")
|
||||
|
||||
byfile = {}
|
||||
# Index shots by file name and by cropped view name, for R4.
|
||||
for s in shots: byfile[s["file"]] = byfile[s.get("view") or s["file"]] = s
|
||||
# R4: at most 2 images per section.
|
||||
for sec in re.split(r"\n(?=## )", md):
|
||||
imgs = re.findall(r"!\[[^\]]*\]\(shots/([^)]+)\)", sec)
|
||||
if len(imgs) > 2: F("R4", f">2 images in {sec[:40]!r}")
|
||||
# R4: every image used must be a content screen (CONTENT_KINDS).
|
||||
used = re.findall(r"!\[[^\]]*\]\(shots/([^)]+)\)", md)
|
||||
for f in used:
|
||||
if byfile.get(f, {}).get("kind") not in CONTENT_KINDS: F("R4", f"{f} kind {byfile.get(f, {}).get('kind')}")
|
||||
# R4: if cropping was applied, every image must be a cropped view_ file.
|
||||
if any((s.get("view") or "").startswith("view_") for s in shots):
|
||||
for f in used:
|
||||
if not f.startswith("view_"): F("R4", f"uncropped image {f}")
|
||||
|
||||
# R5: collect all prose fields to check for English.
|
||||
texts = list(rep["tldr"])
|
||||
for t in T:
|
||||
texts += [x["text"] if isinstance(x, dict) else x for x in t["summary"]] + [x["text"] for x in t.get("from_docs", [])]
|
||||
@@ -68,6 +86,7 @@ def review(name):
|
||||
for x in texts:
|
||||
if english(x): F("R5", x)
|
||||
|
||||
# R6: read the participants section (table rows or comma list).
|
||||
sec = re.search(r"## Partecipanti\n(.*?)(?=\n## )", md, re.S)
|
||||
people = []
|
||||
for l in (sec[1].splitlines() if sec else []):
|
||||
@@ -75,36 +94,48 @@ def review(name):
|
||||
c = l.split("|")[1].strip()
|
||||
if c not in ("Partecipante", "") and not c.startswith("-"): people.append(c)
|
||||
elif l.strip() and not l.startswith("*"): people += [x.strip() for x in l.split(",")]
|
||||
# R6: no initials or truncated names.
|
||||
for p in people:
|
||||
if re.fullmatch(r"[A-Z]{1,3}", p) or "..." in p or "…" in p: F("R6", f"initials/truncated {p}")
|
||||
# R6: no two participants that look like the same person (similarity >= 0.82).
|
||||
for i, a in enumerate(people):
|
||||
for b in people[i + 1:]:
|
||||
if _sim(a, b) >= 0.82: F("R6", f"{a} ~ {b}")
|
||||
|
||||
# R7: share segments must be >= 20 s and not split by a gap of <= 60 s.
|
||||
S = rep["shares"]
|
||||
for s in S:
|
||||
if s["end"] - s["start"] < 20: F("R7", f"short share {s}")
|
||||
for a, b in zip(S, S[1:]):
|
||||
if a["who"] == b["who"] and b["start"] - a["end"] <= 60: F("R7", f"mergeable {a['who']} {a['end']}->{b['start']}")
|
||||
|
||||
# R8: ticket keys from the report's Ticket section.
|
||||
rs = re.search(r"\*\*Ticket\*\*\n\n(.*?)(?=\n\n|\Z)", md, re.S)
|
||||
# R8: allowed keys: Jira-verified when docs ran, else keys from references.
|
||||
ok = ({x["key"] for x in items if x["source"] == "jira" and x.get("mentioned")} if docs is not None
|
||||
else {x["key"] for x in rep["references"]["tickets"]})
|
||||
for k in re.findall(r"\[([A-Z][A-Z0-9]+-\d+)\]", rs[1] if rs else ""):
|
||||
if k not in ok: F("R8", f"ticket {k}")
|
||||
# R8: no raw number or e-mail lists.
|
||||
if "Numeri a schermo" in md or "**Email**" in md: F("R8", "numbers/email lists present")
|
||||
|
||||
# R9: docs section must exist and citation links must point to fetched docs.
|
||||
if items:
|
||||
if "## Documentazione correlata" not in md: F("R9", "missing Documentazione correlata")
|
||||
urls = {x["url"] for x in items}
|
||||
# Citation icon links in the markdown.
|
||||
for u in re.findall(r"\[📄\]\(([^ )]+)", md):
|
||||
if u not in urls: F("R9", f"citation url not in docs {u}")
|
||||
|
||||
# R10: HTML must embed images, not reference shots/ paths.
|
||||
if 'src="shots/' in html: F("R10", "unembedded image")
|
||||
for b in re.findall(r"data:image/jpeg;base64,([A-Za-z0-9+/=]+)", html):
|
||||
# R10: an embedded image under 5000 bytes is a placeholder.
|
||||
if len(base64.b64decode(b)) <= 5000: F("R10", "tiny image")
|
||||
# R11: transcript must not be included in the report.
|
||||
if "## Trascrizione" in md: F("R11", "transcript present")
|
||||
for f in set(used):
|
||||
# R12: cropped views must be at least 600 px wide.
|
||||
if f.startswith("view_") and jpeg_w(d / "shots" / f) < 600: F("R12", f"{f} narrow {jpeg_w(d / 'shots' / f)}px")
|
||||
|
||||
print("\n".join(f"[{name}] {x}" for x in fails))
|
||||
|
||||
Reference in New Issue
Block a user