mannnon commited on
Commit
7bfc4d6
·
verified ·
1 Parent(s): b0ebdad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -144
app.py CHANGED
@@ -347,152 +347,72 @@ def parse_zebris_pdf(uploaded_pdf):
347
  "fore_peak_time_pct_d": np.nan,
348
  }
349
 
350
- # =========================
351
- # TRANSITION talon -> avant-pied (s)
352
- # =========================
353
- vals = find_float_after_label(
354
- text,
355
- "Instant du passage du talon vers\nl'avant-pied, s",
356
- max_numbers=2
357
- )
358
- if len(vals) >= 2:
359
- data["transition_g"], data["transition_d"] = vals[0], vals[1]
360
- else:
361
- vals = find_float_after_label(
362
- text,
363
- "Instant du passage du talon vers l'avant-pied, s",
364
- max_numbers=2
365
- )
366
- if len(vals) >= 2:
367
- data["transition_g"], data["transition_d"] = vals[0], vals[1]
368
-
369
- # =========================
370
- # FORCE maximale, N
371
- # =========================
372
- vals = find_float_after_label(text, "Force maximale, N\nForefoot (Three zones)", max_numbers=2)
373
- if len(vals) >= 2:
374
- data["fore_force_g"], data["fore_force_d"] = vals[0], vals[1]
375
- else:
376
- vals = find_float_after_label(text, "Forefoot (Three zones)", max_numbers=2)
377
- if len(vals) >= 2:
378
- data["fore_force_g"], data["fore_force_d"] = vals[0], vals[1]
379
-
380
- vals = find_float_after_label(text, "Midfoot (Three zones)", max_numbers=4)
381
- if len(vals) >= 2:
382
- # On prend les 2 premières valeurs trouvées après Midfoot
383
- data["mid_force_g"], data["mid_force_d"] = vals[0], vals[1]
384
-
385
- vals = find_float_after_label(text, "Heel (Three zones)", max_numbers=6)
386
- if len(vals) >= 2:
387
- # Sur cette zone, le mot Heel revient plusieurs fois dans la page.
388
- # Les 2 premières valeurs après le premier bloc correspondent bien ici aux forces.
389
- data["heel_force_g"], data["heel_force_d"] = vals[0], vals[1]
390
-
391
- # =========================
392
- # PRESSION maximale, N/cm²
393
- # =========================
394
- vals = find_float_after_label(text, "Pression maximale, N/cm²\nForefoot (Three zones)", max_numbers=2)
395
- if len(vals) >= 2:
396
- data["fore_pressure_g"], data["fore_pressure_d"] = vals[0], vals[1]
397
- else:
398
- # fallback plus tolérant : on repart de "Pression maximale"
399
- vals = find_float_after_label(text, "Pression maximale, N/cm²", max_numbers=8)
400
- # ordre attendu dans ce PDF :
401
- # fore G, fore D, mid G, mid D, heel G, heel D
402
- if len(vals) >= 6:
403
- data["fore_pressure_g"], data["fore_pressure_d"] = vals[0], vals[1]
404
- data["mid_pressure_g"], data["mid_pressure_d"] = vals[2], vals[3]
405
- data["heel_pressure_g"], data["heel_pressure_d"] = vals[4], vals[5]
406
-
407
- if pd.isna(data["mid_pressure_g"]):
408
- vals = find_float_after_label(text, "Pression maximale, N/cm²\nMidfoot (Three zones)", max_numbers=2)
409
- if len(vals) >= 2:
410
- data["mid_pressure_g"], data["mid_pressure_d"] = vals[0], vals[1]
411
-
412
- if pd.isna(data["heel_pressure_g"]):
413
- vals = find_float_after_label(text, "Pression maximale, N/cm²\nHeel (Three zones)", max_numbers=2)
414
- if len(vals) >= 2:
415
- data["heel_pressure_g"], data["heel_pressure_d"] = vals[0], vals[1]
416
-
417
- # =========================
418
- # TIMING pic de force, % phase d'appui
419
- # =========================
420
- vals = find_float_after_label(
421
- text,
422
- "Instant pic de force, % de phase d'appui\nForefoot (Three zones)",
423
- max_numbers=2
424
- )
425
- if len(vals) >= 2:
426
- data["fore_peak_time_pct_g"], data["fore_peak_time_pct_d"] = vals[0], vals[1]
427
- else:
428
- vals = find_float_after_label(text, "Instant pic de force, % de phase d'appui", max_numbers=8)
429
- # ordre attendu : fore G/D, mid G/D, heel G/D
430
- if len(vals) >= 6:
431
- data["fore_peak_time_pct_g"], data["fore_peak_time_pct_d"] = vals[0], vals[1]
432
- data["mid_peak_time_pct_g"], data["mid_peak_time_pct_d"] = vals[2], vals[3]
433
- data["heel_peak_time_pct_g"], data["heel_peak_time_pct_d"] = vals[4], vals[5]
434
-
435
- if pd.isna(data["mid_peak_time_pct_g"]):
436
- vals = find_float_after_label(
437
- text,
438
- "Instant pic de force, % de phase d'appui\nMidfoot (Three zones)",
439
- max_numbers=2
440
- )
441
- if len(vals) >= 2:
442
- data["mid_peak_time_pct_g"], data["mid_peak_time_pct_d"] = vals[0], vals[1]
443
-
444
- if pd.isna(data["heel_peak_time_pct_g"]):
445
- vals = find_float_after_label(
446
- text,
447
- "Instant pic de force, % de phase d'appui\nHeel (Three zones)",
448
- max_numbers=2
449
- )
450
- if len(vals) >= 2:
451
- data["heel_peak_time_pct_g"], data["heel_peak_time_pct_d"] = vals[0], vals[1]
452
-
453
- # =========================
454
- # FALLBACK spécial adapté à ton PDF page 8
455
- # =========================
456
- if (
457
- pd.isna(data["transition_g"]) or
458
- pd.isna(data["fore_force_g"]) or
459
- pd.isna(data["fore_pressure_g"]) or
460
- pd.isna(data["fore_peak_time_pct_g"])
461
- ):
462
- block_match = re.search(
463
- r"Instant du passage du talon vers.*?Heel \(Three zones\)\s+Gauche\s+Droite\s+(\d+,\d+|\d+\.\d+)\±.*?(\d+,\d+|\d+\.\d+)\±.*?"
464
- r"Force maximale, N.*?"
465
- r"Forefoot \(Three zones\)\s+Gauche\s+Droite\s+(\d+,\d+|\d+\.\d+)\±.*?(\d+,\d+|\d+\.\d+)\±.*?"
466
- r"Midfoot \(Three zones\)\s+Gauche\s+Droite\s+(\d+,\d+|\d+\.\d+)\±.*?(\d+,\d+|\d+\.\d+)\±.*?"
467
- r"Heel \(Three zones\)\s+Gauche\s+Droite\s+(\d+,\d+|\d+\.\d+)\±.*?(\d+,\d+|\d+\.\d+)\±.*?"
468
- r"Pression maximale, N/cm².*?"
469
- r"Forefoot \(Three zones\)\s+Gauche\s+Droite\s+(\d+,\d+|\d+\.\d+)\±.*?(\d+,\d+|\d+\.\d+)\±.*?"
470
- r"Midfoot \(Three zones\)\s+Gauche\s+Droite\s+(\d+,\d+|\d+\.\d+)\±.*?(\d+,\d+|\d+\.\d+)\±.*?"
471
- r"Heel \(Three zones\)\s+Gauche\s+Droite\s+(\d+,\d+|\d+\.\d+)\±.*?(\d+,\d+|\d+\.\d+)\±.*?"
472
- r"Instant pic de force, % de phase d'appui.*?"
473
- r"Forefoot \(Three zones\)\s+Gauche\s+Droite\s+(\d+,\d+|\d+\.\d+)\±.*?(\d+,\d+|\d+\.\d+)\±.*?"
474
- r"Midfoot \(Three zones\)\s+Gauche\s+Droite\s+(\d+,\d+|\d+\.\d+)\±.*?(\d+,\d+|\d+\.\d+)\±.*?"
475
- r"Heel \(Three zones\)\s+Gauche\s+Droite\s+(\d+,\d+|\d+\.\d+)\±.*?(\d+,\d+|\d+\.\d+)\±",
476
- text,
477
- flags=re.S
478
- )
479
-
480
- if block_match:
481
- vals = [float(x.replace(",", ".")) for x in block_match.groups()]
482
-
483
- data["transition_g"], data["transition_d"] = vals[0], vals[1]
484
-
485
- data["fore_force_g"], data["fore_force_d"] = vals[2], vals[3]
486
- data["mid_force_g"], data["mid_force_d"] = vals[4], vals[5]
487
- data["heel_force_g"], data["heel_force_d"] = vals[6], vals[7]
488
 
489
- data["fore_pressure_g"], data["fore_pressure_d"] = vals[8], vals[9]
490
- data["mid_pressure_g"], data["mid_pressure_d"] = vals[10], vals[11]
491
- data["heel_pressure_g"], data["heel_pressure_d"] = vals[12], vals[13]
492
 
493
- data["fore_peak_time_pct_g"], data["fore_peak_time_pct_d"] = vals[14], vals[15]
494
- data["mid_peak_time_pct_g"], data["mid_peak_time_pct_d"] = vals[16], vals[17]
495
- data["heel_peak_time_pct_g"], data["heel_peak_time_pct_d"] = vals[18], vals[19]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
496
 
497
  data["attaque_pdf"] = estimate_attack_from_pdf(data)
498
  return data
 
347
  "fore_peak_time_pct_d": np.nan,
348
  }
349
 
350
+ text_flat = re.sub(r"\s+", " ", text)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
351
 
352
+ def to_float(x):
353
+ return float(x.replace(",", "."))
 
354
 
355
+ # 1) Transition talon -> avant-pied (s)
356
+ m = re.search(
357
+ r"Instant du passage du talon vers l'avant-pied, s .*? Gauche .*? Droite .*? "
358
+ r"(\d+,\d+|\d+\.\d+)\±.*?(\d+,\d+|\d+\.\d+)\±",
359
+ text_flat,
360
+ flags=re.S
361
+ )
362
+ if m:
363
+ data["transition_g"] = to_float(m.group(1))
364
+ data["transition_d"] = to_float(m.group(2))
365
+
366
+ # 2) Force maximale, N
367
+ m = re.search(
368
+ r"Force maximale, N .*?"
369
+ r"Forefoot \(Three zones\) Gauche Droite (\d+,\d+|\d+\.\d+)\±.*?(\d+,\d+|\d+\.\d+)\±.*?"
370
+ r"Midfoot \(Three zones\) Gauche Droite (\d+,\d+|\d+\.\d+)\±.*?(\d+,\d+|\d+\.\d+)\±.*?"
371
+ r"Heel \(Three zones\) Gauche Droite (\d+,\d+|\d+\.\d+)\±.*?(\d+,\d+|\d+\.\d+)\±",
372
+ text_flat,
373
+ flags=re.S
374
+ )
375
+ if m:
376
+ data["fore_force_g"] = to_float(m.group(1))
377
+ data["fore_force_d"] = to_float(m.group(2))
378
+ data["mid_force_g"] = to_float(m.group(3))
379
+ data["mid_force_d"] = to_float(m.group(4))
380
+ data["heel_force_g"] = to_float(m.group(5))
381
+ data["heel_force_d"] = to_float(m.group(6))
382
+
383
+ # 3) Pression maximale, N/cm²
384
+ m = re.search(
385
+ r"Pression maximale, N/cm² .*?"
386
+ r"Forefoot \(Three zones\) Gauche Droite (\d+,\d+|\d+\.\d+)\±.*?(\d+,\d+|\d+\.\d+)\±.*?"
387
+ r"Midfoot \(Three zones\) Gauche Droite (\d+,\d+|\d+\.\d+)\±.*?(\d+,\d+|\d+\.\d+)\±.*?"
388
+ r"Heel \(Three zones\) Gauche Droite (\d+,\d+|\d+\.\d+)\±.*?(\d+,\d+|\d+\.\d+)\±",
389
+ text_flat,
390
+ flags=re.S
391
+ )
392
+ if m:
393
+ data["fore_pressure_g"] = to_float(m.group(1))
394
+ data["fore_pressure_d"] = to_float(m.group(2))
395
+ data["mid_pressure_g"] = to_float(m.group(3))
396
+ data["mid_pressure_d"] = to_float(m.group(4))
397
+ data["heel_pressure_g"] = to_float(m.group(5))
398
+ data["heel_pressure_d"] = to_float(m.group(6))
399
+
400
+ # 4) Instant pic de force, % de phase d'appui
401
+ m = re.search(
402
+ r"Instant pic de force, % de phase d'appui .*?"
403
+ r"Forefoot \(Three zones\) Gauche Droite (\d+,\d+|\d+\.\d+)\±.*?(\d+,\d+|\d+\.\d+)\±.*?"
404
+ r"Midfoot \(Three zones\) Gauche Droite (\d+,\d+|\d+\.\d+)\±.*?(\d+,\d+|\d+\.\d+)\±.*?"
405
+ r"Heel \(Three zones\) Gauche Droite (\d+,\d+|\d+\.\d+)\±.*?(\d+,\d+|\d+\.\d+)\±",
406
+ text_flat,
407
+ flags=re.S
408
+ )
409
+ if m:
410
+ data["fore_peak_time_pct_g"] = to_float(m.group(1))
411
+ data["fore_peak_time_pct_d"] = to_float(m.group(2))
412
+ data["mid_peak_time_pct_g"] = to_float(m.group(3))
413
+ data["mid_peak_time_pct_d"] = to_float(m.group(4))
414
+ data["heel_peak_time_pct_g"] = to_float(m.group(5))
415
+ data["heel_peak_time_pct_d"] = to_float(m.group(6))
416
 
417
  data["attaque_pdf"] = estimate_attack_from_pdf(data)
418
  return data