File size: 5,889 Bytes
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/usr/bin/env python3
import pandas as pd
import numpy as np
from pathlib import Path


def aggregate_llm_share():
    base_dir = Path(__file__).parent

    series_order = [
        (
            "Email Responder",
            ["EmailResponder", "EmailResponder-MCP"],
        ),
        (
            "Recruitment",
            [
                "RecruitmentAssistant-A2A",
                "RecruitmentAssistant-H_A2A",
                "RecruitmentAssistant-MCP",
            ],
        ),
        ("Markdown Val.", ["MarkdownValidator", "MarkdownValidator-MCP"]),
        ("Game Builder", ["GameBuilder", "GameBuilder-MCP"]),
        (
            "SQL Asst.",
            ["SQLAssistant-A2A", "SQLAssistant-H_A2A", "SQLAssistant-MCP"],
        ),
        (
            "Landing Pg.",
            [
                "LandingPageGenerator-A2A",
                "LandingPageGenerator-H_A2A",
                "LandingPageGenerator-MCP",
            ],
        ),
        (
            "Book Writer",
            [
                "BookWriter-A2A",
                "BookWriter-H_A2A",
                "BookWriter-MCP",
            ],
        ),
        (
            "Social M. M.",
            [
                "SocialMediaManager-A2A",
                "SocialMediaManager-H_A2A",
                "SocialMediaManager-MCP",
            ],
        ),
    ]

    projects = []
    csv_files = []

    project_to_display_name = {}

    for series_name, project_list in series_order:
        for project_name in project_list:
            project_dir = base_dir / project_name
            if project_dir.is_dir():
                csv_file = project_dir / "performance_breakdown_summary_by_model.csv"
                if csv_file.exists():
                    if "-A2A_mix" in project_name:
                        display_name = f"{series_name} (A2A_mix)"
                    elif "-A2A" in project_name:
                        display_name = f"{series_name} (A2A)"
                    elif "-MCP" in project_name:
                        display_name = f"{series_name} (MCP)"
                    else:
                        # Projects without a suffix are Pure CrewAI baselines
                        display_name = f"{series_name} (CrewAI)"

                    projects.append(project_name)
                    project_to_display_name[project_name] = display_name
                    csv_files.append(csv_file)
                else:
                    print(f"Warning: {project_name} missing CSV file")

    print(f"Found {len(projects)} projects with CSV files")

    models = [
        "GPT-5",
        "GPT-4o-mini",
        "DeepSeek-V3-1",
        "DeepSeek-R1",
        "Gemini-2.5-flash",
        "Gemini-2.5-flash-nothinking",
        "Qwen3-235b",
    ]

    data_dict = {model: [] for model in models}
    weight_dict = {model: [] for model in models}
    total_weighted_sum = 0.0
    total_weight = 0.0

    for project, csv_file in zip(projects, csv_files):
        try:
            df = pd.read_csv(csv_file)

            for model in models:
                model_data = df[df["model"] == model]
                if not model_data.empty:
                    llm_share = model_data["LLM_share"].values[0]
                    llm_share = min(llm_share, 1.0)
                    llm_share = round(llm_share, 4)
                    data_dict[model].append(llm_share)

                    comp_time = model_data["total_components_time"].values[0]
                    weight = float(comp_time) if pd.notna(comp_time) else 0.0
                    weight_dict[model].append(weight)

                    if pd.notna(llm_share) and weight > 0:
                        total_weighted_sum += llm_share * weight
                        total_weight += weight
                else:
                    data_dict[model].append(None)
                    weight_dict[model].append(0.0)
        except Exception as e:
            print(f"Error reading {csv_file}: {e}")
            for model in models:
                data_dict[model].append(None)
                weight_dict[model].append(0.0)

    result_df = pd.DataFrame(data_dict, index=projects)
    result_df.index = result_df.index.map(project_to_display_name)
    result_df.index.name = "Model"
    result_df = result_df.T

    # Time-weighted overall average across all models and projects
    overall_avg = (
        round(total_weighted_sum / total_weight, 4) if total_weight > 0 else np.nan
    )
    overall_row_name = "Overall Average (time-weighted, all models & projects)"
    overall_row = pd.Series(
        {col: overall_avg for col in result_df.columns}, name=overall_row_name
    )
    result_df = pd.concat([result_df, overall_row.to_frame().T])

    output_file = base_dir / "llm_share_summary.csv"
    result_df.to_csv(output_file, float_format="%.4f")
    print(f"\nCSV saved to: {output_file}")
    print(f"\nShape: {result_df.shape[0]} models × {result_df.shape[1]} projects")

    return result_df


def generate_latex_table(df):
    num_cols = len(df.columns)

    latex = []
    latex.append("\\begin{table*}[htbp]")
    latex.append("\\centering")
    latex.append("\\small")
    latex.append(f"\\begin{{tabular}}{{l{'c' * num_cols}}}")
    latex.append("\\toprule")

    header = "Model & " + " & ".join(df.columns) + " \\\\"
    latex.append(header)
    latex.append("\\midrule")

    for idx, row in df.iterrows():
        row_str = (
            str(idx)
            + " & "
            + " & ".join([f"{v:.4f}" if pd.notna(v) else "-" for v in row])
            + " \\\\"
        )
        latex.append(row_str)

    latex.append("\\bottomrule")
    latex.append("\\end{tabular}")
    latex.append("\\caption{LLM Share by Model and Project}")
    latex.append("\\label{tab:llm_share}")
    latex.append("\\end{table*}")

    return "\n".join(latex)


if __name__ == "__main__":
    aggregate_llm_share()