get_statistics
Retrieve task statistics such as completion rates and urgency distribution to analyze task management efficiency. Part of DeltaTask MCP Server’s API for locally-hosted task systems.
Instructions
Get task statistics including completion rates and urgency distribution.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- server.py:71-74 (handler)MCP tool handler for 'get_statistics'. This is the entry point exposed via FastMCP, decorated with @mcp.tool(), which handles the tool execution by delegating to the TaskService.@mcp.tool() async def get_statistics() -> dict[str, Any]: """Get task statistics including completion rates and urgency distribution.""" return service.get_statistics()
- TaskService wrapper method for get_statistics, simply delegates to the repository.def get_statistics(self) -> Dict[str, Any]: """Get task statistics.""" return self.repository.get_statistics()
- Core implementation of get_statistics in the repository layer. Computes total tasks, completed count, completion rate, urgency distribution for incomplete tasks, and upcoming deadlines within a week.def get_statistics(self) -> Dict[str, Any]: """Get task statistics.""" with self.session_scope() as session: total = session.query(Todo).count() completed = session.query(Todo).filter(Todo.completed == True).count() # Count by urgency by_urgency = {} for urgency in range(1, 6): count = session.query(Todo).filter(Todo.completed == False, Todo.urgency == urgency).count() by_urgency[urgency] = count # Count upcoming deadlines from datetime import datetime today = datetime.now().date().isoformat() week_later = today.replace(today[:8], str(int(today[8:]) + 7)) upcoming_deadlines = session.query(Todo).filter( Todo.completed == False, Todo.deadline.between(today, week_later) ).count() return { "total": total, "completed": completed, "completion_rate": (completed / total * 100) if total > 0 else 0, "by_urgency": by_urgency, "upcoming_deadlines": upcoming_deadlines }