一个功能完整的机器人日志智能分析平台,集成前后端 Web 服务、多种分析引擎和 AI 增强报告生成能力,支持任务识别、异常检测、投诉问题定位、历史追溯分析和可视化报告生成。
┌─────────────────────────────────────────────────────────────────┐
│ 用户界面层 │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ Web 前端 (HTML/CSS/JavaScript) │ │
│ │ - 仪表板、日志分析、报告查看、设置管理 │ │
│ └─────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ 后端服务层 │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ Flask REST API Server │ │
│ │ /api/status | /api/analyze | /api/reports | ... │ │
│ └─────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ 核心分析层 │
│ ┌───────────────┐ ┌───────────────┐ ┌───────────────────┐ │
│ │ 综合分析器 │ │ 投诉分析器 │ │ 历史追溯分析器 │ │
│ │ Comprehensive │ │ Complaint │ │ Historical Trace │ │
│ └───────────────┘ └───────────────┘ └───────────────────┘ │
│ ┌───────────────────────────────────────────────────────────┐ │
│ │ 报告生成器 (HTML/JSON/AI增强) │ │
│ │ EnhancedDetailedReportGenerator + DeepSeek AI │ │
│ └───────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ 外部服务层 │
│ ┌───────────────────────────────────────────────────────────┐ │
│ │ DeepSeek / OpenAI API (AI 智能分析增强) │ │
│ └───────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
- 🔍 任务阶段智能识别 - 自动识别任务开始/结束、充电、调试、地图维护等阶段
- 📍 位置数据分析 - 实时追踪机器人位置和运动轨迹
⚠️ 异常检测 - 传感器掉线、CPU高负载、机械故障、速度异常等检测- 📊 系统状态监控 - CPU、内存、电池、温度等系统指标分析
- 🛑 停机点精准定位 - 检测机器人异常停止位置和时间
- 🔎 根因分析 - 障碍物阻挡、导航失败、传感器故障等原因识别
- 📝 投诉场景匹配 - 自动匹配投诉描述与日志异常
- 💡 处理建议生成 - 基于分析结果给出解决方案
- 📅 任务序列追溯 - 追溯问题发生前的历史任务
- 📈 性能趋势分析 - 检测性能下降趋势和异常模式
- 🔗 跨任务关联 - 发现任务间的关联问题
- 🎯 根因指示器 - 识别潜在的根本原因指标
- 基础报告 (
report_generator.py) - 标准 HTML/JSON 报告 - 增强报告 (
enhanced_detailed_report_generator.py) - 可视化图表和详细分析 - AI增强报告 (
deepseek_enhanced_report_generator.py) - DeepSeek AI 智能分析建议
- 后端服务 (
backend/server.py) - Flask REST API 服务 - 前端界面 (
frontend/) - 响应式 Web 管理界面- 仪表板概览
- 日志分析控制台
- 报告查看器
- 系统设置管理
- Python: 3.7+
- 操作系统: macOS / Windows / Linux
- 可选: DeepSeek 或 OpenAI API Key (用于 AI 增强分析)
# 进入项目目录
cd log_reader
# 安装 Python 依赖
pip install -r requirements.txt# 启动后端服务 (默认端口 8080)
python backend/server.py
# 或使用启动脚本
python start_server.py打开浏览器访问: http://localhost:8080
# 测试系统功能
python test_system.py
# 测试 API 连接
python test_api_connection.pylog_reader/
├── 📁 backend/ # 后端服务
│ └── server.py # Flask Web 服务器
├── 📁 frontend/ # 前端界面
│ ├── index.html # 主页面
│ ├── script.js # 前端逻辑
│ └── styles.css # 样式表
├── 📁 logs/ # 日志文件目录 (输入)
│ ├── *.txt # 文本日志
│ ├── *.log # 标准日志
│ └── cartographer_node.* # Cartographer 日志
├── 📁 reports/ # 生成的报告 (输出)
├── 📁 temp_reports/ # 临时报告
├── 📁 reports_new/ # 新版报告
├── 📁 final_reports/ # 最终报告存档
│
├── 📄 核心分析模块
│ ├── comprehensive_robot_analyzer.py # 综合分析器 (728行)
│ ├── advanced_log_analyzer.py # 高级日志分析器 (585行)
│ ├── complaint_analyzer.py # 投诉分析器 (602行)
│ ├── historical_trace_analyzer.py # 历史追溯分析器 (626行)
│ └── complete_robot_log_analyzer.py # 分析器入口
│
├── 📄 报告生成模块
│ ├── report_generator.py # 基础报告生成器
│ ├── enhanced_report_generator.py # 增强报告生成器
│ ├── enhanced_detailed_report_generator.py # 详细增强报告 (677行)
│ ├── deepseek_enhanced_report_generator.py # AI增强报告 (1023行)
│ └── gpt_enhanced_report_generator.py # GPT增强报告
│
├── 📄 配置与入口
│ ├── config.py # 配置文件 (API/路径/参数)
│ ├── start_server.py # 服务启动脚本
│ ├── run_frontend.py # 前端启动脚本
│ └── requirements.txt # Python 依赖
│
├── 📄 测试文件
│ ├── test_system.py # 系统功能测试
│ ├── test_api_connection.py # API连接测试
│ ├── test_deepseek_connection.py # DeepSeek测试
│ └── test_*.py # 其他测试脚本
│
├── 📄 文档
│ ├── README.md # 项目说明 (本文件)
│ ├── architecture.md # 架构文档
│ ├── task.md # 任务规划
│ └── README_SECURITY.md # 安全说明
│
└── 📁 trickyuser/ # 扩展用户模块
├── logs/
└── src/
| 接口 | 方法 | 说明 |
|---|---|---|
/api/status |
GET | 系统状态检查 |
/api/test |
GET | API 连接测试 |
/api/logs |
GET | 获取日志文件列表 |
| 接口 | 方法 | 说明 |
|---|---|---|
/api/analyze |
POST | 执行日志分析 |
/api/reports |
GET | 获取报告列表 |
/api/report |
GET | 获取单个报告内容 |
| 接口 | 方法 | 说明 |
|---|---|---|
/api/settings |
GET | 获取当前设置 |
/api/settings |
POST | 更新设置 |
# 基础分析
curl -X POST http://localhost:8080/api/analyze \
-H "Content-Type: application/json" \
-d '{"log_directory": "./logs", "enable_ai": false, "report_type": "basic"}'
# 综合分析 (含AI增强)
curl -X POST http://localhost:8080/api/analyze \
-H "Content-Type: application/json" \
-d '{"log_directory": "./logs", "enable_ai": true, "report_type": "comprehensive"}'
# 带投诉时间的分析
curl -X POST http://localhost:8080/api/analyze \
-H "Content-Type: application/json" \
-d '{"log_directory": "./logs", "complaint_time": "2025-10-15 14:30:00"}'在 config.py 中配置或通过环境变量设置:
# 日志和报告路径
export LOG_DIRECTORY="./logs"
export REPORTS_DIRECTORY="./reports"
export TEMP_REPORTS_DIRECTORY="./temp_reports"
# OpenAI API (可选)
export OPENAI_API_KEY="sk-your-key"
export BASE_URL="https://api.openai.com/v1"
# DeepSeek API (可选,用于AI增强报告)
export DEEPSEEK_API_KEY="sk-your-deepseek-key"
export DEEPSEEK_BASE_URL="https://api.deepseek.com/v1"
export DEEPSEEK_MODEL="deepseek-chat"
export USE_DEEPSEEK="true"
# AI 请求参数
export MAX_TOKENS="1000"
export TEMPERATURE="0.7"
export REQUEST_TIMEOUT="30"import os
# 目录配置
LOG_DIRECTORY = os.getenv("LOG_DIRECTORY", "./logs")
REPORTS_DIRECTORY = os.getenv("REPORTS_DIRECTORY", "./reports")
TEMP_REPORTS_DIRECTORY = os.getenv("TEMP_REPORTS_DIRECTORY", "./temp_reports")
# AI API 配置
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
DEEPSEEK_API_KEY = os.getenv("DEEPSEEK_API_KEY")
USE_DEEPSEEK = os.getenv("USE_DEEPSEEK", "false").lower() == "true"
# 动态选择 API
API_KEY = DEEPSEEK_API_KEY if USE_DEEPSEEK else OPENAI_API_KEY# 基础综合分析
python comprehensive_robot_analyzer.py -d ./logs -o ./reports
# 投诉问题分析
python complaint_analyzer.py -d ./logs --complaint-time "2025-10-15 14:30:00"
# 历史追溯分析
python historical_trace_analyzer.py -d ./logs -o ./reports| 参数 | 说明 | 示例 |
|---|---|---|
-d, --directory |
日志目录路径 | -d ./logs |
-o, --output |
输出目录路径 | -o ./reports |
--complaint-time |
投诉时间点 | --complaint-time "2025-10-15 14:30:00" |
--analysis-type |
分析类型 | --analysis-type comprehensive |
basic- 基础分析comprehensive- 综合深度分析complaint- 投诉问题分析historical- 历史追溯分析deepseek_enhanced- AI增强分析
| 文件类型 | 格式 | 说明 |
|---|---|---|
comprehensive_report_*.json |
JSON | 综合分析数据 |
historical_trace_report_*.json |
JSON | 历史追溯数据 |
integrated_report_*.json |
JSON | 集成报告数据 |
enhanced_detailed_report_*.html |
HTML | 可视化详细报告 |
deepseek_enhanced_report_*.html |
HTML | AI增强可视化报告 |
{
"report_metadata": {
"report_id": "comprehensive_report_20251128_125145",
"generated_at": "2025-11-28T12:51:45",
"analysis_type": "comprehensive"
},
"analysis_summary": {
"total_log_files": 10,
"total_anomalies": 5,
"total_task_segments": 3
},
"task_segments": [...],
"anomalies": [...],
"recommendations": [...]
}- 📈 时间线可视化图表
- 📊 异常分布统计图
- 🗺️ 位置轨迹展示
- 💡 AI 智能建议 (如启用)
- 📱 响应式设计
from comprehensive_robot_analyzer import ComprehensiveRobotAnalyzer
analyzer = ComprehensiveRobotAnalyzer('./logs')
# 自定义任务识别模式
analyzer.task_patterns['custom_task'] = [
r'自定义任务模式',
r'custom.*task.*pattern'
]
# 自定义异常检测模式
analyzer.anomaly_patterns['custom_anomaly'] = [
r'自定义异常关键词',
r'custom.*error'
]
# 执行分析
analyzer.analyze_all_logs()
report = analyzer.generate_comprehensive_report()from enhanced_detailed_report_generator import EnhancedDetailedReportGenerator
class CustomReportGenerator(EnhancedDetailedReportGenerator):
def add_custom_section(self, data):
# 添加自定义报告章节
passfrom deepseek_enhanced_report_generator import DeepSeekEnhancedReportGenerator
generator = DeepSeekEnhancedReportGenerator(
analysis_report_path='./temp_reports/report.json',
api_key='your-api-key',
base_url='https://your-api-endpoint/v1'
)
generator.generate_detailed_report('./reports/ai_report.html')# 检查端口占用
lsof -i :8080
# 使用其他端口
python backend/server.py --port 9090# 升级 pip
pip install --upgrade pip
# 重新安装依赖
pip install -r requirements.txt --force-reinstall# 测试 DeepSeek 连接
python test_deepseek_connection.py
# 检查 API Key 配置
python -c "from config import DEEPSEEK_API_KEY; print(bool(DEEPSEEK_API_KEY))"- 确保日志文件为 UTF-8 编码
- 检查时间戳格式是否正确
import logging
logging.basicConfig(level=logging.DEBUG)
# 或在配置中启用
export FLASK_DEBUG=1- ✅ 完整的 Web 前后端系统
- ✅ DeepSeek AI 智能分析集成
- ✅ 增强版可视化 HTML 报告
- ✅ 响应式 Web 管理界面
- ✅ 多种分析器协同工作
- ✅ RESTful API 接口
- ✅ 核心日志分析功能
- ✅ 任务识别和异常检测
- ✅ 投诉分析和历史追溯
- ✅ 基础报告生成
本项目仅供学习和研究使用。
# 1. 克隆/下载项目
cd log_reader
# 2. 安装依赖
pip install -r requirements.txt
# 3. 启动服务
python backend/server.py
# 4. 打开浏览器访问
open http://localhost:8080🎉 开始探索机器人日志智能分析的世界!