analyze_robot_data
Analyze robot operational data to identify statistical patterns, trends, anomalies, and performance metrics for Universal Robots collaborative robots.
Instructions
分析机器人数据
参数:
- robot_id: 机器人ID
- analysis_type: 分析类型,可选值包括"statistical", "trend", "anomaly", "performance"
- start_time: 开始时间戳
- end_time: 结束时间戳
返回:
- 分析结果
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| robot_id | Yes | ||
| analysis_type | Yes | ||
| start_time | No | ||
| end_time | No |
Implementation Reference
- The handler function for the analyze_robot_data tool. Decorated with @mcp.tool() which registers it with the FastMCP server. Implements the core logic by loading robot data and performing analysis (statistical, trend, anomaly, performance) using the advanced_data_analyzer module.@mcp.tool() def analyze_robot_data(robot_id: str, analysis_type: str, start_time: float = None, end_time: float = None): """ 分析机器人数据 参数: - robot_id: 机器人ID - analysis_type: 分析类型,可选值包括"statistical", "trend", "anomaly", "performance" - start_time: 开始时间戳 - end_time: 结束时间戳 返回: - 分析结果 """ try: if advanced_data_analyzer is None: return return_msg("高级数据分析器未初始化") # 映射分析类型字符串到枚举值 type_map = { "statistical": AnalysisType.STATISTICAL, "trend": AnalysisType.TREND, "anomaly": AnalysisType.ANOMALY, "performance": AnalysisType.PERFORMANCE } if analysis_type not in type_map: return return_msg(f"不支持的分析类型: {analysis_type}") # 加载数据 df = advanced_data_analyzer.load_data( robot_id=robot_id, start_time=start_time, end_time=end_time ) if df.empty: return return_msg({"error": "未找到数据"}) # 执行分析 analysis_params = {} if analysis_type == "trend" and 'timestamp' in df.columns: # 对于趋势分析,使用时间戳作为x轴 numeric_columns = df.select_dtypes(include=['float64', 'int64']).columns.tolist() if numeric_columns and numeric_columns[0] != 'timestamp': analysis_params = {'x_column': 'timestamp', 'y_column': numeric_columns[0]} result = advanced_data_analyzer.analyze( df, type_map[analysis_type], analysis_params ) return return_msg({"analysis_type": analysis_type, "result": result}) except Exception as e: logger.error(f"分析机器人数据失败: {str(e)}") return return_msg(f"分析机器人数据失败: {str(e)}")