feat(lps): 네이버 몰별 최저가 분해(by_mall) — 오픈마켓 가시화

네이버 오픈API 결과엔 G마켓·옥션·11번가 등이 이미 mallName 으로 들어오는데
최저가 1건만 쓰고 몰 정보를 버리고 있었다. summarize_by_mall() 로 매칭 후보를
(소스, 판매몰)별 최저가로 축약해 result.by_mall(가격 오름차순)에 노출한다.
추가 요청 0건으로 오픈마켓 몰별 최저가를 확보 — 별도 크롤러 불필요.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
민헌andClaude Fable 5 committed 2026-07-09 13:59:15 +09:00
1 parent 4863425ca5
commit 313d882df4
2 files changed
+45 -1

No files matched your search

+20
View File
@@ -51,6 +51,25 @@ def apply_filters(
return cur, stages
def summarize_by_mall(products: list[NormalizedProduct]) -> list[dict]:
"""같은상품 매칭 후보를 (소스, 판매몰)별 최저가로 분해한다.
네이버 결과엔 G마켓·옥션·11번가 등이 mall_name 으로 이미 들어오므로,
추가 요청 없이 '오픈마켓 몰별 최저가'를 노출할 수 있다(가격 오름차순).
네이버 가격비교(mall_name='네이버')는 여러 판매자 중 최저가 롤업이다."""
best: dict[tuple[str, str], NormalizedProduct] = {}
for p in products:
key = (p.source, (p.mall_name or "기타"))
cur = best.get(key)
if cur is None or p.price < cur.price:
best[key] = p
rows = sorted(best.values(), key=lambda p: p.price)
return [{
"source": p.source, "mall_name": p.mall_name, "price": p.price,
"shipping_fee": p.shipping_fee, "shipping_type": p.shipping_type,
"name": p.name, "detail_url": p.detail_url,
} for p in rows]
def rank_result(products: list[NormalizedProduct], total_found: int, stages: list[dict], top_n: int = 5) -> dict:
"""최저가순 정렬 + top-N + 결과 봉투 조립(top_n STAGE 포함)."""
ranked = sorted(products, key=lambda p: p.price)
@@ -61,6 +80,7 @@ def rank_result(products: list[NormalizedProduct], total_found: int, stages: lis
"kept": len(ranked),
"lowest": top[0].model_dump() if top else None,
"top": [p.model_dump() for p in top],
"by_mall": summarize_by_mall(ranked),
"stages": stages,
}