Skip to content

Commit ea71e61

Browse files
committed
Update viz
1 parent 8b99130 commit ea71e61

4 files changed

Lines changed: 39 additions & 14 deletions

File tree

codeclash/analysis/metrics/elo.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,6 @@ def _analyze_tournament(self, tournament_log_folder: Path) -> None:
233233
player2profile[player_name] = self._player_profiles[key]
234234

235235
# Determine total rounds for weighting calculation
236-
if "round_stats" not in metadata:
237-
raise SkipTournamentException("Skipping (no `round_stats` in metadata)")
238236
total_rounds = len([k for k in metadata["round_stats"].keys() if k != "0"])
239237

240238
if self._unit == "round":

codeclash/analysis/viz/cdf_files_edited_per_round.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ def main():
3333
for changes_file in changes_files:
3434
with open(changes_file) as f:
3535
changes = json.load(f)
36-
num_files = len(PatchSet(changes["incremental_diff"]))
36+
try:
37+
num_files = len(PatchSet(changes["incremental_diff"]))
38+
except Exception as e:
39+
print(f"Issue parsing diff in {changes_file}, skipping: {e}")
40+
continue
3741
model_to_num_files[p2m[name]].append(num_files)
3842

3943
with open(DATA_CACHE, "w") as f:

codeclash/analysis/viz/heatmap_win_streak_distribution.py

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,24 @@ def main(log_dir: Path, xlim: int = 15):
7272
streaks = win_streaks[model]
7373
max_streaks.append(max(streaks) if streaks else 0)
7474

75-
# Use xlim as the display maximum
76-
display_columns = xlim
75+
# Use xlim as the display maximum, start from streak length 2
76+
display_columns = xlim - 1 # Exclude length 1, so columns represent 2 through xlim
7777
streak_matrix = np.zeros((len(models), display_columns))
7878

7979
for i, model in enumerate(models):
8080
streaks = win_streaks[model]
8181
for streak_len in streaks:
82+
# Skip streaks of length 1
83+
if streak_len == 1:
84+
continue
85+
# Map streak_len 2 to column 0, 3 to column 1, etc.
8286
if streak_len < xlim:
83-
streak_matrix[i, streak_len - 1] += 1
87+
streak_matrix[i, streak_len - 2] += 1
8488
else:
8589
# Aggregate all streaks >= xlim into the last column
86-
streak_matrix[i, xlim - 1] += 1
90+
streak_matrix[i, display_columns - 1] += 1
8791

88-
# Normalize by total streaks for each model
92+
# Normalize by total streaks for each model (excluding length 1)
8993
for i in range(len(models)):
9094
total = np.sum(streak_matrix[i, :])
9195
if total > 0:
@@ -100,11 +104,15 @@ def main(log_dir: Path, xlim: int = 15):
100104
for i, model in enumerate(models):
101105
streaks = win_streaks[model]
102106
for streak_len in streaks:
107+
# Skip streaks of length 1
108+
if streak_len == 1:
109+
continue
110+
# Map streak_len 2 to column 0, 3 to column 1, etc.
103111
if streak_len < xlim:
104-
absolute_counts[i, streak_len - 1] += 1
112+
absolute_counts[i, streak_len - 2] += 1
105113
else:
106114
# Aggregate all streaks >= xlim into the last column
107-
absolute_counts[i, xlim - 1] += 1
115+
absolute_counts[i, display_columns - 1] += 1
108116

109117
# Add percentage and absolute count labels to ALL cells
110118
for i in range(len(models)):
@@ -124,12 +132,20 @@ def main(log_dir: Path, xlim: int = 15):
124132
fontproperties=FONT_BOLD,
125133
)
126134

127-
plt.xlabel("Win Streak Length", fontproperties=FONT_BOLD, fontsize=18)
135+
plt.xlabel("Consecutive Rounds Won", fontproperties=FONT_BOLD, fontsize=18)
128136

129-
# Create x-axis labels with the last one as "xlim+"
130-
x_labels = [str(i) for i in range(1, xlim)] + [f"{xlim}+"]
137+
# Create x-axis labels starting from 2, with the last one as "xlim+"
138+
x_labels = [str(i) for i in range(2, xlim)] + [f"{xlim}+"]
131139
plt.xticks(range(display_columns), x_labels, fontproperties=FONT_BOLD, fontsize=14)
132-
plt.yticks(range(len(models)), [MODEL_TO_DISPLAY_NAME[m] for m in models], fontproperties=FONT_BOLD, fontsize=14)
140+
141+
# Create y-axis labels with total streak counts (excluding length 1)
142+
y_labels = []
143+
for model in models:
144+
total_streaks = sum(1 for streak_len in win_streaks[model] if streak_len >= 2)
145+
display_name = MODEL_TO_DISPLAY_NAME[model]
146+
y_labels.append(f"{display_name}\n(n={total_streaks})")
147+
148+
plt.yticks(range(len(models)), y_labels, fontproperties=FONT_BOLD, fontsize=14)
133149
# plt.colorbar(im, label="Percentage of Streaks")
134150
plt.tight_layout()
135151
plt.savefig(OUTPUT_FILE, dpi=300, bbox_inches="tight")

codeclash/analysis/viz/line_chart_per_round_win_rate.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,14 @@ def aggregate_win_rates_across_games(profiles):
119119
)
120120
plt.ylim(0.1, 1)
121121
FONT_BOLD.set_size(14)
122+
# Get handles and labels, then sort by label alphabetically
123+
handles, labels = plt.gca().get_legend_handles_labels()
124+
sorted_pairs = sorted(zip(handles, labels), key=lambda x: x[1])
125+
sorted_handles, sorted_labels = zip(*sorted_pairs)
126+
122127
plt.legend(
128+
sorted_handles,
129+
sorted_labels,
123130
bbox_to_anchor=(1, 1),
124131
loc="upper right",
125132
ncol=2,

0 commit comments

Comments
 (0)