"""_요약.md 표에 키별 행을 추가(이미 있으면 교체)하고 처리 건수·DROP 검토 목록을 갱신한다. python3 sum_rows.py ROOT TOTAL KEY... [--drop "항목 문장"]... """ import json, re, sys from collections import Counter argv = sys.argv[1:] drops = [] while "--drop" in argv: i = argv.index("--drop"); drops.append(argv[i + 1]); del argv[i:i + 2] root, total, keys = argv[0], int(argv[1]), argv[2:] p = root + "/청구취지규칙문서_사건종류별_부록정리_기록/_요약.md" t = open(p, encoding="utf-8").read() lines = t.split("\n") for k in keys: L = json.load(open("%s/청구취지규칙문서_사건종류별_부록정리_기록/%s.json" % (root, k), encoding="utf-8")) assert all(L["checks"].values()), k c, a = L["chars"], Counter(d["action"] for d in L["decisions"]) row = "| %s | %s | %s | %s | %s | %d | %d | %d | %d |" % (k, format(c["raw_total"], ","), format(c["total"], ","), format(c["appendix_a"], ","), format(c["appendix_b"], ","), a["KEEP_SECTION"] + a["KEEP_UNSURE"], a["KEEP_ITEMS"], a["OMIT"], a["DROP"]) old = [i for i, l in enumerate(lines) if l.startswith("| %s |" % k)] if old: lines[old[0]] = row else: last = max(i for i, l in enumerate(lines[:lines.index("## 특수 처리 목록")]) if l.startswith("| ")) lines.insert(last + 1, row) t = "\n".join(lines) t = re.sub(r"^# 부록 정리 요약 — \d+종 처리분", "# 부록 정리 요약 — %d종 처리분" % total, t, flags=re.M) t = re.sub(r"판단 파일은 (`[^`]+`)\(\d+개\)이다", r"판단 파일은 \1(%d개)이다" % total, t) if drops: anchor = "\n\n### 해결책 반영" assert t.count(anchor) == 1 t = t.replace(anchor, "".join("\n- " + d for d in drops) + anchor, 1) open(p, "w", encoding="utf-8").write(t) print("ok", total, keys)