| |
| """ |
| Calculate success rates for each model on the EmailResponder-MCP task. |
| """ |
|
|
| import json |
| import os |
| from pathlib import Path |
| from collections import defaultdict |
|
|
| |
| BASE_DIR = Path("/Users/wzr/TOSEM-2025/RESULTS") |
| MODELS = [ |
| "DeepSeek-R1", |
| "DeepSeek-V3-1", |
| "GPT-4o-mini", |
| "GPT-5", |
| "Gemini-2.5-flash", |
| "Gemini-2.5-flash-nothinking", |
| "Qwen3-235b", |
| ] |
| PROJECT_NAME = "EmailResponder-MCP" |
|
|
|
|
| def analyze_model_results(): |
| """Analyze execution results for each model.""" |
| results = {} |
|
|
| for model in MODELS: |
| test_results_dir = BASE_DIR / model / PROJECT_NAME / "test_results" |
|
|
| if not test_results_dir.exists(): |
| print( |
| f"[WARN] test_results directory does not exist for model {model}: {test_results_dir}" |
| ) |
| continue |
|
|
| model_stats = { |
| "success_count": 0, |
| "failure_count": 0, |
| "total_count": 0, |
| "sessions": [], |
| } |
|
|
| |
| for session_dir in sorted(test_results_dir.iterdir()): |
| if not session_dir.is_dir(): |
| continue |
|
|
| execution_log = session_dir / "execution_log.json" |
| if not execution_log.exists(): |
| continue |
|
|
| try: |
| with open(execution_log, "r", encoding="utf-8") as f: |
| log_data = json.load(f) |
|
|
| success = log_data.get("success", False) |
| email_index = log_data.get("email_index", "unknown") |
|
|
| model_stats["total_count"] += 1 |
| if success: |
| model_stats["success_count"] += 1 |
| else: |
| model_stats["failure_count"] += 1 |
|
|
| model_stats["sessions"].append( |
| { |
| "session": session_dir.name, |
| "success": success, |
| "email_index": email_index, |
| "error": log_data.get("error"), |
| } |
| ) |
|
|
| except Exception as e: |
| print(f"[ERROR] Error reading {execution_log}: {e}") |
|
|
| results[model] = model_stats |
|
|
| return results |
|
|
|
|
| def print_summary(results): |
| """Print statistics summary.""" |
| print("\n" + "=" * 80) |
| print(f"Model Execution Results Statistics - {PROJECT_NAME}") |
| print("=" * 80 + "\n") |
|
|
| for model, stats in results.items(): |
| total = stats["total_count"] |
| success = stats["success_count"] |
| failure = stats["failure_count"] |
|
|
| if total > 0: |
| success_rate = (success / total) * 100 |
| print(f"{model}") |
| print(f" Total: {total} runs") |
| print(f" Success: {success} runs ({success_rate:.1f}%)") |
| print(f" Failure: {failure} runs ({100-success_rate:.1f}%)") |
| print() |
| else: |
| print(f"{model}") |
| print(f" No data") |
| print() |
|
|
| print("=" * 80) |
|
|
|
|
| def save_detailed_results(results, output_file="success-finish_detailed_results.json"): |
| """Save detailed results to JSON file.""" |
| output_path = Path(__file__).parent / output_file |
| with open(output_path, "w", encoding="utf-8") as f: |
| json.dump(results, f, indent=2, ensure_ascii=False) |
| print(f"\n[OK] Detailed results saved to: {output_path}") |
|
|
|
|
| def save_csv_summary(results, output_file="success-finish_rate.csv"): |
| """Save summary to CSV file.""" |
| import csv |
|
|
| output_path = Path(__file__).parent / output_file |
| with open(output_path, "w", newline="", encoding="utf-8") as f: |
| writer = csv.writer(f) |
| writer.writerow(["Model", "Total", "Success", "Failure", "Success_Rate(%)"]) |
|
|
| for model, stats in results.items(): |
| total = stats["total_count"] |
| success = stats["success_count"] |
| failure = stats["failure_count"] |
| success_rate = (success / total * 100) if total > 0 else 0 |
|
|
| writer.writerow([model, total, success, failure, f"{success_rate:.2f}"]) |
|
|
| print(f"[OK] CSV summary saved to: {output_path}") |
|
|
|
|
| if __name__ == "__main__": |
| results = analyze_model_results() |
| print_summary(results) |
| save_detailed_results(results) |
| save_csv_summary(results) |
|
|