File size: 4,292 Bytes
8c10cf2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c4e7970
8c10cf2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/env python3
"""
Calculate success rates for each model in EmailResponder task
"""

import json
import os
from pathlib import Path
from collections import defaultdict

# Define 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",
]


def analyze_model_results():
    """Analyze execution results for each model"""
    results = {}

    for model in MODELS:
        test_results_dir = BASE_DIR / model / "EmailResponder" / "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,
            "sessions": [],
        }

        # Iterate through all session subdirectories
        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 reading {execution_log}: {e}")

        results[model] = model_stats

    return results


def print_summary(results):
    """Print statistical summary"""
    print("\n" + "=" * 80)
    print("Model Execution Results - EmailResponder")
    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} times")
            print(f"   Success: {success} times ({success_rate:.1f}%)")
            print(f"   Failure: {failure} times ({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✅ 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"✅ CSV summary saved to: {output_path}")


if __name__ == "__main__":
    results = analyze_model_results()
    print_summary(results)
    save_detailed_results(results)
    save_csv_summary(results)