#!/bin/bash # -*- coding: utf-8 -*- # AIM智能体系统分析工具自动化脚本 # 用法: ./run_analysis.sh results/results0902 # # Author: ycz copilot # 移除set -e,改为手动错误处理 # set -e # 颜色定义 RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color print_info() { echo -e "${BLUE}[INFO]${NC} $1"; } print_success() { echo -e "${GREEN}[SUCCESS]${NC} $1"; } print_warning() { echo -e "${YELLOW}[WARNING]${NC} $1"; } print_error() { echo -e "${RED}[ERROR]${NC} $1"; } # 检查参数 if [ $# -eq 0 ]; then print_error "请提供数据目录路径" echo "用法: $0 " echo "示例: $0 results/results0902" exit 1 fi RESULTS_DIR=$1 OUTPUT_DIR="analysis/$(basename ${RESULTS_DIR} | sed 's/results//')" print_info "开始运行AIM智能体系统分析..." print_info "数据目录: ${RESULTS_DIR}" print_info "输出目录: ${OUTPUT_DIR}" # 检查数据目录 if [ ! -d "${RESULTS_DIR}" ]; then print_error "数据目录不存在: ${RESULTS_DIR}" exit 1 fi # 检查是否存在.jsonl文件 if [ -z "$(ls -A ${RESULTS_DIR}/*.jsonl 2>/dev/null)" ]; then print_error "数据目录中没有找到.jsonl文件: ${RESULTS_DIR}" exit 1 fi # 创建输出目录 mkdir -p "${OUTPUT_DIR}" # 检查并安装依赖 print_info "检查Python依赖包..." for package in matplotlib numpy; do if ! uv run python -c "import $package" 2>/dev/null; then print_info "安装缺失的依赖包: $package" uv add "$package" fi done # 运行分析脚本的函数 run_script() { local script=$1 local name=$(basename "$script" .py) print_info "运行: ${name}" # 执行Python脚本,捕获错误但继续运行 print_info "执行命令: uv run python analysis/${script} ${RESULTS_DIR} ${OUTPUT_DIR}" # 使用临时变量存储退出状态 local exit_code=0 uv run python "analysis/${script}" "${RESULTS_DIR}" "${OUTPUT_DIR}" || exit_code=$? if [ $exit_code -eq 0 ]; then print_success "${name} 执行成功" return 0 else print_error "${name} 执行失败 (退出码: $exit_code)" return 1 fi } # 主执行流程 print_info "===============================================" print_info "AIM智能体系统自动化分析工具" print_info "===============================================" success=0 total=0 # 1. 首先运行完成度检查(预处理步骤) print_info "==========================================" print_info "步骤1: 检查工作流完成度" print_info "==========================================" if uv run python "analysis/workflow_completeness_checker.py" "${RESULTS_DIR}" "${OUTPUT_DIR}"; then print_success "工作流完成度检查成功" else print_error "工作流完成度检查失败" exit 1 fi print_info "" print_info "==========================================" print_info "步骤2: 运行分析脚本(仅处理完成的文件)" print_info "==========================================" # 要运行的分析脚本列表 scripts=( "medical_workflow_analysis.py" "evaluate_metrics_analysis.py" "triage_accuracy_analysis.py" "extract_error_cases.py" "failed_tasks_analyzer.py" ) # 运行各个分析脚本 for script in "${scripts[@]}"; do if [ -f "analysis/${script}" ]; then print_info "----------------------------------------" print_info "准备执行脚本: ${script}" ((total++)) if run_script "$script"; then ((success++)) print_info "脚本 ${script} 执行完成" else print_error "脚本 ${script} 执行失败" fi else print_warning "脚本不存在: analysis/${script}" fi done print_info "----------------------------------------" print_info "分析完成: 成功 ${success}/${total} 个脚本" if [ $success -eq $total ] && [ $total -gt 0 ]; then print_success "所有分析脚本执行成功!" elif [ $success -gt 0 ]; then print_warning "部分分析脚本执行成功 (${success}/${total})" else print_error "所有分析脚本执行失败" fi if [ $success -gt 0 ]; then print_info "分析结果已保存到: ${OUTPUT_DIR}" if [ -d "${OUTPUT_DIR}" ]; then print_info "生成的文件:" find "${OUTPUT_DIR}" -type f \( -name "*.png" -o -name "*.json" -o -name "*.csv" -o -name "*.md" -o -name "*.txt" \) | sort | sed 's|.*/| - |' fi else print_error "未生成任何分析结果" fi print_success "AIM智能体系统分析完成!"