feat(lps): 최저가 이력(price_history) — 트리거 기반 시계열 그래프
같은 상품 반복 검색 시 최저가를 스냅샷으로 적재 → 네이버/쿠팡/최종 3개 선 그래프.
배치 아님(조회된 상품만, 실제 검색 시각에 기록) — 트래픽/리소스 절약.
- price_history 테이블: product_code·triggered_at(X축)·naver/coupang/final 최저가+상세·outcome
- crud/price_history: record() + list_by_product(시각 오름차순)
- handler: AI 매칭 후 소스별 min + 전체 min 스냅샷 기록(_price_snapshot).
found/not_found 기록, 네거티브 캐시 히트·기술실패는 미기록
- API: GET /v1/lps/products/{product_code}/history → 그래프 데이터(시각 오름차순)
- tests: 스냅샷 계산/기록·조회/핸들러 기록규칙/API → 전체 54/54
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
bca8032b79
commit
5906acc48a
9 files changed
+299
-5
No files matched your search
@@ -68,6 +68,40 @@ class search_negative(MAIN_BASE):
|
||||
created_at = Column(DateTime(timezone=True), nullable=False, server_default=text("now()"))
|
||||
|
||||
|
||||
class price_history(MAIN_BASE):
|
||||
"""상품별 최저가 스냅샷(트리거 기반). 네이버/쿠팡/최종 최저가를 검색 시점마다 적재해
|
||||
시계열 그래프(X=triggered_at, Y=가격, 3개 선)로 본다. 배치 아님 — 조회된 상품만 기록."""
|
||||
|
||||
@staticmethod
|
||||
def DBType():
|
||||
return DBType.MAIN.value
|
||||
|
||||
__tablename__ = "price_history"
|
||||
|
||||
id = Column(UUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()"))
|
||||
product_code = Column(String(100), nullable=False) # 상품 식별(조회 키)
|
||||
job_id = Column(UUID(as_uuid=True), nullable=True) # 검색 잡 연결(추적)
|
||||
triggered_at = Column(DateTime(timezone=True), nullable=False, server_default=text("now()")) # X축(검색 실행 시각)
|
||||
outcome = Column(String(20), nullable=False) # found / not_found
|
||||
matched_count = Column(Integer, nullable=True) # AI 매칭 건수
|
||||
|
||||
naver_lowest = Column(Integer, nullable=True) # 네이버 최저가(같은 상품)
|
||||
naver_name = Column(String(300), nullable=True)
|
||||
naver_url = Column(Text, nullable=True)
|
||||
coupang_lowest = Column(Integer, nullable=True) # 쿠팡 최저가(같은 상품)
|
||||
coupang_name = Column(String(300), nullable=True)
|
||||
coupang_url = Column(Text, nullable=True)
|
||||
final_lowest = Column(Integer, nullable=True) # 전체 최저가(Y축 핵심)
|
||||
final_source = Column(String(20), nullable=True) # 최종 최저가 소스
|
||||
|
||||
created_at = Column(DateTime(timezone=True), nullable=False, server_default=text("now()"))
|
||||
|
||||
__table_args__ = (
|
||||
# 특정 상품 시계열 조회 최적화
|
||||
Index("ix_price_history_product", "product_code", "triggered_at"),
|
||||
)
|
||||
|
||||
|
||||
class bot_detection(MAIN_BASE):
|
||||
"""봇 감지 이력 — '이 IP로 몇 번째 요청에서, 어떤 방식으로 차단됐나'를 축적해 패턴 분석.
|
||||
(예: SELECT avg(ip_request_no) → IP당 평균 몇 요청 만에 감지되는지)"""
|
||||
|
||||
Reference in new issue
Block a user