analyze_activity
Extracts and analyzes Strava activity data by activity ID, returning detailed insights in a structured format for integration and usage.
Instructions
Анализ активности из Strava
Args:
activity_id: ID активности (строка или число)
Returns:
dict: Результаты анализа активности
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| activity_id | Yes |
Implementation Reference
- src/server.py:336-375 (handler)Main handler function for the 'analyze_activity' tool. Fetches the Strava activity data and performs analysis including pace calculation, effort assessment, and stats extraction.@mcp.tool() def analyze_activity(activity_id: Union[str, int]) -> dict: """Анализ активности из Strava Args: activity_id: ID активности (строка или число) Returns: dict: Результаты анализа активности """ activity_id = str(activity_id) try: activity = get_activity(activity_id) # Calculate pace and zones pace = _calculate_pace(activity) effort = _calculate_effort(activity) return { "type": activity.get("type"), "distance": activity.get("distance"), "moving_time": activity.get("moving_time"), "average_heartrate": activity.get("average_heartrate"), "analysis": { "pace": pace, "effort": effort, "stats": { "elapsed_time": activity.get("elapsed_time"), "elevation_gain": activity.get("total_elevation_gain"), "calories": activity.get("calories"), } }, } except Exception as e: logger.error(f"Ошибка анализа активности {activity_id}: {e}") return { "error": f"Не удалось проанализировать активность: {str(e)}", "activity_id": activity_id }
- src/server.py:376-388 (helper)Helper function to compute pace: minutes per km for Run activities, km/h for Ride activities.def _calculate_pace(activity: dict) -> float: """Расчет темпа активности""" try: if activity.get("type") == "Run": # Для бега: мин/км return (activity.get("moving_time", 0) / 60) / (activity.get("distance", 0) / 1000) elif activity.get("type") == "Ride": # Для велосипеда: км/ч return (activity.get("distance", 0) / 1000) / (activity.get("moving_time", 0) / 3600) return 0 except (TypeError, ZeroDivisionError): return 0
- src/server.py:389-400 (helper)Helper function to categorize effort level based on average heart rate: Легкая (<120), Средняя (120-150), Высокая (>150).def _calculate_effort(activity: dict) -> str: """Оценка нагрузки""" if "average_heartrate" not in activity: return "Неизвестно" hr = activity["average_heartrate"] if hr < 120: return "Легкая" if hr < 150: return "Средняя" return "Высокая"