Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 521 |
-
|
|
|
|
|
|
|
|
|
|
| 522 |
|
| 523 |
-
#
|
| 524 |
if pdf_name == target:
|
| 525 |
return pdf
|
| 526 |
|
| 527 |
-
#
|
| 528 |
-
|
| 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 |
-
|
| 537 |
-
|
| 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 |
-
#
|
| 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 |
|