82 lines
3.2 KiB
Python
82 lines
3.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""
|
|
CLI 入口 - 数据分析智能体
|
|
"""
|
|
|
|
import glob
|
|
import os
|
|
import sys
|
|
from datetime import datetime
|
|
|
|
from data_analysis_agent import DataAnalysisAgent
|
|
from config.llm_config import LLMConfig
|
|
from utils.create_session_dir import create_session_output_dir
|
|
from utils.logger import PrintCapture
|
|
|
|
|
|
def main():
|
|
llm_config = LLMConfig()
|
|
|
|
# 自动查找数据文件
|
|
data_extensions = ["*.csv", "*.xlsx", "*.xls"]
|
|
search_dirs = ["cleaned_data"]
|
|
files = []
|
|
|
|
for search_dir in search_dirs:
|
|
for ext in data_extensions:
|
|
pattern = os.path.join(search_dir, ext)
|
|
files.extend(glob.glob(pattern))
|
|
|
|
if not files:
|
|
print("[WARN] 未在 cleaned_data 目录找到数据文件,尝试使用默认文件")
|
|
files = ["./cleaned_data.csv"]
|
|
else:
|
|
print(f"[DIR] 自动识别到以下数据文件: {files}")
|
|
|
|
analysis_requirement = """
|
|
基于所有运维工单,整理一份工单健康度报告,包括但不限于对所有车联网技术支持工单的全面数据分析,
|
|
深入挖掘工单处理过程中的关键问题、效率瓶颈及改进机会。请从车型,模块,功能角度,分别展示工单数据、问题类型、模块分布、严重程度、责任人负载、车型分布、来源渠道及处理时长等多个维度。
|
|
通过多轮交叉分析与趋势洞察,为提升车联网服务质量、优化资源配置及降低运营风险提供数据驱动的决策依据,问题总揽,高频问题、重点问题分析,输出若干个重要的统计指标,并绘制相关图表;
|
|
结合图表,总结一份,车联网运维工单健康度报告,汇报给我。
|
|
"""
|
|
|
|
# 创建会话目录
|
|
base_output_dir = "outputs"
|
|
session_output_dir = create_session_output_dir(base_output_dir, analysis_requirement)
|
|
|
|
# 使用 PrintCapture 替代全局 stdout 劫持
|
|
log_path = os.path.join(session_output_dir, "log.txt")
|
|
|
|
with PrintCapture(log_path):
|
|
print(f"\n{'='*20} Run Started at {datetime.now().strftime('%Y-%m-%d %H:%M:%S')} {'='*20}\n")
|
|
print(f"[DOC] 日志文件已保存至: {log_path}")
|
|
|
|
agent = DataAnalysisAgent(llm_config, force_max_rounds=False)
|
|
|
|
# 交互式分析循环
|
|
while True:
|
|
is_first_run = agent.current_round == 0 and not agent.conversation_history
|
|
|
|
report = agent.analyze(
|
|
user_input=analysis_requirement,
|
|
files=files if is_first_run else None,
|
|
session_output_dir=session_output_dir,
|
|
reset_session=is_first_run,
|
|
max_rounds=None if is_first_run else 10,
|
|
)
|
|
print("\n" + "=" * 30 + " 当前阶段分析完成 " + "=" * 30)
|
|
|
|
print("\n[TIP] 你可以继续对数据提出分析需求,或者输入 'exit'/'quit' 结束程序。")
|
|
user_response = input("[>] 请输入后续分析需求 (直接回车退出): ").strip()
|
|
|
|
if not user_response or user_response.lower() in ["exit", "quit", "n", "no"]:
|
|
print("[BYE] 分析结束,再见!")
|
|
break
|
|
|
|
analysis_requirement = user_response
|
|
print(f"\n[LOOP] 收到新需求,正在继续分析...")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|