뷰성형외과 전용 mock데이터 외삽 알고리즘 추가

This commit is contained in:
jaehwang committed 2026-05-21 15:41:43 +09:00
1 parent cb798f7acc
commit 0e68cbe71b
4 files changed
+816 -4

No files matched your search

+38 -2
View File
@@ -1,5 +1,6 @@
import json
import logging
import os
from common.db import fetchone, execute, fetch_raw, get_analysis_raw_data, save_analysis_report, get_market_analysis
from integrations.llm.llm_service import LLMService
from integrations.llm.prompt import report_prompt, plan_prompt
@@ -192,9 +193,40 @@ def _patch_report(result: ReportOutput, overrides: dict) -> ReportOutput:
return ReportOutput(**merged)
_MOCK_DOMAINS = {"viewclinic.com"}
_MOCK_REPORT_PATH = os.path.join(os.path.dirname(__file__), "../mock/report_viewclinic.json")
async def _is_mock(analysis_run_id: str) -> bool:
row = await fetchone(
"SELECT h.url FROM analysis_runs ar JOIN hospital_baseinfo h USING (hospital_id)"
" WHERE ar.analysis_run_id = %s",
(analysis_run_id,),
)
url = (row or {}).get("url") or ""
return any(domain in url for domain in _MOCK_DOMAINS)
def _load_mock_report() -> ReportOutput:
with open(_MOCK_REPORT_PATH, encoding="utf-8") as f:
return ReportOutput(**json.load(f))
_MOCK_PLAN_PATH = os.path.join(os.path.dirname(__file__), "../mock/plan_viewclinic.json")
def _load_mock_plan() -> PlanOutput:
with open(_MOCK_PLAN_PATH, encoding="utf-8") as f:
return PlanOutput(**json.load(f))
async def run_report_task(analysis_run_id: str) -> None:
logger.info("[report] start run=%s", analysis_run_id)
result = await generate_report(analysis_run_id)
if await _is_mock(analysis_run_id):
logger.info("[report] mock mode run=%s", analysis_run_id)
result = _load_mock_report()
else:
result = await generate_report(analysis_run_id)
result = _patch_report(result, await _build_overrides(analysis_run_id))
await save_analysis_report(analysis_run_id, result.model_dump())
logger.info("[report] done run=%s", analysis_run_id)
@@ -202,7 +234,11 @@ async def run_report_task(analysis_run_id: str) -> None:
async def run_plan_task(analysis_run_id: str) -> None:
logger.info("[plan] start run=%s", analysis_run_id)
result = await generate_plan(analysis_run_id)
if await _is_mock(analysis_run_id):
logger.info("[plan] mock mode run=%s", analysis_run_id)
result = _load_mock_plan()
else:
result = await generate_plan(analysis_run_id)
await execute(
"UPDATE analysis_runs SET plan_data = %s WHERE analysis_run_id = %s",
(json.dumps(result.model_dump(), ensure_ascii=False), analysis_run_id),