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
@@ -51,6 +51,24 @@ async def test_job_status_not_found(client, clean_jobs):
|
||||
assert r2.json()["result"]["desc"] == "LPS_JOB_NOT_FOUND"
|
||||
|
||||
|
||||
async def test_price_history_endpoint(client, db_engine):
|
||||
from crud.price_history import PriceHistory
|
||||
async with db_engine.begin() as conn:
|
||||
await conn.execute(text("TRUNCATE price_history"))
|
||||
ph = PriceHistory()
|
||||
await ph.record({"product_code": "GRAPH1", "outcome": "found", "final_lowest": 2500,
|
||||
"final_source": "naver", "naver_lowest": 2500, "coupang_lowest": 2700, "matched_count": 2})
|
||||
|
||||
r = await client.get("/v1/lps/products/GRAPH1/history")
|
||||
assert r.status_code == 200
|
||||
body = r.json()
|
||||
assert body["product_code"] == "GRAPH1"
|
||||
assert len(body["points"]) == 1
|
||||
pt = body["points"][0]
|
||||
assert pt["final"] == 2500 and pt["naver"] == 2500 and pt["coupang"] == 2700 and pt["final_source"] == "naver"
|
||||
assert "triggered_at" in pt
|
||||
|
||||
|
||||
async def test_queue_stats(client, clean_jobs):
|
||||
await client.post("/v1/lps/search", json={"data": [
|
||||
{"product_code": "A", "product_name": "x"},
|
||||
|
||||
Reference in new issue
Block a user