Files
Negotiation_daegu/eval/07_data_count/aggregate.py
T
민헌andClaude Opus 5 def79af03c ⑦ result.json을 측정값 3개만 남기고 정리
산식·목표·판정·상세 포인터를 meta로 옮김. 값 변화 없음 (10,383건/년 PASS).

- result.json: 협상 건수 / 측정기간_일 / 연환산_건
- data_count_meta.json: 기존 항목 + 산식·목표_건년·verdict
- 07 provenance에 두 파일의 역할 분담 명시

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

82 lines
3.3 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 건수 + 기간 + 연환산
"""
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}),
"산식": "누적 건수 ÷ 측정 기간(일) × 365 (협상 레코드 1행 = 1건)",
"목표_건년": args.target,
"verdict": "PASS" if yearly and yearly >= args.target else "FAIL",
"기준선": BASELINE,
}, ensure_ascii=False, indent=1), encoding="utf-8")
result = {
"협상 건수": len(rows),
"측정기간_일": days,
"연환산_건": yearly,
}
(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()