cropping summaries
This commit is contained in:
@@ -83,6 +83,26 @@ def process_copies(files: list[Path], staging: Path, workers: int) -> list[dict]
|
||||
key=lambda row: (order[row["file"]], row["page"]))
|
||||
|
||||
|
||||
def crop_statistics(records: list[dict]) -> tuple[int, float, int]:
|
||||
"""Return cropped page count, their mean removed percentage, and >30% count."""
|
||||
percentages: list[float] = []
|
||||
for record in records:
|
||||
removed_mm = record["top_removed_mm"] + record["bottom_removed_mm"]
|
||||
if removed_mm <= 0:
|
||||
continue
|
||||
x0, y0, x1, y1 = record["original_cropbox"]
|
||||
original_height_points = (
|
||||
x1 - x0 if record.get("rotation", 0) % 180 else y1 - y0
|
||||
)
|
||||
if original_height_points <= 0:
|
||||
continue
|
||||
original_height_mm = original_height_points * 25.4 / 72
|
||||
percentages.append(min(100.0, removed_mm / original_height_mm * 100))
|
||||
mean_percentage = sum(percentages) / len(percentages) if percentages else 0.0
|
||||
over_thirty = sum(percentage > 30 for percentage in percentages)
|
||||
return len(percentages), mean_percentage, over_thirty
|
||||
|
||||
|
||||
def run(workspace: EvaluationWorkspace, target: Path, *, workers: int = 5) -> ExitCode:
|
||||
if workers < 1:
|
||||
raise CliError("Le nombre de traitements parallèles doit être positif.",
|
||||
@@ -109,9 +129,14 @@ def run(workspace: EvaluationWorkspace, target: Path, *, workers: int = 5) -> Ex
|
||||
(backup/"report.json").write_text(json.dumps(records, ensure_ascii=False, indent=2),
|
||||
encoding="utf-8")
|
||||
print(f"Sauvegarde des PDF non rognés : {originals}", flush=True)
|
||||
cropped = sum(row["top_removed_mm"]+row["bottom_removed_mm"] > 0 for row in records)
|
||||
cropped, mean_percentage, over_thirty = crop_statistics(records)
|
||||
print(f"Terminé : {cropped}/{len(records)} pages rognées ; "
|
||||
f"{len(files)} PDF remplacés dans Copies.", flush=True)
|
||||
print(
|
||||
f"Rognage moyen des pages modifiées : {mean_percentage:.1f} % ; "
|
||||
f"{over_thirty} page(s) rognée(s) de plus de 30 %.",
|
||||
flush=True,
|
||||
)
|
||||
return ExitCode.SUCCESS
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user