- results/ 를 없애고 지표별 eval/<NN_지표>/ 에 측정 코드·result.json·detail.jsonl·실행 원본·provenance.md 를 모음 (요약은 eval/SUMMARY.md) - 입력은 testdata/ 로 통일: 0_server_logs_frozen(동결본)·2_total_data(②)·8_items1000_master(⑧ 시험 데이터) - ⑧ 은 입력 8_items1000_master.xlsx 1개 + 검수 완료 items1000.xlsx 1개만 남김 (실행 원본·캐시·모집단은 저장소 밖 보관) - prism_core + capture_local → server/services/price_search (데모 API 와 측정 하네스가 같은 엔진 사용, sys.path 해킹 제거) - 엔진 의존성(selectolax·Pillow·openpyxl) server/requirements.txt 로 통합, docker-compose 는 eval·testdata 만 마운트 - prism_core 주석·독스트링 1~2줄로 축약 (AST 동일성 검증) - 데모 콘솔 최저가 검색 패널(PriceSearchPanel) 추가 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
99 lines
4.8 KiB
Python
99 lines
4.8 KiB
Python
#!/usr/bin/env python3
|
|
"""⑦ 협상 데이터 수집 — **협상 챗봇 계약 기록** 전수 집계.
|
|
|
|
계획서 평가방법 순번 7: "협상 챗봇으로 이루어진 계약 데이터화".
|
|
따라서 원천은 챗봇이 실제로 협상해 남긴 계약 로그 `server/data/contracts.jsonl` 이다
|
|
(엔진이 협상 합의 시 1줄씩 적는다 — server/config/config_models.py 의 `contracts_log`).
|
|
|
|
**원천 교체 (2026-09-08)**: 이전엔 `testdata/total_data.xlsx`(10,315행)를 써서
|
|
10,383건/년(PASS)을 냈으나, 그 파일은 챗봇 협상 기록이 아니라 견적 시스템 이력이었다
|
|
(견적번호 연도가 2015~2026 에 걸침, raw_data 와 겹침 8건뿐). 지표 정의와 맞지 않아 폐기했다.
|
|
|
|
**연환산에 대한 주의**: 산식 `건수 ÷ 기간 × 365` 는 원천이 **자연 운용 기간**에 걸쳐
|
|
쌓였을 때만 뜻이 있다. 평가용으로 몰아 실행한 로그(예: 300건/32분)에 그대로 쓰면
|
|
연 500만 건 같은 무의미한 값이 나온다. 그래서 이 집계기는 두 값을 함께 낸다:
|
|
· 누적_건수 — 지어낼 수 없는 사실
|
|
· 연환산_건 — 기간이 하루 이상일 때만 산출하고, 아니면 None 과 사유를 남긴다
|
|
어느 쪽을 성적서 판정값으로 쓸지는 측정 설계에서 정한다.
|
|
|
|
사용: python3 aggregate.py [--source ../../server/data/contracts.jsonl] [--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 / "server" / "data" / "contracts.jsonl"
|
|
BASELINE = "계획서 성능지표표 기준선 — 2023년 운용 협상 데이터 9,407건 (KTC)"
|
|
# 연환산을 낼 최소 관측 기간. 이보다 짧으면 '수집 속도'를 잰 것이지 '연간 수집량'이 아니다.
|
|
MIN_SPAN_DAYS = 1.0
|
|
|
|
|
|
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)
|
|
args = ap.parse_args()
|
|
if not args.source.is_file():
|
|
sys.exit(f"원천 파일이 없습니다: {args.source}\n"
|
|
f" 협상 챗봇을 실행해 계약 로그가 쌓여야 집계할 수 있습니다.")
|
|
|
|
rows = [json.loads(x) for x in args.source.read_text(encoding="utf-8").splitlines() if x.strip()]
|
|
if not rows:
|
|
sys.exit(f"계약 기록이 비어 있습니다: {args.source}")
|
|
|
|
ts = sorted(datetime.fromisoformat(r["ts"]) for r in rows if r.get("ts"))
|
|
span_days = (ts[-1] - ts[0]).total_seconds() / 86400 if len(ts) > 1 else 0.0
|
|
|
|
# 세션 접두로 실사용/평가용을 가른다 — EVAL-* 는 지표 ① 본측정이 남긴 부산물이다.
|
|
prefixes = Counter(str(r.get("session_id", "")).split("-")[0] for r in rows)
|
|
by_day = Counter(t.date().isoformat() for t in ts)
|
|
|
|
annual, note = None, None
|
|
if span_days >= MIN_SPAN_DAYS:
|
|
annual = round(len(rows) / span_days * 365)
|
|
else:
|
|
note = (f"관측 기간이 {span_days:.3f}일로 {MIN_SPAN_DAYS}일 미만이라 연환산하지 않는다 — "
|
|
f"몰아서 실행한 로그에 연환산을 적용하면 무의미한 값이 나온다")
|
|
|
|
meta = {
|
|
"출처": f"{args.source.name} — 협상 챗봇 계약 로그 {len(rows)}건",
|
|
"정의": "협상 1건 = 챗봇이 협상해 합의에 이른 계약 기록 1줄",
|
|
"기준선": BASELINE,
|
|
"관측시작": ts[0].isoformat() if ts else None,
|
|
"관측종료": ts[-1].isoformat() if ts else None,
|
|
"관측기간_일": round(span_days, 4),
|
|
"세션접두_분포": dict(prefixes),
|
|
"일자별_건수": dict(sorted(by_day.items())),
|
|
"산식": "연환산 = 누적 건수 ÷ 관측 기간(일) × 365",
|
|
"연환산_보류사유": note,
|
|
"목표_건년": args.target,
|
|
}
|
|
out = HERE / "data"
|
|
out.mkdir(exist_ok=True)
|
|
(out / "data_count_meta.json").write_text(
|
|
json.dumps(meta, ensure_ascii=False, indent=1), encoding="utf-8")
|
|
|
|
result = {
|
|
"누적_건수": len(rows),
|
|
"관측기간_일": round(span_days, 4),
|
|
"연환산_건": annual,
|
|
"목표_건년": args.target,
|
|
"verdict": ("PASS" if annual >= args.target else "FAIL") if annual is not None else "미판정",
|
|
"비고": note,
|
|
"상세": "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()
|