Skip to content

Commit ee29acc

Browse files
committed
Change(viewer): sim win rate -> score; move to top of table
1 parent 48340d5 commit ee29acc

5 files changed

Lines changed: 73 additions & 48 deletions

File tree

codeclash/viewer/app.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -496,10 +496,11 @@ def analyze_line_counts(self) -> dict[str, Any]:
496496
return {"all_files": all_files_list, "line_counts_by_round": line_counts_by_round}
497497

498498
def analyze_sim_wins_per_round(self) -> dict[str, Any]:
499-
"""Analyze number of simulations won per round for each competitor from round_stats in metadata.json"""
499+
"""Analyze scores per round for each competitor from round_stats in metadata.json.
500+
Scores are calculated as wins + 0.5*ties, same as in the table."""
500501
metadata = load_metadata(self.log_dir)
501502
if not metadata:
502-
return {"players": [], "rounds": [], "wins_by_player": {}}
503+
return {"players": [], "rounds": [], "scores_by_player": {}}
503504

504505
round_stats = metadata.get("round_stats", {})
505506
# Collect all player names from all rounds
@@ -512,18 +513,28 @@ def analyze_sim_wins_per_round(self) -> dict[str, Any]:
512513
# Collect all round numbers (sorted)
513514
round_nums = sorted([int(k) for k in round_stats.keys()])
514515

515-
# Build wins_by_player: {player: [wins_per_round]}
516-
wins_by_player = {p: [] for p in player_names}
516+
# Build scores_by_player: {player: [scores_per_round]}
517+
# Scores = (wins + 0.5*ties) / total_games * 100 (percentage, same as in process_round_results)
518+
scores_by_player = {p: [] for p in player_names}
517519
for round_num in round_nums:
518520
round_data = round_stats.get(str(round_num), {})
519521
scores = round_data.get("scores", {})
522+
ties = scores.get("Tie", 0)
523+
total_games = sum(scores.values())
524+
520525
for p in player_names:
521-
wins_by_player[p].append(scores.get(p, 0))
526+
wins = scores.get(p, 0)
527+
if total_games > 0:
528+
# Calculate score as percentage: (wins + 0.5*ties) / total_games * 100
529+
player_score = ((wins + 0.5 * ties) / total_games) * 100
530+
else:
531+
player_score = 0
532+
scores_by_player[p].append(round(player_score, 1))
522533

523534
return {
524535
"players": player_names,
525536
"rounds": round_nums,
526-
"wins_by_player": wins_by_player,
537+
"scores_by_player": scores_by_player,
527538
}
528539

529540
def load_matrix_analysis(self) -> dict[str, Any] | None:

codeclash/viewer/static/css/style.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,6 +1649,22 @@ summary:focus {
16491649
max-height: 100%;
16501650
}
16511651

1652+
/* Scores per round container in overview */
1653+
.scores-per-round-container {
1654+
margin: 2rem 0;
1655+
padding: 1.5rem;
1656+
background-color: var(--bg-secondary);
1657+
border: 1px solid var(--border-color);
1658+
border-radius: 0.5rem;
1659+
}
1660+
1661+
.scores-per-round-container h3 {
1662+
color: var(--text-primary);
1663+
margin-bottom: 1rem;
1664+
font-size: 1.25rem;
1665+
font-weight: 600;
1666+
}
1667+
16521668
/* Responsive design for analysis */
16531669
@media (max-width: 768px) {
16541670
.file-selector {

codeclash/viewer/static/js/analysis.js

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -184,34 +184,37 @@ function prepareChartData(fileName) {
184184
}
185185

186186
// Initialize when DOM is loaded
187-
// --- Sim Wins Per Round Chart ---
188-
let simWinsChart = null;
189-
let simWinsData = null;
190187

191-
function initializeSimWinsChart() {
192-
const simWinsDataElement = document.getElementById("sim-wins-data");
193-
if (!simWinsDataElement) return;
188+
// --- Overview Scores Chart ---
189+
let overviewScoresChart = null;
190+
let overviewScoresData = null;
191+
192+
function initializeOverviewScoresChart() {
193+
const overviewScoresDataElement = document.getElementById(
194+
"overview-scores-data",
195+
);
196+
if (!overviewScoresDataElement) return;
194197
try {
195-
simWinsData = JSON.parse(simWinsDataElement.textContent);
198+
overviewScoresData = JSON.parse(overviewScoresDataElement.textContent);
196199
if (
197-
simWinsData &&
198-
simWinsData.players &&
199-
simWinsData.players.length > 0 &&
200-
simWinsData.rounds &&
201-
simWinsData.rounds.length > 0
200+
overviewScoresData &&
201+
overviewScoresData.players &&
202+
overviewScoresData.players.length > 0 &&
203+
overviewScoresData.rounds &&
204+
overviewScoresData.rounds.length > 0
202205
) {
203-
createSimWinsChart();
206+
createOverviewScoresChart();
204207
}
205208
} catch (error) {
206-
console.error("Error parsing sim wins data:", error);
209+
console.error("Error parsing overview scores data:", error);
207210
}
208211
}
209212

210-
function createSimWinsChart() {
211-
const canvas = document.getElementById("sim-wins-chart");
212-
if (!canvas || !simWinsData) return;
213+
function createOverviewScoresChart() {
214+
const canvas = document.getElementById("overview-scores-chart");
215+
if (!canvas || !overviewScoresData) return;
213216
const ctx = canvas.getContext("2d");
214-
if (simWinsChart) simWinsChart.destroy();
217+
if (overviewScoresChart) overviewScoresChart.destroy();
215218

216219
// Prepare datasets
217220
const colors = [
@@ -226,8 +229,11 @@ function createSimWinsChart() {
226229
"#FF6384",
227230
];
228231
let colorIndex = 0;
229-
const datasets = simWinsData.players.map((player) => {
230-
const data = simWinsData.rounds.map((round, i) => ({ x: round, y: simWinsData.wins_by_player[player][i] }));
232+
const datasets = overviewScoresData.players.map((player) => {
233+
const data = overviewScoresData.rounds.map((round, i) => ({
234+
x: round,
235+
y: overviewScoresData.scores_by_player[player][i],
236+
}));
231237
const color = colors[colorIndex % colors.length];
232238
colorIndex++;
233239
return {
@@ -241,7 +247,7 @@ function createSimWinsChart() {
241247
};
242248
});
243249

244-
simWinsChart = new Chart(ctx, {
250+
overviewScoresChart = new Chart(ctx, {
245251
type: "line",
246252
data: { datasets },
247253
options: {
@@ -250,7 +256,7 @@ function createSimWinsChart() {
250256
plugins: {
251257
title: {
252258
display: true,
253-
text: `Simulations Won Per Round`,
259+
text: `Scores Per Round`,
254260
},
255261
legend: {
256262
display: true,
@@ -264,17 +270,18 @@ function createSimWinsChart() {
264270
position: "bottom",
265271
},
266272
y: {
267-
title: { display: true, text: "Simulations Won" },
273+
title: { display: true, text: "Score %" },
268274
beginAtZero: true,
275+
max: 100,
269276
},
270277
},
271278
interaction: { intersect: false, mode: "index" },
272279
},
273280
});
274281
}
275282

276-
// Initialize both analyses when DOM is loaded
283+
// Initialize all analyses when DOM is loaded
277284
document.addEventListener("DOMContentLoaded", function () {
278285
initializeAnalysis();
279-
initializeSimWinsChart();
286+
initializeOverviewScoresChart();
280287
});

codeclash/viewer/templates/includes/analysis.html

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,6 @@
22
<section class="analysis-section">
33
<h2><i class="bi bi-graph-up"></i> Analysis</h2>
44

5-
<!-- Sim Wins Per Round Analysis -->
6-
<details class="foldout">
7-
<summary><i class="bi bi-bar-chart-line"></i> Sim Wins Per Round</summary>
8-
<div class="log-content-container">
9-
{% if sim_wins_data and sim_wins_data.players and sim_wins_data.rounds %}
10-
<div class="sim-wins-analysis-container">
11-
<div class="chart-container">
12-
<canvas id="sim-wins-chart" width="800" height="400"></canvas>
13-
</div>
14-
<script type="application/json" id="sim-wins-data">{{ sim_wins_data | tojson }}</script>
15-
</div>
16-
{% else %}
17-
<p>No simulation win data available. This analysis requires games with round stats.</p>
18-
{% endif %}
19-
</div>
20-
</details>
21-
225
<!-- Line Counting Analysis -->
236
<details class="foldout">
247
<summary><i class="bi bi-graph-up-arrow"></i> Line Counting Analysis</summary>

codeclash/viewer/templates/includes/overview.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
<section class="overview-section">
33
<h2><i class="bi bi-bar-chart"></i> Overview</h2>
44

5+
<!-- Scores Per Round Chart -->
6+
{% if sim_wins_data and sim_wins_data.players and sim_wins_data.rounds %}
7+
<div class="chart-container">
8+
<canvas id="overview-scores-chart" width="800" height="400"></canvas>
9+
</div>
10+
<script type="application/json" id="overview-scores-data">{{ sim_wins_data | tojson }}</script>
11+
{% endif %}
12+
513
<div class="overview-summary">
614
<table class="table table-striped table-hover results-table">
715
<thead>

0 commit comments

Comments
 (0)