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
@@ -45,3 +45,22 @@ class Res_JobStatus(Res_WebPacketProtocol):
|
||||
|
||||
class Res_QueueStats(Res_WebPacketProtocol):
|
||||
counts: dict[str, int] = Field(default_factory=dict, description="상태별 잡 개수")
|
||||
|
||||
|
||||
class PricePoint(BaseModel):
|
||||
triggered_at: str = Field(description="관측 시각(X축)")
|
||||
outcome: str
|
||||
matched_count: Optional[int] = None
|
||||
naver: Optional[int] = Field(None, description="네이버 최저가")
|
||||
coupang: Optional[int] = Field(None, description="쿠팡 최저가")
|
||||
final: Optional[int] = Field(None, description="전체 최저가(Y축)")
|
||||
final_source: Optional[str] = None
|
||||
naver_name: Optional[str] = None
|
||||
naver_url: Optional[str] = None
|
||||
coupang_name: Optional[str] = None
|
||||
coupang_url: Optional[str] = None
|
||||
|
||||
|
||||
class Res_PriceHistory(Res_WebPacketProtocol):
|
||||
product_code: Optional[str] = None
|
||||
points: list[PricePoint] = Field(default_factory=list, description="시각 오름차순 스냅샷(그래프용)")
|
||||
@@ -2,9 +2,11 @@
|
||||
|
||||
from fastapi import APIRouter, Depends
|
||||
|
||||
from fastapi import Query
|
||||
|
||||
from router.v1.validator.dependencies import RemoveNoneResponse
|
||||
from services.lps_service import LpsService
|
||||
from router.v1.lps.protocol import Res_JobStatus, Res_QueueStats, Res_Search, Req_Search
|
||||
from router.v1.lps.protocol import Res_JobStatus, Res_PriceHistory, Res_QueueStats, Res_Search, Req_Search
|
||||
|
||||
router = APIRouter(prefix="/v1/lps", tags=["LPS"], responses={404: {"description": "Not found"}})
|
||||
|
||||
@@ -37,3 +39,13 @@ async def job_status(job_id: str, service: LpsService = Depends()):
|
||||
)
|
||||
async def queue_stats(service: LpsService = Depends()):
|
||||
return RemoveNoneResponse(await service.stats())
|
||||
|
||||
|
||||
@router.get(
|
||||
path="/products/{product_code}/history",
|
||||
response_model=Res_PriceHistory,
|
||||
summary="최저가 이력(그래프)",
|
||||
description="상품의 트리거별 최저가 스냅샷(네이버/쿠팡/최종)을 시각 오름차순으로 반환. 가격 시계열 그래프용.",
|
||||
)
|
||||
async def price_history(product_code: str, limit: int = Query(100, ge=1, le=1000), service: LpsService = Depends()):
|
||||
return RemoveNoneResponse(await service.price_history(product_code, limit))
|
||||
Reference in new issue
Block a user