| |
| """ |
| Generate radar charts for evaluation results across different scenarios. |
| Creates one PDF radar chart per subfolder showing all models' performance. |
| """ |
|
|
| import pandas as pd |
| import numpy as np |
| from pathlib import Path |
| import math |
|
|
| try: |
| import matplotlib.pyplot as plt |
| import matplotlib as mpl |
| from matplotlib.patches import Circle |
|
|
| mpl.rcParams["font.family"] = "Times New Roman" |
| except ImportError: |
| plt = None |
| mpl = None |
| Circle = None |
|
|
| |
| METRICS = [ |
| "exact_match", |
| "any_order_match", |
| "precision", |
| "recall", |
| "retry_rate", |
| "pass_rate", |
| ] |
|
|
| |
| MODEL_COLORS = { |
| "GPT-5": "#1f77b4", |
| "GPT-4o-mini": "#ff7f0e", |
| "DeepSeek-V3-1": "#2ca02c", |
| "DeepSeek-R1": "#d62728", |
| "Gemini-2.5-flash": "#9467bd", |
| "Gemini-2.5-flash-nothinking": "#8c564b", |
| "Qwen3-235b": "#e377c2", |
| } |
|
|
| MODEL_CATEGORY = { |
| "GPT-5": "closed", |
| "GPT-4o-mini": "closed", |
| "DeepSeek-V3-1": "open", |
| "DeepSeek-R1": "open", |
| "Gemini-2.5-flash": "closed", |
| "Gemini-2.5-flash-nothinking": "closed", |
| "Qwen3-235b": "open", |
| } |
|
|
|
|
| def df_to_markdown(df): |
| """Convert a DataFrame to a simple markdown table without external deps.""" |
| headers = list(df.columns) |
| lines = [] |
| lines.append("| " + " | ".join(headers) + " |") |
| lines.append("| " + " | ".join(["---"] * len(headers)) + " |") |
| for _, row in df.iterrows(): |
| values = [] |
| for val in row: |
| if isinstance(val, float): |
| values.append(f"{val:.2f}") |
| else: |
| values.append(str(val)) |
| lines.append("| " + " | ".join(values) + " |") |
| return "\n".join(lines) |
|
|
|
|
| def metric_display_name(metric, base_project, gt_projects): |
| if metric == "pass_rate" and gt_projects and base_project in gt_projects: |
| return "average_score" |
| return metric |
|
|
|
|
| def series_metric_headers(series_name, gt_projects): |
| rate_label = ( |
| "average_score" if gt_projects and series_name in gt_projects else "pass_rate" |
| ) |
| return [(rate_label if m == "pass_rate" else m) for m in METRICS] |
|
|
|
|
| def generate_model_pair_comparison( |
| model_a, model_b, data_dict, comparison_name, gt_projects=None |
| ): |
| """Generate comparison table between two models across all scenarios.""" |
| lines = [] |
| lines.append(f"# {comparison_name}\n\n") |
|
|
| |
| project_series = {} |
| for scenario_name in data_dict.keys(): |
| |
| base_name = scenario_name |
| for suffix in ["-A2A_mix", "-A2A", "-MCP"]: |
| if scenario_name.endswith(suffix): |
| base_name = scenario_name[: -len(suffix)] |
| break |
|
|
| if base_name not in project_series: |
| project_series[base_name] = [] |
| project_series[base_name].append(scenario_name) |
|
|
| |
| series_data = {} |
| for base_name, scenarios in project_series.items(): |
| series_data[base_name] = {model_a: {}, model_b: {}} |
|
|
| for metric in METRICS: |
| vals_a = [] |
| vals_b = [] |
| for scenario_name in scenarios: |
| scenario_data = data_dict[scenario_name] |
| if model_a in scenario_data and model_b in scenario_data: |
| vals_a.append(scenario_data[model_a].get(metric, 0)) |
| vals_b.append(scenario_data[model_b].get(metric, 0)) |
|
|
| if vals_a and vals_b: |
| series_data[base_name][model_a][metric] = np.mean(vals_a) |
| series_data[base_name][model_b][metric] = np.mean(vals_b) |
|
|
| |
| overall_avgs = { |
| metric: {"a": [], "b": []} for metric in METRICS if metric != "pass_rate" |
| } |
| overall_rate_avgs = { |
| "gt": {"a": [], "b": []}, |
| "non_gt": {"a": [], "b": []}, |
| } |
| for base_name in series_data.keys(): |
| for metric in METRICS: |
| if ( |
| metric not in series_data[base_name][model_a] |
| or metric not in series_data[base_name][model_b] |
| ): |
| continue |
|
|
| if metric == "pass_rate": |
| bucket = "gt" if gt_projects and base_name in gt_projects else "non_gt" |
| overall_rate_avgs[bucket]["a"].append( |
| series_data[base_name][model_a][metric] |
| ) |
| overall_rate_avgs[bucket]["b"].append( |
| series_data[base_name][model_b][metric] |
| ) |
| continue |
|
|
| overall_avgs[metric]["a"].append(series_data[base_name][model_a][metric]) |
| overall_avgs[metric]["b"].append(series_data[base_name][model_b][metric]) |
|
|
| |
| lines.append("## Overall Summary (Averaged Across All Project Series)\n\n") |
| lines.append(f"| Metric | {model_a} | {model_b} | Diff (A-B) |\n") |
| lines.append("| --- | --- | --- | --- |\n") |
| for metric in METRICS: |
| if metric == "pass_rate": |
| if overall_rate_avgs["gt"]["a"]: |
| avg_a = np.mean(overall_rate_avgs["gt"]["a"]) |
| avg_b = np.mean(overall_rate_avgs["gt"]["b"]) |
| diff = avg_a - avg_b |
| lines.append( |
| f"| average_score | {avg_a:.2f} | {avg_b:.2f} | {diff:+.2f} |\n" |
| ) |
| if overall_rate_avgs["non_gt"]["a"]: |
| avg_a = np.mean(overall_rate_avgs["non_gt"]["a"]) |
| avg_b = np.mean(overall_rate_avgs["non_gt"]["b"]) |
| diff = avg_a - avg_b |
| lines.append( |
| f"| pass_rate | {avg_a:.2f} | {avg_b:.2f} | {diff:+.2f} |\n" |
| ) |
| continue |
|
|
| if overall_avgs[metric]["a"]: |
| avg_a = np.mean(overall_avgs[metric]["a"]) |
| avg_b = np.mean(overall_avgs[metric]["b"]) |
| diff = avg_a - avg_b |
| lines.append(f"| {metric} | {avg_a:.2f} | {avg_b:.2f} | {diff:+.2f} |\n") |
| lines.append("\n---\n\n") |
|
|
| |
| headers = ["Project Series", f"{model_a}", f"{model_b}", "Diff (A-B)"] |
|
|
| for metric in METRICS: |
| if metric != "pass_rate": |
| lines.append(f"## {metric}\n\n") |
| lines.append("| " + " | ".join(headers) + " |\n") |
| lines.append("| " + " | ".join(["---"] * len(headers)) + " |\n") |
|
|
| for base_name in sorted(series_data.keys()): |
| if ( |
| metric in series_data[base_name][model_a] |
| and metric in series_data[base_name][model_b] |
| ): |
| val_a = series_data[base_name][model_a][metric] |
| val_b = series_data[base_name][model_b][metric] |
| diff = val_a - val_b |
| lines.append( |
| f"| {base_name} | {val_a:.2f} | {val_b:.2f} | {diff:+.2f} |\n" |
| ) |
| lines.append("\n") |
| continue |
|
|
| lines.append("## average_score\n\n") |
| lines.append("| " + " | ".join(headers) + " |\n") |
| lines.append("| " + " | ".join(["---"] * len(headers)) + " |\n") |
| for base_name in sorted(series_data.keys()): |
| if gt_projects and base_name not in gt_projects: |
| continue |
| if ( |
| metric in series_data[base_name][model_a] |
| and metric in series_data[base_name][model_b] |
| ): |
| val_a = series_data[base_name][model_a][metric] |
| val_b = series_data[base_name][model_b][metric] |
| diff = val_a - val_b |
| lines.append( |
| f"| {base_name} | {val_a:.2f} | {val_b:.2f} | {diff:+.2f} |\n" |
| ) |
| lines.append("\n") |
|
|
| lines.append("## pass_rate\n\n") |
| lines.append("| " + " | ".join(headers) + " |\n") |
| lines.append("| " + " | ".join(["---"] * len(headers)) + " |\n") |
| for base_name in sorted(series_data.keys()): |
| if gt_projects and base_name in gt_projects: |
| continue |
| if ( |
| metric in series_data[base_name][model_a] |
| and metric in series_data[base_name][model_b] |
| ): |
| val_a = series_data[base_name][model_a][metric] |
| val_b = series_data[base_name][model_b][metric] |
| diff = val_a - val_b |
| lines.append( |
| f"| {base_name} | {val_a:.2f} | {val_b:.2f} | {diff:+.2f} |\n" |
| ) |
| lines.append("\n") |
|
|
| return "".join(lines) |
|
|
|
|
| def generate_mcp_comparison(base_project, scenario_data_dict, gt_projects=None): |
| """Generate comparison between MCP and hardcoded versions for a project.""" |
| lines = [] |
| lines.append(f"# {base_project}: MCP vs Hardcoded\n\n") |
|
|
| mcp_scenario = f"{base_project}-MCP" |
| hardcoded_scenario = base_project |
|
|
| if ( |
| mcp_scenario not in scenario_data_dict |
| or hardcoded_scenario not in scenario_data_dict |
| ): |
| lines.append(f"_Data not available for comparison_\n\n") |
| return "".join(lines) |
|
|
| mcp_data = scenario_data_dict[mcp_scenario] |
| hardcoded_data = scenario_data_dict[hardcoded_scenario] |
|
|
| all_models = set(mcp_data.keys()) | set(hardcoded_data.keys()) |
|
|
| |
| overall_avgs = {metric: {"mcp": [], "hard": []} for metric in METRICS} |
| for model in all_models: |
| for metric in METRICS: |
| mcp_val = mcp_data.get(model, {}).get(metric, 0) |
| hard_val = hardcoded_data.get(model, {}).get(metric, 0) |
| overall_avgs[metric]["mcp"].append(mcp_val) |
| overall_avgs[metric]["hard"].append(hard_val) |
|
|
| |
| lines.append("## Overall Summary (Averaged Across All Models)\n\n") |
| lines.append("| Metric | MCP | Hardcoded | Diff (MCP-Hardcoded) |\n") |
| lines.append("| --- | --- | --- | --- |\n") |
| for metric in METRICS: |
| if overall_avgs[metric]["mcp"]: |
| avg_mcp = np.mean(overall_avgs[metric]["mcp"]) |
| avg_hard = np.mean(overall_avgs[metric]["hard"]) |
| diff = avg_mcp - avg_hard |
| display_metric = metric_display_name(metric, base_project, gt_projects) |
| lines.append( |
| f"| {display_metric} | {avg_mcp:.2f} | {avg_hard:.2f} | {diff:+.2f} |\n" |
| ) |
| lines.append("\n---\n\n") |
|
|
| for metric in METRICS: |
| display_metric = metric_display_name(metric, base_project, gt_projects) |
| lines.append(f"## {display_metric}\n\n") |
| headers = ["Model", "MCP", "Hardcoded", "Diff (MCP-Hardcoded)"] |
| lines.append("| " + " | ".join(headers) + " |\n") |
| lines.append("| " + " | ".join(["---"] * len(headers)) + " |\n") |
|
|
| for model in sorted(all_models): |
| mcp_val = mcp_data.get(model, {}).get(metric, 0) |
| hard_val = hardcoded_data.get(model, {}).get(metric, 0) |
| diff = mcp_val - hard_val |
| lines.append( |
| f"| {model} | {mcp_val:.2f} | {hard_val:.2f} | {diff:+.2f} |\n" |
| ) |
| lines.append("\n") |
|
|
| return "".join(lines) |
|
|
|
|
| def generate_mcp_overall_comparison(projects, scenario_data_dict, gt_projects=None): |
| """Generate overall comparison across all MCP vs hardcoded projects.""" |
| lines = [] |
| lines.append("# Overall MCP vs Hardcoded Comparison\n\n") |
| lines.append( |
| "Averaged across all projects: MarkdownValidator, GameBuilder, EmailResponder\n\n" |
| ) |
|
|
| |
| overall_data = {} |
| framework_data = { |
| metric: {"mcp": [], "hard": []} for metric in METRICS if metric != "pass_rate" |
| } |
| framework_rate_data = { |
| "gt": {"mcp": [], "hard": []}, |
| "non_gt": {"mcp": [], "hard": []}, |
| } |
| overall_rate_data = {} |
|
|
| for project in projects: |
| mcp_scenario = f"{project}-MCP" |
| hardcoded_scenario = project |
|
|
| if ( |
| mcp_scenario not in scenario_data_dict |
| or hardcoded_scenario not in scenario_data_dict |
| ): |
| continue |
|
|
| mcp_data = scenario_data_dict[mcp_scenario] |
| hardcoded_data = scenario_data_dict[hardcoded_scenario] |
|
|
| all_models = set(mcp_data.keys()) | set(hardcoded_data.keys()) |
| project_bucket = "gt" if gt_projects and project in gt_projects else "non_gt" |
|
|
| for model in all_models: |
| if model not in overall_data: |
| overall_data[model] = { |
| metric: {"mcp": [], "hard": []} |
| for metric in METRICS |
| if metric != "pass_rate" |
| } |
| if model not in overall_rate_data: |
| overall_rate_data[model] = { |
| "gt": {"mcp": [], "hard": []}, |
| "non_gt": {"mcp": [], "hard": []}, |
| } |
|
|
| for metric in METRICS: |
| mcp_val = mcp_data.get(model, {}).get(metric, 0) |
| hard_val = hardcoded_data.get(model, {}).get(metric, 0) |
| if metric == "pass_rate": |
| overall_rate_data[model][project_bucket]["mcp"].append(mcp_val) |
| overall_rate_data[model][project_bucket]["hard"].append(hard_val) |
| framework_rate_data[project_bucket]["mcp"].append(mcp_val) |
| framework_rate_data[project_bucket]["hard"].append(hard_val) |
| else: |
| overall_data[model][metric]["mcp"].append(mcp_val) |
| overall_data[model][metric]["hard"].append(hard_val) |
| framework_data[metric]["mcp"].append(mcp_val) |
| framework_data[metric]["hard"].append(hard_val) |
|
|
| |
| lines.append("## Framework-Level Comparison (All Models Averaged)\n\n") |
| lines.append("| Metric | MCP | Hardcoded | Diff (MCP-Hardcoded) |\n") |
| lines.append("| --- | --- | --- | --- |\n") |
| for metric in METRICS: |
| if metric == "pass_rate": |
| if framework_rate_data["gt"]["mcp"]: |
| avg_mcp = np.mean(framework_rate_data["gt"]["mcp"]) |
| avg_hard = np.mean(framework_rate_data["gt"]["hard"]) |
| diff = avg_mcp - avg_hard |
| lines.append( |
| f"| average_score | {avg_mcp:.2f} | {avg_hard:.2f} | {diff:+.2f} |\n" |
| ) |
| if framework_rate_data["non_gt"]["mcp"]: |
| avg_mcp = np.mean(framework_rate_data["non_gt"]["mcp"]) |
| avg_hard = np.mean(framework_rate_data["non_gt"]["hard"]) |
| diff = avg_mcp - avg_hard |
| lines.append( |
| f"| pass_rate | {avg_mcp:.2f} | {avg_hard:.2f} | {diff:+.2f} |\n" |
| ) |
| continue |
|
|
| if framework_data[metric]["mcp"]: |
| avg_mcp = np.mean(framework_data[metric]["mcp"]) |
| avg_hard = np.mean(framework_data[metric]["hard"]) |
| diff = avg_mcp - avg_hard |
| lines.append( |
| f"| {metric} | {avg_mcp:.2f} | {avg_hard:.2f} | {diff:+.2f} |\n" |
| ) |
| lines.append("\n---\n\n") |
|
|
| |
| for metric in METRICS: |
| if metric != "pass_rate": |
| lines.append(f"## {metric}\n\n") |
| headers = [ |
| "Model", |
| "MCP (Avg)", |
| "Hardcoded (Avg)", |
| "Diff (MCP-Hardcoded)", |
| ] |
| lines.append("| " + " | ".join(headers) + " |\n") |
| lines.append("| " + " | ".join(["---"] * len(headers)) + " |\n") |
|
|
| for model in sorted(overall_data.keys()): |
| if overall_data[model][metric]["mcp"]: |
| avg_mcp = np.mean(overall_data[model][metric]["mcp"]) |
| avg_hard = np.mean(overall_data[model][metric]["hard"]) |
| diff = avg_mcp - avg_hard |
| lines.append( |
| f"| {model} | {avg_mcp:.2f} | {avg_hard:.2f} | {diff:+.2f} |\n" |
| ) |
| lines.append("\n") |
| continue |
|
|
| lines.append("## average_score\n\n") |
| headers = ["Model", "MCP (Avg)", "Hardcoded (Avg)", "Diff (MCP-Hardcoded)"] |
| lines.append("| " + " | ".join(headers) + " |\n") |
| lines.append("| " + " | ".join(["---"] * len(headers)) + " |\n") |
| for model in sorted(overall_rate_data.keys()): |
| if overall_rate_data[model]["gt"]["mcp"]: |
| avg_mcp = np.mean(overall_rate_data[model]["gt"]["mcp"]) |
| avg_hard = np.mean(overall_rate_data[model]["gt"]["hard"]) |
| diff = avg_mcp - avg_hard |
| lines.append( |
| f"| {model} | {avg_mcp:.2f} | {avg_hard:.2f} | {diff:+.2f} |\n" |
| ) |
| lines.append("\n") |
|
|
| lines.append("## pass_rate\n\n") |
| lines.append("| " + " | ".join(headers) + " |\n") |
| lines.append("| " + " | ".join(["---"] * len(headers)) + " |\n") |
| for model in sorted(overall_rate_data.keys()): |
| if overall_rate_data[model]["non_gt"]["mcp"]: |
| avg_mcp = np.mean(overall_rate_data[model]["non_gt"]["mcp"]) |
| avg_hard = np.mean(overall_rate_data[model]["non_gt"]["hard"]) |
| diff = avg_mcp - avg_hard |
| lines.append( |
| f"| {model} | {avg_mcp:.2f} | {avg_hard:.2f} | {diff:+.2f} |\n" |
| ) |
| lines.append("\n") |
|
|
| lines.append("---\n\n") |
| return "".join(lines) |
|
|
|
|
| def generate_version_comparison( |
| base_project, |
| version_a_suffix, |
| version_b_suffix, |
| scenario_data_dict, |
| version_a_name, |
| version_b_name, |
| gt_projects=None, |
| ): |
| """Generate comparison between two versions of a project.""" |
| lines = [] |
| lines.append(f"# {base_project}: {version_a_name} vs {version_b_name}\n\n") |
|
|
| scenario_a = f"{base_project}{version_a_suffix}" |
| scenario_b = f"{base_project}{version_b_suffix}" |
|
|
| if scenario_a not in scenario_data_dict or scenario_b not in scenario_data_dict: |
| lines.append(f"_Data not available for comparison_\n\n") |
| return "".join(lines) |
|
|
| data_a = scenario_data_dict[scenario_a] |
| data_b = scenario_data_dict[scenario_b] |
|
|
| all_models = set(data_a.keys()) | set(data_b.keys()) |
|
|
| |
| overall_avgs = {metric: {"a": [], "b": []} for metric in METRICS} |
| for model in all_models: |
| for metric in METRICS: |
| val_a = data_a.get(model, {}).get(metric, 0) |
| val_b = data_b.get(model, {}).get(metric, 0) |
| overall_avgs[metric]["a"].append(val_a) |
| overall_avgs[metric]["b"].append(val_b) |
|
|
| |
| lines.append("## Overall Summary (Averaged Across All Models)\n\n") |
| lines.append( |
| f"| Metric | {version_a_name} | {version_b_name} | Diff ({version_a_name}-{version_b_name}) |\n" |
| ) |
| lines.append("| --- | --- | --- | --- |\n") |
| for metric in METRICS: |
| if overall_avgs[metric]["a"]: |
| avg_a = np.mean(overall_avgs[metric]["a"]) |
| avg_b = np.mean(overall_avgs[metric]["b"]) |
| diff = avg_a - avg_b |
| display_metric = metric_display_name(metric, base_project, gt_projects) |
| lines.append( |
| f"| {display_metric} | {avg_a:.2f} | {avg_b:.2f} | {diff:+.2f} |\n" |
| ) |
| lines.append("\n---\n\n") |
|
|
| for metric in METRICS: |
| display_metric = metric_display_name(metric, base_project, gt_projects) |
| lines.append(f"## {display_metric}\n\n") |
| headers = [ |
| "Model", |
| version_a_name, |
| version_b_name, |
| f"Diff ({version_a_name}-{version_b_name})", |
| ] |
| lines.append("| " + " | ".join(headers) + " |\n") |
| lines.append("| " + " | ".join(["---"] * len(headers)) + " |\n") |
|
|
| for model in sorted(all_models): |
| val_a = data_a.get(model, {}).get(metric, 0) |
| val_b = data_b.get(model, {}).get(metric, 0) |
| diff = val_a - val_b |
| lines.append(f"| {model} | {val_a:.2f} | {val_b:.2f} | {diff:+.2f} |\n") |
| lines.append("\n") |
|
|
| return "".join(lines) |
|
|
|
|
| def generate_version_overall_comparison( |
| projects, |
| version_a_suffix, |
| version_b_suffix, |
| scenario_data_dict, |
| version_a_name, |
| version_b_name, |
| comparison_title, |
| gt_projects=None, |
| ): |
| """Generate overall comparison across all projects for two versions.""" |
| lines = [] |
| lines.append(f"# Overall {comparison_title}\n\n") |
| lines.append(f"Averaged across all projects: {', '.join(projects)}\n\n") |
|
|
| |
| overall_data = {} |
| framework_data = { |
| metric: {"a": [], "b": []} for metric in METRICS if metric != "pass_rate" |
| } |
| framework_rate_data = { |
| "gt": {"a": [], "b": []}, |
| "non_gt": {"a": [], "b": []}, |
| } |
| overall_rate_data = {} |
|
|
| for project in projects: |
| scenario_a = f"{project}{version_a_suffix}" |
| scenario_b = f"{project}{version_b_suffix}" |
|
|
| if scenario_a not in scenario_data_dict or scenario_b not in scenario_data_dict: |
| continue |
|
|
| data_a = scenario_data_dict[scenario_a] |
| data_b = scenario_data_dict[scenario_b] |
|
|
| all_models = set(data_a.keys()) | set(data_b.keys()) |
| project_bucket = "gt" if gt_projects and project in gt_projects else "non_gt" |
|
|
| for model in all_models: |
| if model not in overall_data: |
| overall_data[model] = { |
| metric: {"a": [], "b": []} |
| for metric in METRICS |
| if metric != "pass_rate" |
| } |
| if model not in overall_rate_data: |
| overall_rate_data[model] = { |
| "gt": {"a": [], "b": []}, |
| "non_gt": {"a": [], "b": []}, |
| } |
|
|
| for metric in METRICS: |
| val_a = data_a.get(model, {}).get(metric, 0) |
| val_b = data_b.get(model, {}).get(metric, 0) |
| if metric == "pass_rate": |
| overall_rate_data[model][project_bucket]["a"].append(val_a) |
| overall_rate_data[model][project_bucket]["b"].append(val_b) |
| framework_rate_data[project_bucket]["a"].append(val_a) |
| framework_rate_data[project_bucket]["b"].append(val_b) |
| else: |
| overall_data[model][metric]["a"].append(val_a) |
| overall_data[model][metric]["b"].append(val_b) |
| framework_data[metric]["a"].append(val_a) |
| framework_data[metric]["b"].append(val_b) |
|
|
| |
| lines.append("## Framework-Level Comparison (All Models Averaged)\n\n") |
| lines.append( |
| f"| Metric | {version_a_name} | {version_b_name} | Diff ({version_a_name}-{version_b_name}) |\n" |
| ) |
| lines.append("| --- | --- | --- | --- |\n") |
| for metric in METRICS: |
| if metric == "pass_rate": |
| if framework_rate_data["gt"]["a"]: |
| avg_a = np.mean(framework_rate_data["gt"]["a"]) |
| avg_b = np.mean(framework_rate_data["gt"]["b"]) |
| diff = avg_a - avg_b |
| lines.append( |
| f"| average_score | {avg_a:.2f} | {avg_b:.2f} | {diff:+.2f} |\n" |
| ) |
| if framework_rate_data["non_gt"]["a"]: |
| avg_a = np.mean(framework_rate_data["non_gt"]["a"]) |
| avg_b = np.mean(framework_rate_data["non_gt"]["b"]) |
| diff = avg_a - avg_b |
| lines.append( |
| f"| pass_rate | {avg_a:.2f} | {avg_b:.2f} | {diff:+.2f} |\n" |
| ) |
| continue |
|
|
| if framework_data[metric]["a"]: |
| avg_a = np.mean(framework_data[metric]["a"]) |
| avg_b = np.mean(framework_data[metric]["b"]) |
| diff = avg_a - avg_b |
| lines.append(f"| {metric} | {avg_a:.2f} | {avg_b:.2f} | {diff:+.2f} |\n") |
| lines.append("\n---\n\n") |
|
|
| |
| for metric in METRICS: |
| headers = [ |
| "Model", |
| f"{version_a_name} (Avg)", |
| f"{version_b_name} (Avg)", |
| f"Diff ({version_a_name}-{version_b_name})", |
| ] |
|
|
| if metric != "pass_rate": |
| lines.append(f"## {metric}\n\n") |
| lines.append("| " + " | ".join(headers) + " |\n") |
| lines.append("| " + " | ".join(["---"] * len(headers)) + " |\n") |
|
|
| for model in sorted(overall_data.keys()): |
| if overall_data[model][metric]["a"]: |
| avg_a = np.mean(overall_data[model][metric]["a"]) |
| avg_b = np.mean(overall_data[model][metric]["b"]) |
| diff = avg_a - avg_b |
| lines.append( |
| f"| {model} | {avg_a:.2f} | {avg_b:.2f} | {diff:+.2f} |\n" |
| ) |
| lines.append("\n") |
| continue |
|
|
| lines.append("## average_score\n\n") |
| lines.append("| " + " | ".join(headers) + " |\n") |
| lines.append("| " + " | ".join(["---"] * len(headers)) + " |\n") |
| for model in sorted(overall_rate_data.keys()): |
| if overall_rate_data[model]["gt"]["a"]: |
| avg_a = np.mean(overall_rate_data[model]["gt"]["a"]) |
| avg_b = np.mean(overall_rate_data[model]["gt"]["b"]) |
| diff = avg_a - avg_b |
| lines.append(f"| {model} | {avg_a:.2f} | {avg_b:.2f} | {diff:+.2f} |\n") |
| lines.append("\n") |
|
|
| lines.append("## pass_rate\n\n") |
| lines.append("| " + " | ".join(headers) + " |\n") |
| lines.append("| " + " | ".join(["---"] * len(headers)) + " |\n") |
| for model in sorted(overall_rate_data.keys()): |
| if overall_rate_data[model]["non_gt"]["a"]: |
| avg_a = np.mean(overall_rate_data[model]["non_gt"]["a"]) |
| avg_b = np.mean(overall_rate_data[model]["non_gt"]["b"]) |
| diff = avg_a - avg_b |
| lines.append(f"| {model} | {avg_a:.2f} | {avg_b:.2f} | {diff:+.2f} |\n") |
| lines.append("\n") |
|
|
| lines.append("---\n\n") |
| return "".join(lines) |
|
|
|
|
| def create_radar_chart(df, scenario_name, output_path, pass_rate_label="pass_rate"): |
| """ |
| Create a radar chart for a single scenario with all models. |
| |
| Args: |
| df: DataFrame containing evaluation results |
| scenario_name: Name of the scenario (subfolder name) |
| output_path: Path to save the PDF file |
| """ |
| if plt is None: |
| print( |
| f" Warning: matplotlib not installed, skipping radar chart: {output_path}" |
| ) |
| return |
| |
| num_vars = len(METRICS) |
|
|
| |
| angles = np.linspace(0, 2 * np.pi, num_vars, endpoint=False).tolist() |
| angles += angles[:1] |
|
|
| |
| fig, ax = plt.subplots(figsize=(12, 12), subplot_kw=dict(projection="polar")) |
|
|
| |
| ax.set_facecolor("#cedbea") |
| fig.patch.set_facecolor("white") |
|
|
| |
| for idx, row in df.iterrows(): |
| model_name = row["model"] |
| values = [row[metric] for metric in METRICS] |
| values += values[:1] |
|
|
| color = MODEL_COLORS.get(model_name, f"C{idx}") |
|
|
| |
| ax.plot( |
| angles, |
| values, |
| "o-", |
| linewidth=2, |
| label=model_name, |
| color=color, |
| markersize=6, |
| ) |
| ax.fill(angles, values, alpha=0.15, color=color) |
|
|
| |
| metric_labels = [ |
| (pass_rate_label if metric == "pass_rate" else metric) for metric in METRICS |
| ] |
| ax.set_xticks(angles[:-1]) |
| |
| ax.set_xticklabels([]) |
|
|
| label_radius = 1.3 |
| for angle, label in zip(angles[:-1], metric_labels): |
| |
| if 0 <= angle < np.pi / 2 or 3 * np.pi / 2 <= angle <= 2 * np.pi: |
| ha = "left" |
| elif np.pi / 2 < angle < 3 * np.pi / 2: |
| ha = "right" |
| else: |
| ha = "center" |
| ax.text( |
| angle, |
| label_radius, |
| label, |
| ha=ha, |
| va="center", |
| fontsize=30, |
| fontweight="bold", |
| ) |
|
|
| |
| ax.set_ylim(0, 1.25) |
| ax.set_yticks([0, 0.25, 0.5, 0.75, 1.0, 1.25]) |
| ax.set_yticklabels( |
| ["0", "0.25", "0.5", "0.75", "1.0", ""], |
| size=30, |
| color="black", |
| weight="bold", |
| ) |
|
|
| |
| ax.spines["polar"].set_visible(False) |
|
|
| |
| ax.xaxis.grid(True, linestyle="--", linewidth=3.0, alpha=1.0, color="white") |
| ax.yaxis.grid(True, linestyle="-", linewidth=3.0, color="white", alpha=1.0) |
|
|
| |
| |
| plt.tight_layout() |
|
|
| |
| plt.savefig(output_path, format="pdf", dpi=300, bbox_inches="tight") |
| plt.close() |
|
|
| print(f" Created: {output_path}") |
|
|
|
|
| def create_legend_pdf(output_path): |
| if plt is None: |
| print(f" Warning: matplotlib not installed, skipping legend PDF: {output_path}") |
| return |
| fig, ax = plt.subplots(figsize=(4, 3)) |
| ax.axis("off") |
|
|
| handles = [] |
| labels = [] |
| for model_name, color in MODEL_COLORS.items(): |
| (handle,) = ax.plot( |
| [], |
| [], |
| "o-", |
| linewidth=2, |
| markersize=8, |
| color=color, |
| ) |
| handles.append(handle) |
| labels.append(model_name) |
|
|
| ax.legend( |
| handles, |
| labels, |
| loc="center", |
| frameon=True, |
| fancybox=True, |
| shadow=False, |
| prop={"size": 12, "weight": "bold"}, |
| ) |
|
|
| plt.tight_layout() |
| plt.savefig(output_path, format="pdf", dpi=300, bbox_inches="tight") |
| plt.close(fig) |
|
|
| print(f" Legend PDF created: {output_path}") |
|
|
|
|
| def create_legend_pdf_horizontal(output_path): |
| if plt is None: |
| print( |
| f" Warning: matplotlib not installed, skipping horizontal legend PDF: {output_path}" |
| ) |
| return |
| |
| fig, ax = plt.subplots(figsize=(12, 1.0)) |
| ax.axis("off") |
|
|
| handles = [] |
| labels = [] |
| for model_name, color in MODEL_COLORS.items(): |
| (handle,) = ax.plot( |
| [], |
| [], |
| "o-", |
| linewidth=2, |
| markersize=8, |
| color=color, |
| ) |
| handles.append(handle) |
| labels.append(model_name) |
|
|
| ax.legend( |
| handles, |
| labels, |
| loc="center", |
| ncol=len(MODEL_COLORS), |
| frameon=False, |
| fancybox=False, |
| shadow=False, |
| borderaxespad=0.1, |
| borderpad=0.3, |
| handletextpad=0.4, |
| labelspacing=0.2, |
| prop={"size": 12, "weight": "bold"}, |
| ) |
|
|
| plt.tight_layout(pad=0.0) |
| plt.savefig(output_path, format="pdf", dpi=300, bbox_inches="tight", pad_inches=0.0) |
| plt.close(fig) |
|
|
| print(f" Horizontal legend PDF created: {output_path}") |
|
|
|
|
| def main(): |
| """Main function to process all subfolders and generate radar charts.""" |
| base_dir = Path("/Users/wzr/TOSEM-2025/RESULTS/RQ1") |
| output_dir = base_dir / "RadarCharts" |
| output_dir.mkdir(exist_ok=True) |
|
|
| |
| csv_files = list(base_dir.glob("*/evaluation_results.csv")) |
|
|
| print(f"Found {len(csv_files)} evaluation_results.csv files") |
| print("=" * 60) |
|
|
| |
| all_data = { |
| model: {metric: [] for metric in METRICS} for model in MODEL_COLORS.keys() |
| } |
|
|
| series_data = {} |
| combined_open_closed_lines = [] |
| combined_series_avg_lines = [] |
| scenario_data = {} |
| gt_projects = set() |
|
|
| |
| for csv_file in sorted(csv_files): |
| scenario_name = csv_file.parent.name |
| series_name = scenario_name.split("-")[0] |
|
|
| try: |
| |
| df = pd.read_csv(csv_file) |
|
|
| |
| retry_file = csv_file.parent / "retry_summary.csv" |
| if retry_file.exists(): |
| retry_df = pd.read_csv(retry_file) |
| retry_rate_col = "Retry_Rate(%)" |
| if ( |
| retry_rate_col not in retry_df.columns |
| and "Error_Rate(%)" in retry_df.columns |
| ): |
| retry_rate_col = "Error_Rate(%)" |
| retry_df["retry_rate"] = retry_df[retry_rate_col] / 100.0 |
| |
| df = df.merge( |
| retry_df[["Model", "retry_rate"]], |
| left_on="model", |
| right_on="Model", |
| how="left", |
| ) |
| df = df.drop(columns=["Model"]) |
| df["retry_rate"] = df["retry_rate"].fillna(0.0) |
| else: |
| print(f" Warning: retry_summary.csv not found for {scenario_name}") |
| df["retry_rate"] = 0.0 |
|
|
| |
| success_file = csv_file.parent / "success_rate.csv" |
| if success_file.exists(): |
| success_df = pd.read_csv(success_file) |
| |
| success_df["pass_rate"] = success_df["Success_Rate(%)"] / 100.0 |
| |
| df = df.merge( |
| success_df[["Model", "pass_rate"]], |
| left_on="model", |
| right_on="Model", |
| how="left", |
| ) |
| df = df.drop(columns=["Model"]) |
| df["pass_rate"] = df["pass_rate"].fillna(0.0) |
| else: |
| print(f" Warning: success_rate.csv not found for {scenario_name}") |
| df["pass_rate"] = 0.0 |
|
|
| df["pass_rate_agg"] = df["pass_rate"] |
|
|
| pass_rate_label = "pass_rate" |
| score_file = csv_file.parent / "score_summary.csv" |
| if score_file.exists(): |
| score_df = pd.read_csv(score_file) |
| score_df["average_score"] = score_df["Mean_Score"] / 100.0 |
| df = df.merge( |
| score_df[["Model", "average_score"]], |
| left_on="model", |
| right_on="Model", |
| how="left", |
| ) |
| df["pass_rate"] = df["average_score"].fillna(df["pass_rate"]) |
| df = df.drop(columns=["Model", "average_score"]) |
| pass_rate_label = "average_score" |
| gt_projects.add(series_name) |
|
|
| |
| missing_metrics = [m for m in METRICS if m not in df.columns] |
| if missing_metrics: |
| print(f" Skipping {scenario_name}: missing metrics {missing_metrics}") |
| continue |
|
|
| |
| scenario_data[scenario_name] = {} |
| for idx, row in df.iterrows(): |
| model_name = row["model"] |
| scenario_data[scenario_name][model_name] = { |
| metric: row[metric] for metric in METRICS |
| } |
|
|
| |
| for idx, row in df.iterrows(): |
| model_name = row["model"] |
| if model_name in all_data: |
| for metric in METRICS: |
| value = row[metric] |
| all_data[model_name][metric].append(value) |
| series_models = series_data.setdefault(series_name, {}) |
| if model_name not in series_models: |
| series_models[model_name] = {m: [] for m in METRICS} |
| series_models[model_name][metric].append(value) |
|
|
| |
| output_path = output_dir / f"{scenario_name}_radar.pdf" |
|
|
| |
| create_radar_chart( |
| df, |
| scenario_name, |
| output_path, |
| pass_rate_label=pass_rate_label, |
| ) |
|
|
| except Exception as e: |
| print(f" Error processing {scenario_name}: {e}") |
|
|
| print("=" * 60) |
| print("All individual radar charts generated successfully!") |
| print("=" * 60) |
|
|
| |
| try: |
| print("Generating overall average chart...") |
|
|
| |
| avg_data = [] |
| for model_name, metrics_data in all_data.items(): |
| row_data = {"model": model_name} |
| for metric in METRICS: |
| if metrics_data[metric]: |
| row_data[metric] = np.mean(metrics_data[metric]) |
| else: |
| row_data[metric] = 0 |
| avg_data.append(row_data) |
|
|
| |
| avg_df = pd.DataFrame(avg_data) |
|
|
| group_rows = [] |
| for group_name in ["open", "closed"]: |
| group_models = [ |
| m for m, category in MODEL_CATEGORY.items() if category == group_name |
| ] |
| if not group_models: |
| continue |
| group_df = avg_df[avg_df["model"].isin(group_models)] |
| if group_df.empty: |
| continue |
| row = {"group": group_name, "model_count": len(group_df)} |
| for metric in METRICS: |
| row[metric] = float(group_df[metric].mean()) |
| group_rows.append(row) |
| if group_rows: |
| header_cols = ["Group", "Model Count"] + METRICS |
| header_line = "| " + " | ".join(header_cols) + " |\n" |
| separator_line = "| " + " | ".join(["---"] * len(header_cols)) + " |\n" |
| md_lines = [] |
| md_lines.append("# Overall Open vs Closed Models\n\n") |
| md_lines.append(header_line) |
| md_lines.append(separator_line) |
| for row in group_rows: |
| row_vals = [ |
| row["group"], |
| str(row["model_count"]), |
| ] |
| for metric in METRICS: |
| val = row[metric] |
| row_vals.append(f"{val:.2f}") |
| md_lines.append("| " + " | ".join(row_vals) + " |\n") |
| combined_open_closed_lines.extend(md_lines) |
| combined_open_closed_lines.append("\n") |
|
|
| |
| overall_models_data = {} |
| for series_name, models_data in series_data.items(): |
| for model_name, metrics_data in models_data.items(): |
| if model_name not in overall_models_data: |
| overall_models_data[model_name] = {m: [] for m in METRICS} |
| for metric in METRICS: |
| values = metrics_data.get(metric, []) |
| overall_models_data[model_name][metric].extend(values) |
|
|
| |
| if overall_models_data: |
| overall_rows = [] |
| for model_name, metrics_data in overall_models_data.items(): |
| row_data = {"model": model_name} |
| for metric in METRICS: |
| values = metrics_data.get(metric, []) |
| if values: |
| row_data[metric] = float(np.mean(values)) |
| else: |
| row_data[metric] = 0 |
| overall_rows.append(row_data) |
|
|
| if overall_rows: |
| overall_df = pd.DataFrame(overall_rows) |
| combined_series_avg_lines.append("# Overall Summary (All Projects)\n\n") |
| combined_series_avg_lines.append(df_to_markdown(overall_df) + "\n\n") |
|
|
| for series_name, models_data in sorted(series_data.items()): |
| series_avg_rows = [] |
| for model_name, metrics_data in models_data.items(): |
| row_data = {"model": model_name} |
| for metric in METRICS: |
| values = metrics_data.get(metric, []) |
| if values: |
| row_data[metric] = float(np.mean(values)) |
| else: |
| row_data[metric] = 0 |
| series_avg_rows.append(row_data) |
| if not series_avg_rows: |
| continue |
| series_df = pd.DataFrame(series_avg_rows) |
| series_pdf_output = output_dir / f"{series_name}_Series_Average_radar.pdf" |
| series_pass_rate_label = ( |
| "average_score" if series_name in gt_projects else "pass_rate" |
| ) |
| create_radar_chart( |
| series_df, |
| f"{series_name} Series Average", |
| series_pdf_output, |
| pass_rate_label=series_pass_rate_label, |
| ) |
|
|
| combined_series_avg_lines.append(f"# {series_name} Series Average\n\n") |
| if series_pass_rate_label != "pass_rate": |
| combined_series_avg_lines.append( |
| df_to_markdown( |
| series_df.rename(columns={"pass_rate": series_pass_rate_label}) |
| ) |
| + "\n\n" |
| ) |
| else: |
| combined_series_avg_lines.append(df_to_markdown(series_df) + "\n\n") |
|
|
| group_rows = [] |
| for group_name in ["open", "closed"]: |
| group_models = [ |
| m |
| for m, category in MODEL_CATEGORY.items() |
| if category == group_name |
| ] |
| if not group_models: |
| continue |
| group_df = series_df[series_df["model"].isin(group_models)] |
| if group_df.empty: |
| continue |
| row = { |
| "series": series_name, |
| "group": group_name, |
| "model_count": len(group_df), |
| } |
| for metric in METRICS: |
| row[metric] = float(group_df[metric].mean()) |
| group_rows.append(row) |
| if group_rows: |
| header_cols = [ |
| "Series", |
| "Group", |
| "Model Count", |
| ] + series_metric_headers(series_name, gt_projects) |
| header_line = "| " + " | ".join(header_cols) + " |\n" |
| separator_line = "| " + " | ".join(["---"] * len(header_cols)) + " |\n" |
| md_lines = [] |
| md_lines.append(f"# {series_name} Open vs Closed Models\n\n") |
| md_lines.append(header_line) |
| md_lines.append(separator_line) |
| for row in group_rows: |
| row_vals = [ |
| row["series"], |
| row["group"], |
| str(row["model_count"]), |
| ] |
| for metric in METRICS: |
| val = row[metric] |
| row_vals.append(f"{val:.2f}") |
| md_lines.append("| " + " | ".join(row_vals) + " |\n") |
| combined_open_closed_lines.extend(md_lines) |
| combined_open_closed_lines.append("\n") |
|
|
| |
| if combined_open_closed_lines: |
| combined_md_path = output_dir / "All_Open_vs_Closed_summaries.md" |
| combined_md_path.write_text( |
| "".join(combined_open_closed_lines), |
| encoding="utf-8", |
| ) |
| print(f" Combined markdown created: {combined_md_path}") |
|
|
| |
| if combined_series_avg_lines: |
| combined_csv_md_path = output_dir / "All_Series_Average_tables.md" |
| combined_csv_md_path.write_text( |
| "".join(combined_series_avg_lines), |
| encoding="utf-8", |
| ) |
| print(f" Combined Series Average markdown created: {combined_csv_md_path}") |
|
|
| |
| overall_output = output_dir / "Overall_Average_radar.pdf" |
| create_radar_chart(avg_df, "Overall Average (All Scenarios)", overall_output) |
|
|
| legend_output = output_dir / "Model_Legend.pdf" |
| create_legend_pdf(legend_output) |
|
|
| legend_horizontal_output = output_dir / "Model_Legend_horizontal.pdf" |
| create_legend_pdf_horizontal(legend_horizontal_output) |
|
|
| |
|
|
| |
| comparison1_lines = [] |
| comparison1_lines.append( |
| generate_model_pair_comparison( |
| "GPT-5", |
| "GPT-4o-mini", |
| scenario_data, |
| "GPT-5 vs GPT-4o-mini (Powerful vs Lightweight)", |
| gt_projects=gt_projects, |
| ) |
| ) |
| comparison1_md_path = output_dir / "Comparison_Powerful_vs_Lightweight.md" |
| comparison1_md_path.write_text("".join(comparison1_lines), encoding="utf-8") |
| print(f" Powerful vs Lightweight comparison created: {comparison1_md_path}") |
|
|
| |
| comparison2_lines = [] |
| comparison2_lines.append( |
| generate_model_pair_comparison( |
| "DeepSeek-R1", |
| "DeepSeek-V3-1", |
| scenario_data, |
| "DeepSeek-R1 vs DeepSeek-V3-1 (Reasoning vs Non-Reasoning)", |
| gt_projects=gt_projects, |
| ) |
| ) |
| comparison2_lines.append("\n---\n\n") |
| comparison2_lines.append( |
| generate_model_pair_comparison( |
| "Gemini-2.5-flash", |
| "Gemini-2.5-flash-nothinking", |
| scenario_data, |
| "Gemini-2.5-flash vs Gemini-2.5-flash-nothinking (Reasoning vs Non-Reasoning)", |
| gt_projects=gt_projects, |
| ) |
| ) |
| comparison2_md_path = output_dir / "Comparison_Reasoning_vs_NonReasoning.md" |
| comparison2_md_path.write_text("".join(comparison2_lines), encoding="utf-8") |
| print(f" Reasoning vs Non-Reasoning comparison created: {comparison2_md_path}") |
|
|
| |
| comparison3_lines = [] |
| projects = ["MarkdownValidator", "GameBuilder", "EmailResponder"] |
|
|
| |
| comparison3_lines.append( |
| generate_mcp_overall_comparison( |
| projects, scenario_data, gt_projects=gt_projects |
| ) |
| ) |
|
|
| |
| for project in projects: |
| comparison3_lines.append( |
| generate_mcp_comparison(project, scenario_data, gt_projects=gt_projects) |
| ) |
|
|
| comparison3_md_path = output_dir / "Comparison_MCP_vs_Hardcoded.md" |
| comparison3_md_path.write_text("".join(comparison3_lines), encoding="utf-8") |
| print(f" MCP vs Hardcoded comparison created: {comparison3_md_path}") |
|
|
| |
| comparison4_lines = [] |
| version_projects = [ |
| "SQL_assistant", |
| "intelligent_recruitment_platform", |
| "landing_page_generator", |
| "self_evaluation_loop_flow", |
| "write_a_book_with_flows", |
| ] |
|
|
| |
| comparison4_lines.append( |
| generate_version_overall_comparison( |
| version_projects, |
| "-MCP", |
| "-A2A", |
| scenario_data, |
| "MCP", |
| "A2A", |
| "MCP vs A2A Comparison", |
| gt_projects=gt_projects, |
| ) |
| ) |
|
|
| |
| for project in version_projects: |
| comparison4_lines.append( |
| generate_version_comparison( |
| project, |
| "-MCP", |
| "-A2A", |
| scenario_data, |
| "MCP", |
| "A2A", |
| gt_projects=gt_projects, |
| ) |
| ) |
|
|
| comparison4_md_path = output_dir / "Comparison_MCP_vs_A2A.md" |
| comparison4_md_path.write_text("".join(comparison4_lines), encoding="utf-8") |
| print(f" MCP vs A2A comparison created: {comparison4_md_path}") |
|
|
| |
| comparison5_lines = [] |
|
|
| |
| comparison5_lines.append( |
| generate_version_overall_comparison( |
| version_projects, |
| "-A2A", |
| "-A2A_mix", |
| scenario_data, |
| "A2A", |
| "A2A_mix", |
| "A2A vs A2A_mix Comparison", |
| gt_projects=gt_projects, |
| ) |
| ) |
|
|
| |
| for project in version_projects: |
| comparison5_lines.append( |
| generate_version_comparison( |
| project, |
| "-A2A", |
| "-A2A_mix", |
| scenario_data, |
| "A2A", |
| "A2A_mix", |
| gt_projects=gt_projects, |
| ) |
| ) |
|
|
| comparison5_md_path = output_dir / "Comparison_A2A_vs_A2A_mix.md" |
| comparison5_md_path.write_text("".join(comparison5_lines), encoding="utf-8") |
| print(f" A2A vs A2A_mix comparison created: {comparison5_md_path}") |
|
|
| print("=" * 60) |
| print(f" Overall average chart created: {overall_output}") |
| print(f" Legend PDF created: {legend_output}") |
| print(f" Horizontal legend PDF created: {legend_horizontal_output}") |
|
|
| except Exception as e: |
| print(f" Error generating overall chart: {e}") |
|
|
| print("=" * 60) |
| print("All radar charts completed!") |
|
|
|
|
| if __name__ == "__main__": |
| main() |
|
|