big refactor

This commit is contained in:
Nicolas Predella 2026-10-15 14:13:28 +03:00
parent 8099c5eba8
commit 1b763fc11c
3 changed files with 0 additions and 74 deletions

View file

@ -1,37 +0,0 @@
"""
SA2 Performance Profiling & Vector Edge Debug Export Module.
Saves input vector edge debug data and cProfile statistics when debug_sa2 is enabled.
"""
from typing import Any
import numpy as np
from numpy.typing import NDArray
def save_sa2_debug_data(
edges: NDArray[np.float64] | None,
obj_name: str,
filepath: str | Any
) -> None:
"""
Saves debug edge vector data files in the same folder as the output PDF:
- {name}_sa2_debug_edges.txt (Input 2D edge vector coordinates fed to SA2)
"""
if filepath is None:
return
from pathlib import Path
pdf_path = Path(filepath)
out_dir = pdf_path.parent
out_dir.mkdir(parents=True, exist_ok=True)
clean_name = pdf_path.stem if pdf_path.suffix.lower() == ".pdf" else str(obj_name)
base_prefix = out_dir / f"{clean_name}_sa2_debug"
# Save input edge coordinates as text file
if edges is not None and len(edges) > 0:
txt_file = f"{base_prefix}_edges.txt"
with open(txt_file, "w") as f:
f.write(f"# SA2 Input 2D Edges Debug for {clean_name}\n")
f.write(f"# Format: x1 y1 x2 y2\n")
for segment in edges:
(x1, y1), (x2, y2) = segment[0], segment[1]
f.write(f"{x1:.4f} {y1:.4f} {x2:.4f} {y2:.4f}\n")

View file

@ -1,24 +0,0 @@
from functools import lru_cache
import csv
import os
@lru_cache(maxsize=128)
def _load_csv(filename: str, mtime: float, encoding: str | None = None) -> tuple[tuple[str, ...], ...]:
with open(filename, 'r', newline='', encoding=encoding) as f:
reader = csv.reader(f)
return tuple(tuple(row) for row in reader)
def parse_csv_to_tuples(filename: str) -> list[tuple[str, ...]]:
current_mtime = os.path.getmtime(filename)
data: tuple[tuple[str, ...], ...] = _load_csv(filename, current_mtime)
return sorted(data, key=lambda x: x[1])
def parse_csv_to_dict(filename: str) -> dict[str, list[str]]:
current_mtime = os.path.getmtime(filename)
data: tuple[tuple[str, ...], ...] = _load_csv(filename, current_mtime, encoding='utf-8-sig')
result = {}
for row in data:
if row:
result[row[0]] = list(row[1:])
return result

View file

@ -1,13 +0,0 @@
import os, json
def dict_from_json(path):
with open(path, 'r') as file:
return json.load(file)
def dump_dict_to_json(dictionary, path):
folder = os.path.dirname(path)
if folder and not os.path.exists(folder):
os.makedirs(folder, exist_ok=True)
with open(path, 'w') as file:
json.dump(dictionary, file, indent=2)