Download data/processed/RQ1/BookWriter-A2A/evaluate_success.py from AINativeOps/AINativeBench: direct link, hf CLI and curl.
- Browser
- Download file 7.89 kB
-
https://huggingface.co/datasets/AINativeOps/AINativeBench/resolve/main/data/processed/RQ1/BookWriter-A2A/evaluate_success.py
- Command line
-
hf download hf://datasets/AINativeOps/AINativeBench/data/processed/RQ1/BookWriter-A2A/evaluate_success.py
-
curl -L -o evaluate_success.py https://huggingface.co/datasets/AINativeOps/AINativeBench/resolve/main/data/processed/RQ1/BookWriter-A2A/evaluate_success.py
7.89 kB
| #!/usr/bin/env python3 | |
| """ | |
| Compute success rate for each model on the BookWriter-A2A task. | |
| Success criteria: | |
| 1. A `chapters` folder exists | |
| 2. The `chapters` folder contains at least one `.md` file | |
| 3. The session root contains a main book `.md` file | |
| """ | |
| import json | |
| import os | |
| from pathlib import Path | |
| from collections import defaultdict | |
| # Base path and model list | |
| 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 = "BookWriter-A2A" | |
| def check_session_success(session_dir: Path) -> dict: | |
| """Check whether a single session is successful. | |
| Returns: | |
| { | |
| "success": bool, | |
| "has_chapters_folder": bool, | |
| "has_main_md": bool, | |
| "chapter_count": int, | |
| "chapter_files": list, | |
| "main_md_file": str or None, | |
| } | |
| """ | |
| result = { | |
| "success": False, | |
| "has_chapters_folder": False, | |
| "has_main_md": False, | |
| "chapter_count": 0, | |
| "chapter_files": [], | |
| "main_md_file": None, | |
| } | |
| # Check chapters folder | |
| chapters_dir = session_dir / "chapters" | |
| if chapters_dir.exists() and chapters_dir.is_dir(): | |
| result["has_chapters_folder"] = True | |
| # Count .md files in chapters | |
| chapter_files = sorted(chapters_dir.glob("*.md")) | |
| result["chapter_count"] = len(chapter_files) | |
| result["chapter_files"] = [f.name for f in chapter_files] | |
| # Check the main book .md file in session root (exclude execution_path.md) | |
| md_files = [f for f in session_dir.glob("*.md") if f.name != "execution_path.md"] | |
| if md_files: | |
| result["has_main_md"] = True | |
| result["main_md_file"] = md_files[0].name | |
| # Success criteria: chapters folder exists AND at least 1 chapter file | |
| result["success"] = result["has_chapters_folder"] and result["chapter_count"] > 0 | |
| 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"⚠️ test_results directory not found for model {model}: {test_results_dir}" | |
| ) | |
| continue | |
| model_stats = { | |
| "success_count": 0, | |
| "failure_count": 0, | |
| "total_count": 0, | |
| "avg_chapters": 0, | |
| "sessions": [], | |
| } | |
| total_chapters = 0 | |
| # Iterate all session subfolders | |
| for session_dir in sorted(test_results_dir.iterdir()): | |
| if not session_dir.is_dir(): | |
| continue | |
| # Check success | |
| check_result = check_session_success(session_dir) | |
| model_stats["total_count"] += 1 | |
| if check_result["success"]: | |
| model_stats["success_count"] += 1 | |
| total_chapters += check_result["chapter_count"] | |
| else: | |
| model_stats["failure_count"] += 1 | |
| model_stats["sessions"].append( | |
| { | |
| "session": session_dir.name, | |
| "success": check_result["success"], | |
| "has_chapters_folder": check_result["has_chapters_folder"], | |
| "has_main_md": check_result["has_main_md"], | |
| "chapter_count": check_result["chapter_count"], | |
| "chapter_files": check_result["chapter_files"], | |
| "main_md_file": check_result["main_md_file"], | |
| } | |
| ) | |
| # Compute average chapters (over successful sessions) | |
| if model_stats["success_count"] > 0: | |
| model_stats["avg_chapters"] = total_chapters / model_stats["success_count"] | |
| results[model] = model_stats | |
| return results | |
| def print_summary(results): | |
| """Print a summary.""" | |
| print("\n" + "=" * 80) | |
| print(f"Model Execution Summary - {PROJECT_NAME}") | |
| print("=" * 80 + "\n") | |
| print("Success criteria: chapters folder exists AND at least 1 chapter .md file\n") | |
| for model, stats in results.items(): | |
| total = stats["total_count"] | |
| success = stats["success_count"] | |
| failure = stats["failure_count"] | |
| avg_chapters = stats["avg_chapters"] | |
| if total > 0: | |
| success_rate = (success / total) * 100 | |
| print(f"📊 {model}") | |
| print(f" Total: {total}") | |
| print(f" Success: {success} ({success_rate:.1f}%)") | |
| print(f" Failure: {failure} ({100-success_rate:.1f}%)") | |
| if success > 0: | |
| print(f" Avg chapters: {avg_chapters:.1f}") | |
| print() | |
| else: | |
| print(f"📊 {model}") | |
| print(f" No data") | |
| print() | |
| print("=" * 80) | |
| def print_failure_details(results): | |
| """Print details for failed sessions.""" | |
| print("\n" + "=" * 80) | |
| print("Failure Details") | |
| print("=" * 80 + "\n") | |
| for model, stats in results.items(): | |
| failures = [s for s in stats["sessions"] if not s["success"]] | |
| if failures: | |
| print(f"📊 {model} - {len(failures)} failed sessions:") | |
| for session in failures[:5]: # only show first 5 | |
| print(f"\n 🔴 {session['session']}") | |
| print( | |
| f" - chapters folder: {'✅' if session['has_chapters_folder'] else '❌'}" | |
| ) | |
| print( | |
| f" - main .md file: {'✅' if session['has_main_md'] else '❌'} {session['main_md_file'] or ''}" | |
| ) | |
| print(f" - chapter count: {session['chapter_count']}") | |
| if session["chapter_files"]: | |
| print( | |
| f" - chapter files: {', '.join(session['chapter_files'][:3])}" | |
| ) | |
| if len(failures) > 5: | |
| print(f"\n ... and {len(failures) - 5} more failed sessions") | |
| print() | |
| def save_detailed_results(results, output_file="success_detailed_results.json"): | |
| """Save detailed results to a 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✅ Saved detailed results to: {output_path}") | |
| def save_csv_summary(results, output_file="success_rate.csv"): | |
| """Save a summary to a 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(%)", "Avg_Chapters"] | |
| ) | |
| 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 | |
| avg_chapters = stats["avg_chapters"] | |
| writer.writerow( | |
| [ | |
| model, | |
| total, | |
| success, | |
| failure, | |
| f"{success_rate:.2f}", | |
| f"{avg_chapters:.2f}", | |
| ] | |
| ) | |
| print(f"✅ Saved CSV summary to: {output_path}") | |
| if __name__ == "__main__": | |
| print(f"Starting success-rate analysis - {PROJECT_NAME}") | |
| print(f"Success criteria: chapters folder exists AND at least 1 chapter .md file\n") | |
| results = analyze_model_results() | |
| print_summary(results) | |
| print_failure_details(results) | |
| save_detailed_results(results) | |
| save_csv_summary(results) | |
| print("\n✅ Completed!") | |