# utils/io_utils.py import uuid import json import time from datetime import datetime, timezone from pathlib import Path from config import OUTPUTS_DIR def unique_run_dir(stem: str) -> Path: ts = datetime.now(timezone.utc).strftime("%Y%m%dT%H%M%SZ") return OUTPUTS_DIR / f"{stem}_{ts}_{uuid.uuid4().hex[:8]}" def save_json(path: Path, data: dict): with open(path, "w", encoding="utf-8") as f: json.dump(data, f, ensure_ascii=False, indent=2) def build_metrics(file_name: str, n_pages: int, n_tables: int, per_page_counts: dict, start_time: float) -> dict: return { "file": file_name, "n_pages": n_pages, "n_tables": n_tables, "tables_per_page": per_page_counts, "processing_seconds": round(time.time() - start_time, 3), "errors": [] }