mannnon commited on
Commit
6b9ff0a
·
verified ·
1 Parent(s): 65e18cc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -4
app.py CHANGED
@@ -415,16 +415,50 @@ def match_pdf_to_athlete(pdfs_data, athlete_name):
415
  target = normalize_name(athlete_name)
416
  target_parts = set(target.split())
417
 
 
 
 
418
  for pdf in pdfs_data:
419
- pdf_name = normalize_name(pdf.get("athlete_name"))
420
- pdf_parts = set(pdf_name.split())
421
 
422
- # match si au moins 2 mots en commun
423
- if len(target_parts.intersection(pdf_parts)) >= 2:
424
  return pdf
425
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
426
  return None
427
 
 
 
 
 
 
 
 
 
428
  # =========================================================
429
  # ANALYSE V3
430
  # =========================================================
 
415
  target = normalize_name(athlete_name)
416
  target_parts = set(target.split())
417
 
418
+ best_pdf = None
419
+ best_score = 0
420
+
421
  for pdf in pdfs_data:
422
+ pdf_name_raw = pdf.get("athlete_name")
423
+ pdf_name = normalize_name(pdf_name_raw)
424
 
425
+ # 1) match exact
426
+ if pdf_name == target:
427
  return pdf
428
 
429
+ # 2) match par mots communs
430
+ pdf_parts = set(pdf_name.split())
431
+ common_parts = target_parts.intersection(pdf_parts)
432
+ score = len(common_parts)
433
+
434
+ if score > best_score:
435
+ best_score = score
436
+ best_pdf = pdf
437
+
438
+ # 3) fallback si un nom contient l'autre
439
+ if target and pdf_name:
440
+ if target in pdf_name or pdf_name in target:
441
+ best_pdf = pdf
442
+ best_score = max(best_score, 1)
443
+
444
+ # si on a au moins 1 mot en commun, on accepte
445
+ if best_score >= 1:
446
+ return best_pdf
447
+
448
+ # fallback final : s'il n'y a qu'un seul PDF uploadé, on le prend
449
+ if len(pdfs_data) == 1:
450
+ return pdfs_data[0]
451
+
452
  return None
453
 
454
+ matched_pdf = match_pdf_to_athlete(pdfs_data, selected_athlete)
455
+
456
+ st.write("Athlète CSV sélectionné :", selected_athlete)
457
+
458
+ for i, pdf in enumerate(pdfs_data):
459
+ st.write(f"PDF {i+1} - athlete_name extrait :", pdf.get("athlete_name"))
460
+ st.write(f"PDF {i+1} - source_pdf :", pdf.get("source_pdf"))
461
+
462
  # =========================================================
463
  # ANALYSE V3
464
  # =========================================================