Files
QuantEngineByItz/tools/build_calibration_approval_list_v1.py
kjh2064 ee4d1fdab8 캘리브레이션 거버넌스 도구 + WBS-7.1/7.2 실증 격차 가시화
캘리브레이션 백로그 → 우선순위 → 검토리포트 → 승인목록 → 결정초안으로
이어지는 임계값 보정 거버넌스 파이프라인을 추가하고, 2026-06-21
비판적 리뷰에서 발견한 두 가지 stale-수치 문제를 도구 차원에서 해소한다.

- registry_health(): 190여 개 임계값의 source별(SPEC_DERIVED/EXPERT_PRIOR/
  PROVISIONAL/CALIBRATED) 분포를 매 실행마다 자동 집계 — 수동 grep 불필요
- live_t5_status(): T+5 적중률을 하드코딩(35.86 리터럴) 대신
  Temp/prediction_accuracy_harness_v2.json에서 항상 최신값으로 읽음
- spec/calibration_registry.yaml: SEMI_CLUSTER_CAP_RISK_OFF 중복 id로
  인한 조용한 무시 버그 수정(SEMI_CLUSTER_CAP_RISK_OFF_MWA로 분리)
- spec/27_bch_calibration_runbook.yaml: current_status_2026_06_21 블록
  신설(단일 진실원천), 기존 05-30 스냅샷은 "역사적, 현재로 인용 금지"로 명시
2026-06-21 20:07:32 +09:00

137 lines
5.0 KiB
Python

#!/usr/bin/env python3
"""
build_calibration_approval_list_v1.py
───────────────────────────────────────────────────────────────────────────────
calibration_review_report_v1.json을 읽어 PROVISIONAL 승격 승인 리스트를 만든다.
목적:
- source=PROVISIONAL 인 임계값을 별도 승인 대상 리스트로 분리
- reviewer가 바로 볼 수 있는 Markdown/JSON 산출물 생성
- PROVISIONAL 승격과 provisional review를 분리해 운영 책임을 명확화
출력:
Temp/calibration_approval_list_v1.json
Temp/calibration_approval_list_v1.md
사용법:
python tools/build_calibration_approval_list_v1.py
"""
from __future__ import annotations
import json
import sys
from datetime import datetime, timezone
from pathlib import Path
from typing import Any
ROOT = Path(__file__).resolve().parent.parent
REVIEW = ROOT / "Temp" / "calibration_review_report_v1.json"
OUT_JSON = ROOT / "Temp" / "calibration_approval_list_v1.json"
OUT_MD = ROOT / "Temp" / "calibration_approval_list_v1.md"
if sys.stdout.encoding and sys.stdout.encoding.lower() not in ("utf-8", "utf8"):
sys.stdout = open(sys.stdout.fileno(), mode="w", encoding="utf-8", buffering=1)
def _load_json(path: Path) -> dict[str, Any]:
if not path.exists():
return {}
try:
data = json.loads(path.read_text(encoding="utf-8"))
except Exception:
return {}
return data if isinstance(data, dict) else {}
def _table(rows: list[dict[str, Any]], keys: list[str], max_rows: int = 25) -> str:
if not rows:
return "_데이터 없음_"
header = "| " + " | ".join(keys) + " |"
sep = "| " + " | ".join(["---"] * len(keys)) + " |"
body = []
for row in rows[:max_rows]:
body.append("| " + " | ".join(str(row.get(k, "")).replace("|", "ㅣ") for k in keys) + " |")
suffix = f"\n\n_...총 {len(rows)}행 중 {max_rows}행 표시_" if len(rows) > max_rows else ""
return "\n".join([header, sep, *body]) + suffix
def main() -> int:
review = _load_json(REVIEW)
rows = review.get("review_rows") if isinstance(review.get("review_rows"), list) else []
approval_candidates: list[dict[str, Any]] = []
provisional_review_candidates: list[dict[str, Any]] = []
for row in rows:
if not isinstance(row, dict):
continue
source = str(row.get("source") or "")
readiness = str(row.get("readiness") or "")
sample_n = int(row.get("sample_n") or 0)
base = {
"id": row.get("id", ""),
"source": source,
"sample_n": sample_n,
"value": row.get("value"),
"unit": row.get("unit", ""),
"owner_formula": row.get("owner_formula", ""),
"readiness": readiness,
"reason": row.get("reason", ""),
}
if source == "PROVISIONAL":
approval_candidates.append(base)
elif readiness == "PROVISIONAL_CANDIDATE":
provisional_review_candidates.append(base)
approval_candidates.sort(key=lambda item: (-int(item.get("sample_n") or 0), str(item.get("id") or "")))
provisional_review_candidates.sort(key=lambda item: (-int(item.get("sample_n") or 0), str(item.get("id") or "")))
report = {
"formula_id": "CALIBRATION_APPROVAL_LIST_V1",
"generated_at": datetime.now(timezone.utc).isoformat(),
"review_report_path": str(REVIEW),
"approval_candidate_count": len(approval_candidates),
"provisional_review_candidate_count": len(provisional_review_candidates),
"approval_candidates": approval_candidates,
"provisional_review_candidates": provisional_review_candidates,
}
OUT_JSON.write_text(json.dumps(report, ensure_ascii=False, indent=2), encoding="utf-8")
md_lines = [
"# Calibration Approval List",
"",
"## Summary",
"",
f"- approval candidates: {len(approval_candidates)}",
f"- provisional review candidates: {len(provisional_review_candidates)}",
"",
"## Approval Candidates",
"",
_table(approval_candidates, ["id", "source", "sample_n", "value", "unit", "owner_formula", "readiness", "reason"]),
"",
"## Provisional Review Candidates",
"",
_table(provisional_review_candidates, ["id", "source", "sample_n", "value", "unit", "owner_formula", "readiness", "reason"]),
"",
"## Evidence",
"",
f"- review report: {REVIEW}",
]
OUT_MD.write_text("\n".join(md_lines), encoding="utf-8")
print(json.dumps({
"formula_id": report["formula_id"],
"gate": "PASS" if approval_candidates else "WARN",
"approval_candidate_count": len(approval_candidates),
"provisional_review_candidate_count": len(provisional_review_candidates),
"json_path": str(OUT_JSON),
"md_path": str(OUT_MD),
}, ensure_ascii=False, indent=2))
return 0
if __name__ == "__main__":
raise SystemExit(main())