Files
민헌andClaude Opus 5 50016ebd06 ③⑩ 단독측정 정본 반영 + 테스트데이터 지표별 명명 + ⑩ 실행기 경로 정리
③⑩ 을 09-10 단독측정으로 교체 (지표별 독립 실행기 negotiation.py, gpt-4o 1종 300건)
  ③ 5.877 → 5.784% · ⑩ 98.23 → 98.36% (253세션 1,086매칭)
  ①의 협상 기록 재집계 방식은 aggregate.py 보조 경로로 유지

run-eval.sh ⑩ 경로를 ③ 과 같은 단독측정으로 교체 (M10_REAGG=1 이면 옛 재집계)
eval/10_persona/aggregate.py
  - --out 추가 — 시험 실행이 정본 result.json·detail.jsonl 을 덮지 않게
  - 세션 대응 키를 기록의 session_id 우선으로 (EVAL-case_id 하드코딩 시
    EVAL10-* 기록이 ①의 옛 로그와 잘못 짝지어져 오답을 냈다. ① 기록은 폴백 동작 동일)

testdata 명명 규칙 <지표번호>_data_<이름>, 둘 이상이 쓰면 00_ (공용)
  testset_300 → 00_data_testset_300 · product_names → 00_data_product_names
  2_total_data → 02_data_total · 7_testset_10272 → 07_data_testset_10272
  8_items1000_master → 08_data_items1000_master
  생성기·룰(.py)은 번호 없음. 끝난 측정의 기록에는 옛 이름이 남아 있어
  testdata/README.md 에 옛↔새 대응표를 둔다

eval/SUMMARY.md 를 정본 수치와 일치시킴
③ 100건 파일럿 실행원본은 저장소 밖 _archive_20260910_실행원본/ 으로 이동

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-11 11:12:32 +09:00

86 lines
4.0 KiB
Python

#!/usr/bin/env python3
"""③ 평균 가격 협상률 — ① 측정 로그에서 독립 집계.
협상률 = (기존 공급가 − 최종 합의가) / 기존 공급가 × 100.
협상완료(합의) 건의 **단순 평균**(건별 비율의 평균). 목표 3%.
①의 detail_*.jsonl에 건별 reduction_pct가 남아 있어 LLM 재실행 없이 산출한다.
사용: python aggregate.py --source <① 실행 원본 폴더> (원본은 저장소 밖 NEGO_DOCS/_archive_20260909_실행원본/01_win_rate/ 에 보관)
python aggregate.py --source <폴더> --out /tmp/x 정본을 건드리지 않고 그 폴더에 산출
출력: (기본 이 스크립트 폴더 — --out 으로 옮길 수 있다)
data/reduction_all.csv 건별 원자료 (모델·기존공급가·합의가·협상률)
data/reduction_all_meta.json 출처·산식·모델별·분포
result.json 건수 + 평균 협상률 + PASS/FAIL
"""
import argparse
import csv
import json
import statistics
import sys
from pathlib import Path
HERE = Path(__file__).parent
DEFAULT_SOURCE = HERE.parent / "01_win_rate" / "본측정300_azure_20260901" # 저장소 밖으로 보관 이동 — --source 로 지정한다
FORMULA = "건별 가격 협상률 = (기존 공급가 − 최종 합의가) ÷ 기존 공급가 × 100, 협상완료 건의 단순 평균"
def main():
ap = argparse.ArgumentParser(description=__doc__.split("\n", 1)[0])
ap.add_argument("--source", type=Path, default=DEFAULT_SOURCE)
ap.add_argument("--target", type=float, default=3.0)
ap.add_argument("--out", type=Path, default=HERE,
help="산출 위치 (기본: 이 스크립트 폴더 = 정본). 시험 실행은 다른 경로를 준다")
args = ap.parse_args()
files = sorted(args.source.glob("detail_*.jsonl"))
if not files:
sys.exit(f"detail_*.jsonl 이 없습니다: {args.source}")
cases = [(f.stem[len("detail_"):].replace("_", "."), json.loads(line))
for f in files for line in f.open(encoding="utf-8")]
agreed = [(m, c) for m, c in cases if c.get("reduction_pct") is not None]
if not agreed:
sys.exit("합의(협상완료) 건이 없습니다")
reds = [c["reduction_pct"] for _, c in agreed]
avg = round(sum(reds) / len(reds), 3)
args.out.mkdir(parents=True, exist_ok=True)
out = args.out / "data"
out.mkdir(exist_ok=True)
with open(out / "reduction_all.csv", "w", encoding="utf-8-sig", newline="") as f:
w = csv.writer(f)
w.writerow(["모델", "case_id", "견적번호", "기존공급가", "최종합의가", "협상률_pct"])
for model, c in agreed:
w.writerow([model, c["case_id"], c.get("quotation_number"),
c["prev_price"], c["final_price"], c["reduction_pct"]])
by_model = {}
for model, c in agreed:
by_model.setdefault(model, []).append(c["reduction_pct"])
(out / "reduction_all_meta.json").write_text(json.dumps({
"출처": f"{args.source.name} — {len(files)}개 detail_*.jsonl, 전체 {len(cases)}건",
"산식": FORMULA,
"모델별": {m: {"합의건수": len(v), "avg_reduction_pct": round(sum(v) / len(v), 3)}
for m, v in by_model.items()},
"분포_pct": {"최소": min(reds), "중앙값": round(statistics.median(reds), 3),
"최대": max(reds), "표준편차": round(statistics.pstdev(reds), 3)},
}, ensure_ascii=False, indent=1), encoding="utf-8")
result = {
"전체 건수": len(cases),
"합의 건수": len(agreed),
"미합의 건수": len(cases) - len(agreed),
"평균가격협상률_pct": avg,
"산식": FORMULA,
"목표_pct": args.target,
"verdict": "PASS" if avg >= args.target else "FAIL",
"상세": "data/reduction_all_meta.json",
}
(args.out / "result.json").write_text(
json.dumps(result, ensure_ascii=False, indent=1), encoding="utf-8")
print(json.dumps(result, ensure_ascii=False, indent=1))
if __name__ == "__main__":
main()