"""Task Center statistics.""" from typing import Any class TaskStatistics: def summarize(self, tasks: list[dict[str, Any]] | None = None) -> dict[str, Any]: tasks = tasks or [] completed = [t for t in tasks if t.get("status") == "completed"] blocked = [t for t in tasks if t.get("status") == "blocked"] waiting = [t for t in tasks if t.get("status") == "waiting_approval"] elapsed = [t.get("elapsed_seconds", 0) for t in tasks if t.get("elapsed_seconds") is not None] return { "total": len(tasks), "completed": len(completed), "blocked": len(blocked), "waiting_approval": len(waiting), "completion_rate": round(len(completed) / len(tasks) * 100, 2) if tasks else 0, "average_elapsed_seconds": round(sum(elapsed) / len(elapsed), 2) if elapsed else 0, "top_blockers": self._top_values(blocked, "blocker"), "executor_distribution": self._top_values(tasks, "executor"), } def _top_values(self, tasks: list[dict[str, Any]], key: str): result: dict[str, int] = {} for task in tasks: value = task.get(key) if value: result[value] = result.get(value, 0) + 1 return result __all__ = ["TaskStatistics"]