refactor: 아웃바운드 메일·보고서·소개서의 병원 목록·소개서 버전·실측일을 인자와 실측 데이터로 받는다
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1e41bc218c
commit
d64a19ae9f
4 files changed
+60
-25
No files matched your search
@@ -2,7 +2,7 @@
|
||||
haewon이 확정한 소개서(그랜드 v13)를 틀로 삼아 다른 병원 소개서를 만든다.
|
||||
|
||||
- 틀의 레이아웃·글꼴·문구는 그대로 두고 병원별로 달라지는 곳만 바꾼다
|
||||
1 표지 병원명 · 2 출처 분석 건수·자주 인용된 플랫폼 · 4 핵심 발견 · 5 보고서 제목 · 6 요약 제목 · 9·10 답변 장 제목
|
||||
1 표지 병원명·실측일 · 2 출처 분석 건수·자주 인용된 플랫폼 · 4 핵심 발견 · 5 보고서 제목 · 6 요약 제목 · 9·10 답변 장 제목
|
||||
- 보고서 장(5~12) 본문은 report_native 로 이 병원 실측값을 다시 그린다
|
||||
- 저장 전에 틀 병원의 이름·시술·질문이 남아 있지 않은지 검사한다
|
||||
|
||||
@@ -55,6 +55,7 @@ def main(template, out, name):
|
||||
|
||||
# 1 표지
|
||||
set_runs(shape(s[0], "TextBox 6"), [name])
|
||||
set_runs(shape(s[0], "TextBox 7"), [f"측정 {d['measured']}"])
|
||||
# 2 Why Now: OPEN WEB 카드 하단 라벨
|
||||
set_runs(shape(s[1], "TextBox 47"), [f"답변 {d['total']}건 출처 분석"])
|
||||
# OPEN WEB 카드 첫 줄: 이 병원 답변에서 많이 인용된 플랫폼 2곳 (강남구청은 다음 줄 '구청·의료관광·후기'에 있음)
|
||||
|
||||
@@ -243,6 +243,22 @@ def judged_runs(clinic, qid, engine):
|
||||
return out
|
||||
|
||||
|
||||
def measured_dates(clinic, plan):
|
||||
"""이 병원 질문 답변의 실측일. (표지용 '2026. 10. 19 · 10. 26', 방법 행용 기간 '2026-10-19 ~ 2026-10-26')
|
||||
엔진마다 측정일이 다르고 공통 질문은 앞선 답변을 다시 쓰므로 회차별 날짜 대신 기간으로 쓴다 (haewon 2026-10-27)"""
|
||||
days = set()
|
||||
for rep in REPS:
|
||||
got = {r["measured_at"][:10] for e, _ in ENGINES for qid in plan[clinic["name"]].values()
|
||||
if (r := probe.load_done(e, rep).get(qid)) and r.get("measured_at")}
|
||||
assert got, f"실측 없음: {clinic['name']} {rep}회차"
|
||||
days |= got
|
||||
days = sorted(days)
|
||||
period = days[0] if len(days) == 1 else f"{days[0]} ~ {days[-1]}"
|
||||
label = [days[0].replace("-", ". ")]
|
||||
label += [d[5:].replace("-", ". ") if d[:4] == days[0][:4] else d.replace("-", ". ") for d in days[1:]]
|
||||
return " · ".join(label), period
|
||||
|
||||
|
||||
MONO = {"openai": "GPT", "claude": "CL", "perplexity": "PX", "google_ai_overview": "GO"}
|
||||
|
||||
|
||||
@@ -451,7 +467,7 @@ def report_data(clinic, plan):
|
||||
sc = SITE_CHECKS[name]
|
||||
return {"name": name, "proc": clinic["procedure_ko"], "brand": tally(["kr:Q1", "en:Q1"]), "kr": tally(nb("kr")),
|
||||
"en": tally(nb("en")), "total": total, "own_src": own_src, "src": src, "q2_valid": kf["valid"], "kf": kf,
|
||||
"questions": questions, "quotes": quotes, "site": sc["items"],
|
||||
"questions": questions, "quotes": quotes, "site": sc["items"], "measured": measured_dates(clinic, plan)[0],
|
||||
"site_ok": sum(1 for _, ok, _ in sc["items"] if ok)}
|
||||
|
||||
|
||||
@@ -473,6 +489,7 @@ def render(clinic, plan, assets):
|
||||
bh, bv = tally(["kr:Q1", "en:Q1"])
|
||||
kh, kv = tally(nb("kr"))
|
||||
eh, ev = tally(nb("en"))
|
||||
measured, period = measured_dates(clinic, plan)
|
||||
total, own_src, src = v3.sources(clinic, plan)
|
||||
kf = key_finding(clinic, plan, runs)
|
||||
q2_v = kf["valid"]
|
||||
@@ -544,7 +561,7 @@ def render(clinic, plan, assets):
|
||||
("Claude", "Anthropic API · claude-sonnet-5-5 · 웹 검색 켬 · 위치 서울(한국어) / 뉴욕(영어)"),
|
||||
("Perplexity", "Perplexity API · sonar · 자체 웹 검색"),
|
||||
("Google AI 개요", "Google 검색 결과의 AI 개요 · 국가 설정 한국 / 미국"),
|
||||
("회차", "1회차 2026-10-19, 2·3회차 2026-10-26. 질문 원문을 그대로 사용하고 회차마다 새로 질의"),
|
||||
("회차", f"{period} 측정, 질문마다 3회. 질문 원문을 그대로 사용하고 회차마다 새로 질의"),
|
||||
("판정", "답변 속 병원명을 추출해 원문과 대조. 병원명이 수집되지 않은 Google 답변은 분모에서 제외"),
|
||||
("점검 페이지", " · ".join(sc["pages"])),
|
||||
("한계", "AI 답변은 시점과 맥락에 따라 달라질 수 있습니다. 본 보고서는 질문 10개를 표본으로 한 진단이며, "
|
||||
@@ -562,7 +579,7 @@ def render(clinic, plan, assets):
|
||||
<div class="cover-grid"><div>
|
||||
<div class="eyebrow">AI Answer Check · 맞춤 진단 보고서</div>
|
||||
<div class="cover-name">{name}</div>
|
||||
<div class="cover-meta">AI 답변 진단 보고서 · 측정 2026. 10. 19 · 10. 26 · 발행 {ISSUED}</div>
|
||||
<div class="cover-meta">AI 답변 진단 보고서 · 측정 {measured} · 발행 {ISSUED}</div>
|
||||
</div><div class="stat-col">
|
||||
<div class="stat"><b>10</b><span>환자 질문 (한국어 5 · 영어 5)</span></div>
|
||||
<div class="stat"><b>{len(ENGINES)}</b><span>AI 답변엔진</span></div>
|
||||
|
||||
@@ -6,10 +6,14 @@
|
||||
- 효과는 약속하지 않는다: "인용할 수 있는 근거가 생긴다", "다시 측정해 보여 드린다" 까지만 쓴다
|
||||
- 서명은 넣지 않는다 (발송인이 직접 추가)
|
||||
|
||||
python3 docs/reports/outbound_webforai/build_mail_drafts.py <출력 json> [--images=<소개서 폴더>,<이미지 폴더>] [--roadmap=<이미지 폴더>]
|
||||
python3 docs/reports/outbound_webforai/build_mail_drafts.py <출력 json> --clinics=<병원>,<병원>,...
|
||||
[--images=<소개서 폴더>,<이미지 폴더>] [--roadmap=<이미지 폴더>]
|
||||
|
||||
- 메일 이미지용 소개서는 소개서 폴더에서 병원별 가장 높은 버전(WebforAI_소개서_{병원}_v{N}_*.pptx)을 고른다
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
@@ -17,8 +21,6 @@ sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
import build_diagnosis_report as report # noqa: E402
|
||||
import run_outbound_probe as probe # noqa: E402
|
||||
|
||||
CLINICS = ["그랜드성형외과", "JK성형외과", "아이디병원", "바노바기성형외과", "원진성형외과"]
|
||||
|
||||
# 문제 제기에 쓰는 환자 질문 (핵심 발견 질문을 환자 말투로)
|
||||
ASK = {"kr:Q2": "“강남 {proc} 잘하는 곳 추천해줘”", "kr:Q3": "“강남 성형외과 추천해줘”",
|
||||
"en:Q4": "“English-speaking plastic surgeon in Seoul”"}
|
||||
@@ -44,7 +46,9 @@ def body(d, clinic):
|
||||
"""친절하고 간결한 본문. 세부 수치는 이미지(핵심 발견·로드맵)와 첨부 PDF 가 맡는다."""
|
||||
name, kf = d["name"], d["kf"]
|
||||
neun, reul = report.josa(name, "은", "는"), report.josa(name, "을", "를")
|
||||
ask = ASK[kf["slot"]].format(proc=clinic["procedure_ko"])
|
||||
lang, qno = kf["slot"].split(":Q")
|
||||
ask = (ASK[kf["slot"]].format(proc=clinic["procedure_ko"]) if kf["slot"] in ASK
|
||||
else f"“{d['questions'][lang][int(qno) - 1]['question']}”")
|
||||
who = "해외 환자" if kf["slot"].startswith("en") else "환자"
|
||||
fails = [t for t, ok, _ in d["site"] if not ok]
|
||||
causes = [CAUSE_PLAIN.get(t, t) for t in CAUSE_ORDER if t in fails][:3]
|
||||
@@ -74,18 +78,30 @@ def body(d, clinic):
|
||||
MAIL_HERO = "AI 추천 목록에는 아직 없었습니다." # 소개서의 "한 번도 언급되지 않았습니다." 를 메일용으로 순화
|
||||
|
||||
|
||||
def images(deck_dir, img_dir):
|
||||
def latest_deck(deck_dir, name):
|
||||
"""소개서 폴더에서 이 병원의 가장 높은 버전 소개서. 같은 버전이 둘이면 멈춘다."""
|
||||
rx = re.compile(r"WebforAI_소개서_" + re.escape(name) + r"_v(\d+)_.*\.pptx$")
|
||||
found = [(int(m.group(1)), f) for f in os.listdir(deck_dir) if not f.startswith("~$") and (m := rx.match(f))]
|
||||
assert found, f"소개서 없음: {name} ({deck_dir})"
|
||||
top = max(v for v, _ in found)
|
||||
files = [f for v, f in found if v == top]
|
||||
assert len(files) == 1, f"같은 버전 소개서가 여럿입니다: {files}"
|
||||
return os.path.join(deck_dir, files[0])
|
||||
|
||||
|
||||
def images(clinics, deck_dir, img_dir):
|
||||
"""소개서 4장(핵심 발견)을 메일 본문용 PNG(가로 1600px)로 뽑는다.
|
||||
메일용은 강조 문장을 순화하고 쪽 번호(03 · Key Finding)를 뺀다. 소개서 원본은 건드리지 않는다."""
|
||||
from pptx import Presentation
|
||||
import tempfile
|
||||
os.makedirs(img_dir, exist_ok=True)
|
||||
tmp = tempfile.mkdtemp()
|
||||
for name in CLINICS:
|
||||
for name in clinics:
|
||||
out = os.path.join(img_dir, f"{name}_핵심발견")
|
||||
assert not os.path.exists(out + ".png"), f"이미 있습니다: {out}.png"
|
||||
ver = "v14" if name == "그랜드성형외과" else "v13"
|
||||
prs = Presentation(os.path.join(deck_dir, f"WebforAI_소개서_{name}_{ver}_2026-10-26.pptx"))
|
||||
deck = latest_deck(deck_dir, name)
|
||||
print("소개서:", os.path.basename(deck))
|
||||
prs = Presentation(deck)
|
||||
s4 = prs.slides[3]
|
||||
hero = next(sh for sh in s4.shapes if sh.name == "TextBox 2")
|
||||
assert hero.text_frame.paragraphs[2].runs[0].text == "한 번도 언급되지 않았습니다."
|
||||
@@ -190,11 +206,11 @@ def roadmap_html(d, logos):
|
||||
'<div class="top"><div><div class="eyebrow">AI DISCOVERY · %s</div><h1>AI 답변 진단에서 <em>개선까지</em></h1></div>'
|
||||
'<div class="logos"><img src="%s"><div class="bar"></div><img src="%s" style="height:22px"></div></div>'
|
||||
'<div class="flow">%s</div>'
|
||||
'<div class="foot">측정 2026. 10. 19 · 10. 26 · 질문 10개 × AI 답변엔진 4종 × 3회 · 응답 점수는 판정 가능한 답변 중 언급·인용 횟수, 홈페이지 점검은 12개 항목 중 충족 수</div>'
|
||||
'</body></html>' % (ROADMAP_CSS, H.escape(name), logos[0], logos[1], cards))
|
||||
'<div class="foot">측정 %s · 질문 10개 × AI 답변엔진 4종 × 3회 · 응답 점수는 판정 가능한 답변 중 언급·인용 횟수, 홈페이지 점검은 12개 항목 중 충족 수</div>'
|
||||
'</body></html>' % (ROADMAP_CSS, H.escape(name), logos[0], logos[1], cards, d["measured"]))
|
||||
|
||||
|
||||
def roadmap_images(img_dir):
|
||||
def roadmap_images(names, img_dir):
|
||||
from playwright.sync_api import sync_playwright
|
||||
a = os.path.join(os.path.dirname(os.path.abspath(__file__)), "assets")
|
||||
logos = [report.b64(f"{a}/infinith_white.png"), report.b64(f"{a}/webforai_white.png")]
|
||||
@@ -204,7 +220,7 @@ def roadmap_images(img_dir):
|
||||
with sync_playwright() as p:
|
||||
b = p.chromium.launch()
|
||||
pg = b.new_page(viewport={"width": 1600, "height": 900}, device_scale_factor=1)
|
||||
for name in CLINICS:
|
||||
for name in names:
|
||||
out = os.path.join(img_dir, f"{name}_AI_Discovery_로드맵.png")
|
||||
assert not os.path.exists(out), f"이미 있습니다: {out}"
|
||||
c = next(x for x in clinics if x["name"] == name)
|
||||
@@ -218,11 +234,11 @@ def roadmap_images(img_dir):
|
||||
b.close()
|
||||
|
||||
|
||||
def main(out_json):
|
||||
def main(out_json, names):
|
||||
clinics = probe.load("pilot_clinics.json")
|
||||
_, plan = probe.expand(clinics, probe.load("question_template.json"))
|
||||
res = {}
|
||||
for name in CLINICS:
|
||||
for name in names:
|
||||
c = next(x for x in clinics if x["name"] == name)
|
||||
b = body(report.report_data(c, plan), c)
|
||||
banned = ["브릿지", "bridge", "doorway", "서포터즈", "장악", "주입", "노출", "—", "보장", "반드시"]
|
||||
@@ -233,9 +249,10 @@ def main(out_json):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(sys.argv[1])
|
||||
for a in sys.argv[2:]:
|
||||
if a.startswith("--images="):
|
||||
images(*a.split("=", 1)[1].split(","))
|
||||
if a.startswith("--roadmap="):
|
||||
roadmap_images(a.split("=", 1)[1])
|
||||
opts = dict(a[2:].split("=", 1) for a in sys.argv[2:])
|
||||
names = opts["clinics"].split(",")
|
||||
main(sys.argv[1], names)
|
||||
if "images" in opts:
|
||||
images(names, *opts["images"].split(","))
|
||||
if "roadmap" in opts:
|
||||
roadmap_images(names, opts["roadmap"])
|
||||
@@ -67,7 +67,7 @@ def cover(slide, d):
|
||||
y += 0.7
|
||||
text(slide, lx, y, 10.2, 1.45, d["name"], 88.0, 1, "cover name", bold=True, color=NAVY)
|
||||
y += 1.65
|
||||
text(slide, lx, y, 10.2, 0.5, f"AI 답변 진단 보고서 · 측정 {v3.MEASURED}", 26.0, 1, "cover meta", color=SLATE_700)
|
||||
text(slide, lx, y, 10.2, 0.5, f"AI 답변 진단 보고서 · 측정 {d['measured']}", 26.0, 1, "cover meta", color=SLATE_700)
|
||||
_rect(slide, split, Y0 + 0.9, 0.03, Y1 - Y0 - 1.8, fill=RULE, line=None, radius=0)
|
||||
stats = [("10", "환자 질문 (한국어 5 · 영어 5)"), ("4", "AI 답변엔진"), ("×3", "질문마다 3회 측정")]
|
||||
sy = Y0 + (Y1 - Y0 - 3 * 2.05) / 2
|
||||
|
||||
Reference in new issue
Block a user