Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -358,7 +358,31 @@ def extract_pdf_name(text: str, source_pdf: str = None):
|
|
| 358 |
return name.upper()
|
| 359 |
|
| 360 |
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 361 |
|
|
|
|
| 362 |
|
| 363 |
def parse_zebris_pdf(uploaded_pdf):
|
| 364 |
uploaded_pdf.seek(0)
|
|
@@ -408,12 +432,7 @@ def parse_zebris_pdf(uploaded_pdf):
|
|
| 408 |
full_text = " ".join(page_texts)
|
| 409 |
|
| 410 |
# Extraction de l'allure du PDF (ex: "VMA 14kmh" ou "14,0 km/h")
|
| 411 |
-
|
| 412 |
-
if not speed_match:
|
| 413 |
-
speed_match = re.search(r"(\d+(?:[.,]\d+)?)\s*kmh", full_text, flags=re.I)
|
| 414 |
-
|
| 415 |
-
if speed_match:
|
| 416 |
-
data["speed_kmh"] = float(speed_match.group(1).replace(",", "."))
|
| 417 |
|
| 418 |
# fallback si nom non récupéré via fichier
|
| 419 |
if not data["athlete_name"]:
|
|
@@ -1536,8 +1555,7 @@ with tab_pdf:
|
|
| 1536 |
],
|
| 1537 |
"Valeur": [
|
| 1538 |
matched_pdf["source_pdf"],
|
| 1539 |
-
f"{matched_pdf
|
| 1540 |
-
matched_pdf["attaque_pdf"],
|
| 1541 |
f"{matched_pdf['transition_g']:.3f} s" if pd.notna(matched_pdf["transition_g"]) else "N/A",
|
| 1542 |
f"{matched_pdf['transition_d']:.3f} s" if pd.notna(matched_pdf["transition_d"]) else "N/A",
|
| 1543 |
f"{matched_pdf['heel_force_g']:.1f} N" if pd.notna(matched_pdf["heel_force_g"]) else "N/A",
|
|
|
|
| 358 |
return name.upper()
|
| 359 |
|
| 360 |
return None
|
| 361 |
+
def extract_speed_from_pdf_text_or_filename(full_text: str, source_pdf: str):
|
| 362 |
+
# 1) Cherche dans le texte PDF
|
| 363 |
+
patterns = [
|
| 364 |
+
r"VMA\s*(\d+(?:[.,]\d+)?)\s*kmh",
|
| 365 |
+
r"VMA\s*(\d+(?:[.,]\d+)?)\s*km/h",
|
| 366 |
+
r"Vitesse,\s*km/h\s*(\d+(?:[.,]\d+)?)",
|
| 367 |
+
r"(\d+(?:[.,]\d+)?)\s*kmh",
|
| 368 |
+
r"(\d+(?:[.,]\d+)?)\s*km/h",
|
| 369 |
+
]
|
| 370 |
+
|
| 371 |
+
if full_text:
|
| 372 |
+
for pattern in patterns:
|
| 373 |
+
m = re.search(pattern, full_text, flags=re.I)
|
| 374 |
+
if m:
|
| 375 |
+
return float(m.group(1).replace(",", "."))
|
| 376 |
+
|
| 377 |
+
# 2) Fallback : cherche dans le nom du fichier
|
| 378 |
+
if source_pdf:
|
| 379 |
+
m = re.search(r"(\d+(?:[.,]\d+)?)\s*kmh", source_pdf, flags=re.I)
|
| 380 |
+
if not m:
|
| 381 |
+
m = re.search(r"(\d+(?:[.,]\d+)?)\s*km/h", source_pdf, flags=re.I)
|
| 382 |
+
if m:
|
| 383 |
+
return float(m.group(1).replace(",", "."))
|
| 384 |
|
| 385 |
+
return np.nan
|
| 386 |
|
| 387 |
def parse_zebris_pdf(uploaded_pdf):
|
| 388 |
uploaded_pdf.seek(0)
|
|
|
|
| 432 |
full_text = " ".join(page_texts)
|
| 433 |
|
| 434 |
# Extraction de l'allure du PDF (ex: "VMA 14kmh" ou "14,0 km/h")
|
| 435 |
+
data["speed_kmh"] = extract_speed_from_pdf_text_or_filename(full_text, source_pdf)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 436 |
|
| 437 |
# fallback si nom non récupéré via fichier
|
| 438 |
if not data["athlete_name"]:
|
|
|
|
| 1555 |
],
|
| 1556 |
"Valeur": [
|
| 1557 |
matched_pdf["source_pdf"],
|
| 1558 |
+
f"{matched_pdf['speed_kmh']:.1f} km/h" if pd.notna(matched_pdf.get("speed_kmh")) else "N/A",
|
|
|
|
| 1559 |
f"{matched_pdf['transition_g']:.3f} s" if pd.notna(matched_pdf["transition_g"]) else "N/A",
|
| 1560 |
f"{matched_pdf['transition_d']:.3f} s" if pd.notna(matched_pdf["transition_d"]) else "N/A",
|
| 1561 |
f"{matched_pdf['heel_force_g']:.1f} N" if pd.notna(matched_pdf["heel_force_g"]) else "N/A",
|