Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -453,25 +453,43 @@ def parse_zebris_pdf(uploaded_pdf):
|
|
| 453 |
def to_float(x):
|
| 454 |
return float(x.replace(",", ".").replace(" ", ""))
|
| 455 |
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 463 |
|
| 464 |
full_text = " ".join(page_texts)
|
| 465 |
-
|
| 466 |
if not full_text.strip():
|
| 467 |
data["attaque_pdf"] = "indéterminée"
|
| 468 |
return data
|
| 469 |
-
|
| 470 |
|
| 471 |
-
#
|
| 472 |
if not data["athlete_name"]:
|
| 473 |
data["athlete_name"] = extract_pdf_name(full_text, source_pdf=source_pdf)
|
| 474 |
|
|
|
|
|
|
|
|
|
|
| 475 |
# --------------------------------------------------
|
| 476 |
# Chercher la page utile Zebris
|
| 477 |
# --------------------------------------------------
|
|
@@ -493,12 +511,6 @@ def parse_zebris_pdf(uploaded_pdf):
|
|
| 493 |
zone_page_text = zone_page_text.replace("\xa0", " ")
|
| 494 |
zone_page_text = re.sub(r"\s+", " ", zone_page_text).strip()
|
| 495 |
|
| 496 |
-
# --------------------------------------------------
|
| 497 |
-
# Regex paires Gauche / Droite
|
| 498 |
-
# Supporte :
|
| 499 |
-
# Gauche 1066,5±67,8 Droite 1040,5±49,3
|
| 500 |
-
# ou variantes OCR/pdfplumber dégradées
|
| 501 |
-
# --------------------------------------------------
|
| 502 |
pair_pattern = re.compile(
|
| 503 |
r"Gauche\s+(\d+,\d+|\d+\.\d+|\d+)\s*(?:±|[–-])?\s*(\d+,\d+|\d+\.\d+|\d+)?"
|
| 504 |
r".{0,60}?"
|
|
@@ -517,18 +529,6 @@ def parse_zebris_pdf(uploaded_pdf):
|
|
| 517 |
except Exception:
|
| 518 |
pass
|
| 519 |
|
| 520 |
-
# Ordre attendu Zebris :
|
| 521 |
-
# 0 transition s
|
| 522 |
-
# 1 transition %
|
| 523 |
-
# 2 fore force
|
| 524 |
-
# 3 mid force
|
| 525 |
-
# 4 heel force
|
| 526 |
-
# 5 fore pressure
|
| 527 |
-
# 6 mid pressure
|
| 528 |
-
# 7 heel pressure
|
| 529 |
-
# 8 fore peak time
|
| 530 |
-
# 9 mid peak time
|
| 531 |
-
# 10 heel peak time
|
| 532 |
if len(values) >= 11:
|
| 533 |
data["transition_g"], data["transition_d"] = values[0]
|
| 534 |
|
|
|
|
| 453 |
def to_float(x):
|
| 454 |
return float(x.replace(",", ".").replace(" ", ""))
|
| 455 |
|
| 456 |
+
# --------------------------------------------------
|
| 457 |
+
# Lecture texte PDF robuste : pdfplumber puis PyPDF2
|
| 458 |
+
# --------------------------------------------------
|
| 459 |
+
page_texts = []
|
| 460 |
+
|
| 461 |
+
try:
|
| 462 |
+
with pdfplumber.open(io.BytesIO(raw)) as pdf:
|
| 463 |
+
for page in pdf.pages:
|
| 464 |
+
txt = page.extract_text() or ""
|
| 465 |
+
txt = txt.replace("\xa0", " ")
|
| 466 |
+
txt = re.sub(r"\s+", " ", txt).strip()
|
| 467 |
+
page_texts.append(txt)
|
| 468 |
+
except Exception:
|
| 469 |
+
try:
|
| 470 |
+
reader = PdfReader(io.BytesIO(raw))
|
| 471 |
+
for page in reader.pages:
|
| 472 |
+
txt = page.extract_text() or ""
|
| 473 |
+
txt = txt.replace("\xa0", " ")
|
| 474 |
+
txt = re.sub(r"\s+", " ", txt).strip()
|
| 475 |
+
page_texts.append(txt)
|
| 476 |
+
except Exception:
|
| 477 |
+
data["attaque_pdf"] = "indéterminée"
|
| 478 |
+
return data
|
| 479 |
|
| 480 |
full_text = " ".join(page_texts)
|
| 481 |
+
|
| 482 |
if not full_text.strip():
|
| 483 |
data["attaque_pdf"] = "indéterminée"
|
| 484 |
return data
|
|
|
|
| 485 |
|
| 486 |
+
# Nom athlète fallback
|
| 487 |
if not data["athlete_name"]:
|
| 488 |
data["athlete_name"] = extract_pdf_name(full_text, source_pdf=source_pdf)
|
| 489 |
|
| 490 |
+
# Allure PDF
|
| 491 |
+
data["speed_kmh"] = extract_speed_from_text(full_text)
|
| 492 |
+
|
| 493 |
# --------------------------------------------------
|
| 494 |
# Chercher la page utile Zebris
|
| 495 |
# --------------------------------------------------
|
|
|
|
| 511 |
zone_page_text = zone_page_text.replace("\xa0", " ")
|
| 512 |
zone_page_text = re.sub(r"\s+", " ", zone_page_text).strip()
|
| 513 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 514 |
pair_pattern = re.compile(
|
| 515 |
r"Gauche\s+(\d+,\d+|\d+\.\d+|\d+)\s*(?:±|[–-])?\s*(\d+,\d+|\d+\.\d+|\d+)?"
|
| 516 |
r".{0,60}?"
|
|
|
|
| 529 |
except Exception:
|
| 530 |
pass
|
| 531 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 532 |
if len(values) >= 11:
|
| 533 |
data["transition_g"], data["transition_d"] = values[0]
|
| 534 |
|