feat: 优化数据分析页面,添加Excel工单导入功能
- 优化数据分析页面,添加可定制的图表功能 - 支持多种图表类型:折线图、柱状图、饼图、环形图、雷达图、极坐标图 - 添加图表定制功能:时间范围选择、数据维度选择 - 实现Excel工单导入功能,支持详情.xlsx文件 - 添加工单编辑功能,包括前端UI和后端API - 修复WebSocket连接错误,处理invalid Connection header问题 - 简化预警管理参数,改为卡片式选择 - 实现Agent主动调用,无需人工干预 - 改进知识库导入,结合累计工单内容与大模型输出
This commit is contained in:
@@ -13,6 +13,7 @@ import json
|
||||
|
||||
from src.main import TSPAssistant
|
||||
from src.agent import AgentCore, AgentState
|
||||
from src.agent.auto_monitor import AutoMonitorService
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -26,6 +27,9 @@ class TSPAgentAssistant(TSPAssistant):
|
||||
# 初始化Agent核心
|
||||
self.agent_core = AgentCore()
|
||||
|
||||
# 初始化自动监控服务
|
||||
self.auto_monitor = AutoMonitorService(self)
|
||||
|
||||
# Agent特有功能
|
||||
self.is_agent_mode = True
|
||||
self.proactive_tasks = []
|
||||
@@ -409,10 +413,13 @@ class TSPAgentAssistant(TSPAssistant):
|
||||
def get_agent_status(self) -> Dict[str, Any]:
|
||||
"""获取Agent状态"""
|
||||
try:
|
||||
# 获取自动监控状态
|
||||
monitor_status = self.auto_monitor.get_monitoring_status()
|
||||
|
||||
return {
|
||||
"success": True,
|
||||
"agent_mode": self.is_agent_mode,
|
||||
"monitoring_active": getattr(self, '_monitoring_active', False),
|
||||
"monitoring_active": monitor_status["is_running"],
|
||||
"status": "active" if self.is_agent_mode else "inactive",
|
||||
"active_goals": 0, # 简化处理
|
||||
"available_tools": 6, # 简化处理
|
||||
@@ -424,7 +431,8 @@ class TSPAgentAssistant(TSPAssistant):
|
||||
{"name": "analyze_data", "usage_count": 0, "success_rate": 0.8},
|
||||
{"name": "send_notification", "usage_count": 0, "success_rate": 0.8}
|
||||
],
|
||||
"execution_history": []
|
||||
"execution_history": [],
|
||||
"auto_monitor": monitor_status
|
||||
}
|
||||
except Exception as e:
|
||||
logger.error(f"获取Agent状态失败: {e}")
|
||||
@@ -456,11 +464,14 @@ class TSPAgentAssistant(TSPAssistant):
|
||||
# 启动基础监控
|
||||
self.start_monitoring()
|
||||
|
||||
# 启动Agent主动监控(同步版本)
|
||||
self._start_monitoring_loop()
|
||||
|
||||
logger.info("主动监控已启动")
|
||||
return True
|
||||
# 启动自动监控服务
|
||||
success = self.auto_monitor.start_auto_monitoring()
|
||||
if success:
|
||||
logger.info("主动监控已启动")
|
||||
return True
|
||||
else:
|
||||
logger.error("启动自动监控服务失败")
|
||||
return False
|
||||
except Exception as e:
|
||||
logger.error(f"启动主动监控失败: {e}")
|
||||
return False
|
||||
@@ -471,11 +482,14 @@ class TSPAgentAssistant(TSPAssistant):
|
||||
# 停止基础监控
|
||||
self.stop_monitoring()
|
||||
|
||||
# 停止Agent主动监控
|
||||
self._stop_monitoring_loop()
|
||||
|
||||
logger.info("主动监控已停止")
|
||||
return True
|
||||
# 停止自动监控服务
|
||||
success = self.auto_monitor.stop_auto_monitoring()
|
||||
if success:
|
||||
logger.info("主动监控已停止")
|
||||
return True
|
||||
else:
|
||||
logger.error("停止自动监控服务失败")
|
||||
return False
|
||||
except Exception as e:
|
||||
logger.error(f"停止主动监控失败: {e}")
|
||||
return False
|
||||
@@ -619,30 +633,38 @@ class TSPAgentAssistant(TSPAssistant):
|
||||
return ""
|
||||
|
||||
def _extract_knowledge_from_content(self, content: str, filename: str) -> List[Dict[str, Any]]:
|
||||
"""从内容中提取知识"""
|
||||
"""从内容中提取知识,结合工单数据优化"""
|
||||
try:
|
||||
# 构建提示词
|
||||
# 获取历史工单数据用于参考
|
||||
workorder_data = self._get_workorder_insights()
|
||||
|
||||
# 构建增强的提示词
|
||||
prompt = f"""
|
||||
请从以下文档内容中提取问答对,用于构建知识库:
|
||||
请从以下文档内容中提取问答对,用于构建知识库。请结合历史工单数据来优化提取结果:
|
||||
|
||||
文档名称:{filename}
|
||||
文档内容:
|
||||
{content[:2000]}...
|
||||
|
||||
历史工单数据参考:
|
||||
{workorder_data}
|
||||
|
||||
请按照以下格式提取问答对:
|
||||
1. 问题:具体的问题描述
|
||||
2. 答案:详细的答案内容
|
||||
1. 问题:具体的问题描述(参考工单中的常见问题)
|
||||
2. 答案:详细的答案内容(结合工单处理经验)
|
||||
3. 分类:问题所属类别(技术问题、APP功能、远程控制、车辆绑定、其他)
|
||||
4. 置信度:0-1之间的数值
|
||||
5. 工单关联:是否与历史工单相关
|
||||
|
||||
请提取3-5个最有价值的问答对,每个问答对都要完整且实用。
|
||||
请提取3-5个最有价值的问答对,优先提取与历史工单问题相关的问答对。
|
||||
返回格式为JSON数组,例如:
|
||||
[
|
||||
{{
|
||||
"question": "如何远程启动车辆?",
|
||||
"answer": "远程启动车辆需要满足以下条件:1. 车辆处于P档 2. 手刹拉起 3. 车门已锁 4. 电池电量充足",
|
||||
"answer": "远程启动车辆需要满足以下条件:1. 车辆处于P档 2. 手刹拉起 3. 车门已锁 4. 电池电量充足。如果仍然无法启动,请检查车辆是否处于可启动状态。",
|
||||
"category": "远程控制",
|
||||
"confidence_score": 0.9
|
||||
"confidence_score": 0.9,
|
||||
"workorder_related": true
|
||||
}}
|
||||
]
|
||||
"""
|
||||
@@ -700,6 +722,52 @@ class TSPAgentAssistant(TSPAssistant):
|
||||
logger.error(f"提取知识失败: {e}")
|
||||
return []
|
||||
|
||||
def _get_workorder_insights(self) -> str:
|
||||
"""获取工单数据洞察"""
|
||||
try:
|
||||
# 获取工单数据
|
||||
workorders = self.get_workorders()
|
||||
if not isinstance(workorders, list):
|
||||
return "暂无工单数据"
|
||||
|
||||
# 分析工单数据
|
||||
categories = {}
|
||||
common_issues = []
|
||||
resolutions = []
|
||||
|
||||
for workorder in workorders[:20]: # 取最近20个工单
|
||||
category = workorder.get("category", "其他")
|
||||
categories[category] = categories.get(category, 0) + 1
|
||||
|
||||
# 提取常见问题
|
||||
title = workorder.get("title", "")
|
||||
description = workorder.get("description", "")
|
||||
if title and len(title) > 5:
|
||||
common_issues.append(title)
|
||||
|
||||
# 提取解决方案(如果有)
|
||||
resolution = workorder.get("resolution", "")
|
||||
if resolution and len(resolution) > 10:
|
||||
resolutions.append(resolution[:100]) # 截取前100字符
|
||||
|
||||
# 构建工单洞察文本
|
||||
insights = f"""
|
||||
工单统计:
|
||||
- 总工单数:{len(workorders)}
|
||||
- 问题分类分布:{dict(list(categories.items())[:5])}
|
||||
|
||||
常见问题:
|
||||
{chr(10).join(common_issues[:10])}
|
||||
|
||||
解决方案示例:
|
||||
{chr(10).join(resolutions[:5])}
|
||||
"""
|
||||
return insights
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"获取工单洞察失败: {e}")
|
||||
return "获取工单数据失败"
|
||||
|
||||
def _parse_knowledge_manually(self, content: str) -> List[Dict[str, Any]]:
|
||||
"""手动解析知识内容"""
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user