Files
Negotiation_daegu/eval/07_data_count/aggregate.py
T
민헌andClaude Opus 5 926a20fdc2 ⑦ 협상 데이터 수집 — 운용 실데이터 xlsx 기준으로 재작성
집계 근거를 데모 엔진 로그(contracts.jsonl)에서 운용 실데이터로 교체.
계획서 성능지표표의 목표 10,000건/년은 2023년 운용 실적 9,407건을 기준선으로
산정된 값이므로, 같은 단위(협상 레코드 1행 = 1건)로 집계해야 비교가 성립한다.

- testdata/synthetic_quotes_10000.xlsx → total_data.xlsx 로 개명.
  파일명·커밋 49bcbb1의 "합성 견적 데이터" 표기는 잘못된 것으로, 내용은
  재전달받은 운용 실데이터(2025-06~2026-06, 10,315행)임을 확인
- aggregate.py 재작성: xlsx 전수 집계, 협상종료시간 기준 기간 산출,
  수집량 = 누적 건수 ÷ 기간(일) × 365
- 결과 10,315건 / 362.62일 → 연환산 10,383건/년 PASS (기준선 9,407건 대비 +10.4%)
- meta에 월별 건수·협상상태 분포(완료 7,226 / 거부 3,089)·고유 견적 2,156 기록

개인정보 점검: 협력사명 91종 전부 마스킹, 이메일·전화·사업자번호 0건.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014sLpiFCT7Lj78iLwPbVx7a
2026-09-07 13:50:26 +09:00

83 lines
3.4 KiB
Python

#!/usr/bin/env python3
"""⑦ 협상 데이터 수집 — 협상 레코드 xlsx 전수 집계.
협상 1건 = 협상 레코드 1행(견적 1건 × 협력사 1곳).
수집량 = 누적 건수 ÷ 측정 기간(일) × 365. 목표 10,000건/년.
계획서 목표 산정 근거는 2023년 운용 실적 9,407건으로, 같은 단위(레코드 1행 = 1건)다.
사용: python aggregate.py [--source ../../testdata/total_data.xlsx] [--target 10000]
출력: data/data_count_meta.json 출처·기간·월별 건수·상태 분포
result.json 건수 + 연환산 + PASS/FAIL
"""
import argparse
import json
import sys
from collections import Counter
from datetime import datetime
from pathlib import Path
HERE = Path(__file__).parent
REPO = HERE.parents[1]
DEFAULT_SOURCE = REPO / "testdata" / "total_data.xlsx"
DATE_COL = "협상종료시간"
NEEDED = ["견적번호", "협상상태", DATE_COL]
BASELINE = "계획서 성능지표표 기준선 — 2023년 운용 협상 데이터 9,407건 (동일 단위)"
def as_dt(v):
return v if isinstance(v, datetime) else datetime.strptime(str(v)[:16], "%Y-%m-%d %H:%M")
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=10000.0, help="목표 건/년")
args = ap.parse_args()
if not args.source.is_file():
sys.exit(f"원천 파일이 없습니다: {args.source}")
import openpyxl
wb = openpyxl.load_workbook(args.source, read_only=True)
sheet = wb.sheetnames[0]
it = wb[sheet].iter_rows(values_only=True)
idx = {h: i for i, h in enumerate(next(it)) if h is not None}
if missing := [c for c in NEEDED if c not in idx]:
sys.exit(f"필수 컬럼 누락: {missing}")
rows = [r for r in it if r[idx["견적번호"]] and r[idx[DATE_COL]]]
if not rows:
sys.exit("집계할 레코드가 없습니다")
dates = sorted(as_dt(r[idx[DATE_COL]]) for r in rows)
days = round((dates[-1] - dates[0]).total_seconds() / 86400, 2)
yearly = round(len(rows) / days * 365) if days else None
out = HERE / "data"
out.mkdir(exist_ok=True)
(out / "data_count_meta.json").write_text(json.dumps({
"출처": f"{args.source.name} ({sheet}) — {len(rows)}행",
"기간기준컬럼": DATE_COL,
"기간": {"최초": dates[0].isoformat(sep=" "), "최종": dates[-1].isoformat(sep=" "),
"일수": days},
"월별_건수": dict(sorted(Counter(d.strftime("%Y-%m") for d in dates).items())),
"협상상태": dict(Counter(r[idx["협상상태"]] for r in rows)),
"고유_견적번호": len({r[idx["견적번호"]] for r in rows}),
"기준선": BASELINE,
}, ensure_ascii=False, indent=1), encoding="utf-8")
result = {
"협상 건수": len(rows),
"측정기간_일": days,
"연환산_건": yearly,
"산식": "누적 건수 ÷ 측정 기간(일) × 365 (협상 레코드 1행 = 1건)",
"목표_건년": args.target,
"verdict": "PASS" if yearly and yearly >= args.target else "FAIL",
"상세": "data/data_count_meta.json",
}
(HERE / "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()