get_statistics
Retrieve task completion rates and urgency distribution data to analyze productivity and workload patterns in your task management system.
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 and registration for 'get_statistics'. This async function is decorated with @mcp.tool(), making it the entry point for the tool, and delegates to TaskService.get_statistics().@mcp.tool() async def get_statistics() -> dict[str, Any]: """Get task statistics including completion rates and urgency distribution.""" return service.get_statistics()
- TaskService helper method that proxies the get_statistics call to the repository layer.def get_statistics(self) -> Dict[str, Any]: """Get task statistics.""" return self.repository.get_statistics()
- Core implementation of statistics computation in the repository. Queries the database for total tasks, completed tasks, completion rate, tasks by urgency level, and tasks with 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 }