File size: 818 Bytes
23bc040
3ab32c0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 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": []
    }