97 lines
3.4 KiB
Python
97 lines
3.4 KiB
Python
# core/summary.py
|
|
|
|
from core.result import ComicResult
|
|
|
|
_CORRUPT_PATTERNS = ("BadRarFile", "BadZipFile", "corrupto", "Failed to read")
|
|
_BORDER = "═" * 42
|
|
|
|
|
|
class SummaryCollector:
|
|
def __init__(self):
|
|
self._results: list[ComicResult] = []
|
|
|
|
def add(self, result: ComicResult) -> None:
|
|
self._results.append(result)
|
|
|
|
def _is_corrupt(self, result: ComicResult) -> bool:
|
|
all_errors = [e for s in result.steps for e in s.errors]
|
|
return any(
|
|
pattern in err
|
|
for err in all_errors
|
|
for pattern in _CORRUPT_PATTERNS
|
|
)
|
|
|
|
def render(self) -> str:
|
|
results = self._results
|
|
total = len(results)
|
|
if total == 0:
|
|
return ""
|
|
|
|
# Categorize
|
|
errors = [r for r in results if not r.ok() or r.final_path is None]
|
|
ok_results = [r for r in results if r.ok() and r.final_path is not None]
|
|
|
|
modified = [r for r in ok_results if any(s.changed for s in r.steps)]
|
|
warnings_only = [
|
|
r for r in ok_results
|
|
if not any(s.changed for s in r.steps) and r.has_issues()
|
|
]
|
|
no_changes = [
|
|
r for r in ok_results
|
|
if not any(s.changed for s in r.steps) and not r.has_issues()
|
|
]
|
|
|
|
corrupt = [r for r in errors if self._is_corrupt(r)]
|
|
other_errors = [r for r in errors if not self._is_corrupt(r)]
|
|
|
|
# Operation breakdown (among modified)
|
|
def count_step(step_names: list[str]) -> int:
|
|
return sum(
|
|
1 for r in modified
|
|
if any(s.step in step_names and s.changed for s in r.steps)
|
|
)
|
|
|
|
cleaned = count_step(["clean"])
|
|
pages_normalized = count_step(["normalize_pages"])
|
|
images_converted = count_step(["normalize_images", "convert_images"])
|
|
format_converted = count_step(["convert"])
|
|
|
|
lines = [
|
|
_BORDER,
|
|
" RESUMEN DEL PROCESAMIENTO",
|
|
_BORDER,
|
|
f" Total procesados : {total:>3}",
|
|
f" Sin cambios : {len(no_changes):>3}",
|
|
f" Modificados : {len(modified):>3}",
|
|
]
|
|
if modified:
|
|
if cleaned:
|
|
lines.append(f" · Limpiados : {cleaned:>3}")
|
|
if pages_normalized:
|
|
lines.append(f" · Páginas normalizadas : {pages_normalized:>3}")
|
|
if images_converted:
|
|
lines.append(f" · Imágenes convertidas : {images_converted:>3}")
|
|
if format_converted:
|
|
lines.append(f" · Formato convertido : {format_converted:>3}")
|
|
lines.append(f" Advertencias : {len(warnings_only):>3}")
|
|
lines.append(f" Errores : {len(errors):>3}")
|
|
if errors:
|
|
lines.append(f" · Corruptos : {len(corrupt):>3}")
|
|
lines.append(f" · Otros errores : {len(other_errors):>3}")
|
|
lines.append(_BORDER)
|
|
|
|
if corrupt:
|
|
lines.append("")
|
|
lines.append("Archivos corruptos:")
|
|
for r in corrupt:
|
|
lines.append(f" {r.original_path}")
|
|
|
|
if other_errors:
|
|
lines.append("")
|
|
lines.append("Otros errores:")
|
|
for r in other_errors:
|
|
all_errs = [e for s in r.steps for e in s.errors]
|
|
lines.append(f" {r.original_path} — {'; '.join(all_errs)}")
|
|
|
|
return "\n".join(lines)
|