Spaces:
Sleeping
Sleeping
Adzacam commited on
Commit ·
59ad42d
1
Parent(s): 5a1b47c
refactor: update student fuzzy matching logic to use find_best_match with entity objects
Browse files
app.py
CHANGED
|
@@ -703,7 +703,7 @@ def procesar_lote_financiero(payloads: List[FinancePayload], db: Session = Depen
|
|
| 703 |
if current_user.role not in ["analista_datos_marketing", "admin"]:
|
| 704 |
raise HTTPException(status_code=403, detail="Acceso denegado: Se requiere rol de Analista de Datos.")
|
| 705 |
try:
|
| 706 |
-
from similarity import
|
| 707 |
|
| 708 |
for payload in payloads:
|
| 709 |
# 1. Resolver Estudiante
|
|
@@ -718,15 +718,13 @@ def procesar_lote_financiero(payloads: List[FinancePayload], db: Session = Depen
|
|
| 718 |
if not estudiante:
|
| 719 |
estudiante = db.query(DimEstudiante).filter(DimEstudiante.nombre_completo.ilike(f"%{nombre_resuelto}%")).first()
|
| 720 |
|
| 721 |
-
# Si no hay match exacto, usar fuzzy matching
|
| 722 |
if not estudiante:
|
| 723 |
-
todos_estudiantes = db.query(DimEstudiante
|
| 724 |
-
|
| 725 |
-
matches = get_top_matches(nombre_resuelto, nombres_db, limit=1)
|
| 726 |
|
| 727 |
-
if
|
| 728 |
-
|
| 729 |
-
estudiante = db.query(DimEstudiante).filter(DimEstudiante.id_estudiante == est_id).first()
|
| 730 |
|
| 731 |
# Si de plano no existe, lo creamos para que no falle la FK
|
| 732 |
if not estudiante:
|
|
|
|
| 703 |
if current_user.role not in ["analista_datos_marketing", "admin"]:
|
| 704 |
raise HTTPException(status_code=403, detail="Acceso denegado: Se requiere rol de Analista de Datos.")
|
| 705 |
try:
|
| 706 |
+
from similarity import find_best_match
|
| 707 |
|
| 708 |
for payload in payloads:
|
| 709 |
# 1. Resolver Estudiante
|
|
|
|
| 718 |
if not estudiante:
|
| 719 |
estudiante = db.query(DimEstudiante).filter(DimEstudiante.nombre_completo.ilike(f"%{nombre_resuelto}%")).first()
|
| 720 |
|
| 721 |
+
# Si no hay match exacto, usar fuzzy matching
|
| 722 |
if not estudiante:
|
| 723 |
+
todos_estudiantes = db.query(DimEstudiante).all()
|
| 724 |
+
best_match, score = find_best_match(nombre_resuelto, todos_estudiantes, threshold=0.85)
|
|
|
|
| 725 |
|
| 726 |
+
if best_match:
|
| 727 |
+
estudiante = best_match
|
|
|
|
| 728 |
|
| 729 |
# Si de plano no existe, lo creamos para que no falle la FK
|
| 730 |
if not estudiante:
|