mannnon commited on
Commit
1ddfd69
·
verified ·
1 Parent(s): 3093069

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -16
app.py CHANGED
@@ -517,33 +517,28 @@ def match_pdf_to_athlete(pdfs_data, athlete_name):
517
  best_score = 0
518
 
519
  for pdf in pdfs_data:
520
- pdf_name_raw = pdf.get("athlete_name")
521
- pdf_name = normalize_name(pdf_name_raw)
 
 
 
522
 
523
- # 1) match exact
524
  if pdf_name == target:
525
  return pdf
526
 
527
- # 2) match par mots communs
528
- pdf_parts = set(pdf_name.split())
529
- common_parts = target_parts.intersection(pdf_parts)
530
- score = len(common_parts)
531
 
532
  if score > best_score:
533
  best_score = score
534
  best_pdf = pdf
535
 
536
- # 3) fallback si un nom contient l'autre
537
- if target and pdf_name:
538
- if target in pdf_name or pdf_name in target:
539
- best_pdf = pdf
540
- best_score = max(best_score, 1)
541
-
542
- # si on a au moins 1 mot en commun, on accepte
543
- if best_score >= 1:
544
  return best_pdf
545
 
546
- # fallback final : s'il n'y a qu'un seul PDF uploadé, on le prend
547
  if len(pdfs_data) == 1:
548
  return pdfs_data[0]
549
 
 
517
  best_score = 0
518
 
519
  for pdf in pdfs_data:
520
+ pdf_name = normalize_name(pdf.get("athlete_name"))
521
+ pdf_parts = set(pdf_name.split())
522
+
523
+ if not pdf_name:
524
+ continue
525
 
526
+ # match exact = priorité absolue
527
  if pdf_name == target:
528
  return pdf
529
 
530
+ # score = nb de mots en commun
531
+ score = len(target_parts.intersection(pdf_parts))
 
 
532
 
533
  if score > best_score:
534
  best_score = score
535
  best_pdf = pdf
536
 
537
+ # on n'accepte le match que si au moins 2 mots en commun
538
+ if best_score >= 2:
 
 
 
 
 
 
539
  return best_pdf
540
 
541
+ # si un seul PDF est chargé, on peut le prendre
542
  if len(pdfs_data) == 1:
543
  return pdfs_data[0]
544