feat: fuzzy matching Picnic ↔ Leclerc + page /matches dans le dashboard

Nouvelle table product_matches (status: pending/validated/rejected).
Matching via RapidFuzz token_sort_ratio, seuil configurable (défaut 85%).

Workflow :
  1. python -m tickettracker.cli match [--threshold 85]
     → calcule et stocke les paires candidates
  2. http://localhost:8000/matches
     → l'utilisateur valide ou rejette chaque paire
  3. La comparaison de prix enrichie avec les paires validées

Nouvelles dépendances : rapidfuzz, watchdog (requirements.txt).
10 tests ajoutés (test_matcher.py), tous passent.
Suite complète : 129 passent, 1 xfail, 0 échec.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-25 18:02:48 +01:00
parent f360332626
commit be4d4a7076
13 changed files with 804 additions and 23 deletions

View File

@@ -8,6 +8,7 @@ appelle la fonction de queries.py correspondante, puis ferme la connexion.
import sqlite3
from fastapi import APIRouter, HTTPException
from fastapi.responses import Response
import tickettracker.config as config
from tickettracker.db.schema import get_connection
@@ -70,6 +71,46 @@ def api_receipts():
conn.close()
@router.post("/match/{match_id}/validate")
def api_match_validate(match_id: int):
"""Valide une paire fuzzy (status → 'validated').
Retourne 404 si l'id est inconnu.
"""
conn = get_connection(config.DB_PATH)
try:
with conn:
cur = conn.execute(
"UPDATE product_matches SET status='validated' WHERE id=?",
(match_id,),
)
finally:
conn.close()
if cur.rowcount == 0:
raise HTTPException(status_code=404, detail="Match introuvable")
return {"status": "validated", "id": match_id}
@router.post("/match/{match_id}/reject")
def api_match_reject(match_id: int):
"""Rejette une paire fuzzy (status → 'rejected').
Retourne 404 si l'id est inconnu.
"""
conn = get_connection(config.DB_PATH)
try:
with conn:
cur = conn.execute(
"UPDATE product_matches SET status='rejected' WHERE id=?",
(match_id,),
)
finally:
conn.close()
if cur.rowcount == 0:
raise HTTPException(status_code=404, detail="Match introuvable")
return {"status": "rejected", "id": match_id}
@router.get("/receipt/{receipt_id}")
def api_receipt_detail(receipt_id: int):
"""Détail d'un ticket et de ses articles.