| |
| """ |
| Calculate success rate for each model in RecruitmentAssistant-A2A task |
| Success criteria: reports folder exists and contains multiple (>=2) md files |
| """ |
|
|
| 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 = "RecruitmentAssistant-A2A" |
|
|
|
|
| def check_reports_success(reports_dir: Path) -> dict: |
| """ |
| Check if reports folder meets success criteria |
| |
| Success criteria: |
| 1. reports folder exists |
| 2. Contains multiple (>=2) md files |
| |
| Returns: |
| { |
| 'success': bool, |
| 'reports_exists': bool, |
| 'md_count': int, |
| 'md_files': list |
| } |
| """ |
| result = {"success": False, "reports_exists": False, "md_count": 0, "md_files": []} |
|
|
| |
| if not reports_dir.exists() or not reports_dir.is_dir(): |
| return result |
|
|
| result["reports_exists"] = True |
|
|
| |
| md_files = sorted([f.name for f in reports_dir.glob("*.md")]) |
| result["md_count"] = len(md_files) |
| result["md_files"] = md_files |
|
|
| |
| result["success"] = result["md_count"] >= 2 |
|
|
| return result |
|
|
|
|
| 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"⚠️ Model {model} test_results directory not found: {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 |
|
|
| reports_dir = session_dir / "reports" |
|
|
| |
| check_result = check_reports_success(reports_dir) |
|
|
| model_stats["total_count"] += 1 |
| if check_result["success"]: |
| model_stats["success_count"] += 1 |
| else: |
| model_stats["failure_count"] += 1 |
|
|
| model_stats["sessions"].append( |
| { |
| "session": session_dir.name, |
| "success": check_result["success"], |
| "reports_exists": check_result["reports_exists"], |
| "md_count": check_result["md_count"], |
| "md_files": check_result["md_files"], |
| } |
| ) |
|
|
| results[model] = model_stats |
|
|
| return results |
|
|
|
|
| def print_summary(results): |
| """Print statistics summary""" |
| print("\n" + "=" * 80) |
| print(f"Model Execution Results - {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} sessions") |
| print( |
| f" Success: {success} sessions (reports exists with >=2 md files, {success_rate:.1f}%)" |
| ) |
| print(f" Failure: {failure} sessions ({100-success_rate:.1f}%)") |
| print() |
| else: |
| print(f"📊 {model}") |
| print(f" No data") |
| print() |
|
|
| print("=" * 80) |
|
|
|
|
| def print_detailed_stats(results): |
| """Print detailed statistics""" |
| print("\n" + "=" * 80) |
| print("Detailed Statistics") |
| print("=" * 80 + "\n") |
|
|
| for model, stats in results.items(): |
| if stats["total_count"] == 0: |
| continue |
|
|
| print(f"### {model}") |
| print() |
|
|
| |
| md_count_dist = defaultdict(int) |
| for session in stats["sessions"]: |
| md_count_dist[session["md_count"]] += 1 |
|
|
| print(f"MD File Count Distribution:") |
| for count in sorted(md_count_dist.keys()): |
| sessions = md_count_dist[count] |
| percentage = (sessions / stats["total_count"]) * 100 |
| print(f" {count} files: {sessions} sessions ({percentage:.1f}%)") |
|
|
| |
| failed_sessions = [s for s in stats["sessions"] if not s["success"]] |
| if failed_sessions: |
| print(f"\nFailed sessions ({len(failed_sessions)} total):") |
| for session in failed_sessions[:5]: |
| reason = ( |
| "reports not found" |
| if not session["reports_exists"] |
| else f"only {session['md_count']} md files" |
| ) |
| print(f" - {session['session']}: {reason}") |
| if len(failed_sessions) > 5: |
| print(f" ... and {len(failed_sessions) - 5} more failed sessions") |
|
|
| print() |
|
|
| print("=" * 80) |
|
|
|
|
| def save_detailed_results(results, output_file="success_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✅ Detailed results saved to: {output_path}") |
|
|
|
|
| def save_csv_summary(results, output_file="success_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"✅ CSV summary saved to: {output_path}") |
|
|
|
|
| if __name__ == "__main__": |
| print(f"Starting success rate calculation - {PROJECT_NAME}") |
| print( |
| f"Success criteria: reports folder exists and contains multiple (>=2) md files\n" |
| ) |
|
|
| results = analyze_model_results() |
| print_summary(results) |
| print_detailed_stats(results) |
| save_detailed_results(results) |
| save_csv_summary(results) |
|
|
| print("\n✅ Calculation completed!") |
|
|