Skip to content

Commit 14dc13a

Browse files
committed
feat: add run distribution chart
1 parent 4a3d833 commit 14dc13a

2 files changed

Lines changed: 99 additions & 9 deletions

File tree

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script>
1212
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
1313
<script src="https://cdn.jsdelivr.net/npm/heroicons@2.0.18/24/outline/index.js"></script>
14+
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
1415
<style>
1516
/* Ensure no horizontal scrolling on mobile */
1617
html,

js/app.js

Lines changed: 98 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Main application JavaScript for BalatroBench
22

33
// Global state
4-
const currentVersion = 'v0.4.0';
4+
const currentVersion = 'v0.6.0';
55
const currentStrategy = 'default';
66

77
// Initialize the app when DOM is loaded
@@ -197,15 +197,15 @@ function renderIndividualRunsDetailTable(runs) {
197197
${runs.map((run, runIndex) => {
198198
const totalToolCalls = run.successful_calls + (run.error_calls?.length || 0) + (run.failed_calls?.length || 0);
199199
const totalTokens = run.total_input_tokens + run.total_output_tokens;
200-
200+
201201
return `
202202
<tr class="hover:bg-gray-500 transition-colors">
203203
<td class="px-2 py-3 text-center">
204204
<span class="text-xs sm:text-sm font-bold text-white">#${runIndex + 1}</span>
205205
</td>
206206
<td class="px-2 py-3 text-center">
207-
${run.completed ?
208-
'<span class="text-green-400 text-lg">✓</span>' :
207+
${run.completed ?
208+
'<span class="text-green-400 text-lg">✓</span>' :
209209
'<span class="text-red-400 text-lg">✗</span>'
210210
}
211211
</td>
@@ -290,7 +290,7 @@ function renderModelDetails(modelData) {
290290
</div>
291291
</div>
292292
</div>
293-
293+
294294
<!-- Average Stats Card -->
295295
<div class="bg-gray-700 rounded-lg p-4 mb-4">
296296
<h4 class="font-semibold text-white mb-3 text-lg">Average Statistics</h4>
@@ -357,14 +357,22 @@ function renderModelDetails(modelData) {
357357
</div>
358358
</div>
359359
</div>
360-
360+
361361
<!-- Individual Runs Table -->
362-
<div class="bg-gray-700 rounded-lg p-4">
362+
<div class="bg-gray-700 rounded-lg p-4 mb-4">
363363
<h4 class="font-semibold text-white mb-3 text-lg">Individual Runs</h4>
364364
<div class="overflow-x-auto">
365365
${renderIndividualRunsDetailTable(runs)}
366366
</div>
367367
</div>
368+
369+
<!-- Final Round Distribution Chart -->
370+
<div class="bg-gray-700 rounded-lg p-4">
371+
<h4 class="font-semibold text-white mb-3 text-lg">Final Round Distribution</h4>
372+
<div class="h-64">
373+
<canvas id="finalRoundChart-${modelData.config.model.replace(/[^a-zA-Z0-9]/g, '-')}"></canvas>
374+
</div>
375+
</div>
368376
</div>
369377
`;
370378
}
@@ -463,6 +471,11 @@ async function loadModelDetails(modelPath, index) {
463471
// Render detailed view
464472
statsRow.querySelector('td').innerHTML = renderModelDetails(modelData);
465473

474+
// Create final round distribution chart after DOM is updated
475+
setTimeout(() => {
476+
createFinalRoundDistributionChart(modelData);
477+
}, 100);
478+
466479
} catch (error) {
467480
console.error('Error loading model details:', error);
468481
statsRow.querySelector('td').innerHTML =
@@ -544,7 +557,7 @@ async function loadCommunityStrategies() {
544557
</div>
545558
<p class="text-gray-300 mb-4">${strategy.description}</p>
546559
<div class="flex flex-wrap gap-2 mb-4">
547-
${strategy.tags ? strategy.tags.map(tag =>
560+
${strategy.tags ? strategy.tags.map(tag =>
548561
`<span class="bg-gray-700 text-gray-300 px-2 py-1 rounded text-xs">${tag}</span>`
549562
).join('') : ''}
550563
</div>
@@ -594,6 +607,81 @@ function tryStrategy(title) {
594607
`Trying strategy: ${title}\n\nThis would redirect to a page where you can test the strategy.`);
595608
}
596609

610+
// Create final round distribution chart
611+
function createFinalRoundDistributionChart(modelData) {
612+
const chartId = `finalRoundChart-${modelData.config.model.replace(/[^a-zA-Z0-9]/g, '-')}`;
613+
const canvas = document.getElementById(chartId);
614+
615+
if (!canvas) return;
616+
617+
// Extract final round data from all runs
618+
const finalRounds = modelData.stats.map(run => run.final_round);
619+
620+
// Create frequency distribution
621+
const roundCounts = {};
622+
finalRounds.forEach(round => {
623+
roundCounts[round] = (roundCounts[round] || 0) + 1;
624+
});
625+
626+
// Prepare data for Chart.js
627+
const rounds = Object.keys(roundCounts).map(Number).sort((a, b) => a - b);
628+
const counts = rounds.map(round => roundCounts[round]);
629+
630+
const ctx = canvas.getContext('2d');
631+
new Chart(ctx, {
632+
type: 'bar',
633+
data: {
634+
labels: rounds.map(r => `Round ${r}`),
635+
datasets: [{
636+
label: 'Number of Runs',
637+
data: counts,
638+
backgroundColor: 'rgba(59, 130, 246, 0.8)',
639+
borderColor: 'rgba(59, 130, 246, 1)',
640+
borderWidth: 1
641+
}]
642+
},
643+
options: {
644+
responsive: true,
645+
maintainAspectRatio: false,
646+
plugins: {
647+
legend: {
648+
display: false
649+
}
650+
},
651+
scales: {
652+
y: {
653+
beginAtZero: true,
654+
ticks: {
655+
stepSize: 1,
656+
color: '#9CA3AF'
657+
},
658+
grid: {
659+
color: 'rgba(156, 163, 175, 0.2)'
660+
},
661+
title: {
662+
display: true,
663+
text: 'Number of Runs',
664+
color: '#9CA3AF'
665+
}
666+
},
667+
x: {
668+
ticks: {
669+
color: '#9CA3AF'
670+
},
671+
grid: {
672+
color: 'rgba(156, 163, 175, 0.2)'
673+
},
674+
title: {
675+
display: true,
676+
text: 'Final Round',
677+
color: '#9CA3AF'
678+
}
679+
}
680+
}
681+
}
682+
});
683+
}
684+
597685
// Export functions for global access
598686
window.BalatroBench = {
599687
loadLeaderboard,
@@ -603,5 +691,6 @@ window.BalatroBench = {
603691
tryStrategy,
604692
loadModelDetails,
605693
toggleRunDetails,
606-
initializeLeaderboard
694+
initializeLeaderboard,
695+
createFinalRoundDistributionChart
607696
};

0 commit comments

Comments
 (0)