Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
2353 lines (1982 loc) · 86 KB
/
Copy pathscript.js
File metadata and controls
2353 lines (1982 loc) · 86 KB
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Constants
const SPLITS = {
llm: {
results: 'benchmark_results/results_llm.jsonl',
ppi: 'ppi/ppi_llm.jsonl',
metadata: 'datasets/layton_eval_llm.jsonl'
},
vlm: {
results: 'benchmark_results/results_vlm.jsonl',
ppi: 'ppi/ppi_vlm.jsonl',
metadata: 'datasets/layton_eval_vlm.jsonl'
}
};
const PROVIDER_COLORS = {
'openai': '#10a37f',
'anthropic': '#f4a261',
'google': '#4dabf7',
'gemini': '#4dabf7',
'mistral': '#fcd53f',
'meta': '#0668E1',
'together': '#0055ff',
'doubleword': '#9ca3af',
'default': '#6b7280'
};
const JUDGE_DISPLAY_NAMES = {
'openai': 'OpenAI Judge',
'anthropic': 'Anthropic Judge',
'gemini': 'Gemini Judge',
'google': 'Gemini Judge',
'mistral': 'Mistral Judge'
};
const CATEGORY_DEFINITIONS = {
'Arrange Parts': `In the Arrange Parts puzzles, the player has to move specific parts horizontally and/or vertically to place them in the correct spots. In the benchmark, models have to come up with a clear description of their arrangement.`,
'Button': `In the Button puzzles, you have to tap the correct button to submit your answer. Those are basically multi-choice questions. Random positive answers are kept safe through the justification check.`,
'Circle': `The Circle Puzzles require you to draw a circle around the correct answer. In the benchmark that means the model has to semantically or spatially describe something in an image precisely.`,
'Circle Answer': `In the Circle Answer Puzzles, you are provided with a picture in which you must draw a circle around the correct answer. In the benchmark that means the model has to semantically or spatially describe something in an image precisely.`,
'Input': `In the Input Puzzles, you get one or more input boxes, where you can write your answer. These puzzles usually make you think and calculate to get the answer.`,
'Line': `Line puzzles require players to imagine a line or path mentally.`,
'Logical': `Nothing special about that category, bare reasoning.`,
'Mark Answer': `Puzzles in which you must mark your answer(s). In the benchmark that means the model has to semantically or spatially describe something in an image precisely.`,
'Matchstick': `In the Matchstick Puzzles, you need to move one or more matches to the correct position in a certain amount of moves. They can be rotated and moved. Moving and rotating the same match only counts for 1 move. It requires visualizing the outcome of an action on a physical structure.`,
'Move': `All puzzles in which you move stuff. Plain and simple. Since models cannot move anything, those are tied back to choosing an option or outputting plain text.`,
'Multiple Choice': `These are the Puzzles where you have to select one of the possible choices by tapping it. Random positive answers are kept safe through the justification check.`,
'Pin Board': `Pin Board Puzzles present you with a wooden board with various pins on it. You have to connect the correct pins (with your stylus) to solve these Puzzles. In the benchmark, those riddles require models to output the maximum number of shapes meeting specific constraints that can be drawn on the pinboard.`,
'Press Button': `In the Press Button Puzzles, you are provided with a picture in which you must press a button to choose your answer. This is a multi-choice answer. Random positive answers are kept safe through the justification check.`,
'River': `Puzzles involving a river where several entities must cross it, with constraints to respect. Models have to plan and come up with an optimal strategy, while verifying that they don't break rules on each move.`,
'Rotate and Arrange': `A category for puzzles involving Rotating and Arranging. In the benchmark, those riddles require spatial reasoning and 3D visualization, like visualizing how faces of a dice would render when built up from a 2D plan.`,
'Search': `Puzzles in which you search the picture for your answer. Requires precise description of visual elements.`,
'Select': `In the select puzzles, you must select an option and submit it as your answer. This often implies selecting multiple objects, by a number or label, sometimes in the right order.`,
'Select and Submit': `Puzzles in which you select your chosen answer, then tap the submit button. This often implies selecting multiple answers in a list, or semantically/spatially describing objects.`,
'Selection': `Selection puzzles are puzzles in which the player must tap and select one of many choices to find the answer of the puzzle. These are similar to Multiple Choice-esque puzzles from the previous Professor Layton games. In the benchmark, models have to come up with a visual description of the object they want to select.`,
'Strategy': `Strategy puzzles, as the name suggests, deal with using tactical thinking to solve the puzzle.`,
'Tap Answer': `All puzzles that are solved by tapping the correct answer. All of which being multiple choice. Random positive answers are kept safe through the justification check.`,
'Touch': `In the touch puzzles, the player must select an option and submit it as your answer. In the benchmark, models must semantically or spatially describe the object instead of touching it.`,
'Write Answer': `In the Write Answer Puzzles, you need to write your answer in the provided boxes. Free-text answer.`
};
// State
const state = {
currentSplit: 'llm',
cache: {
llm: { judges: [] },
vlm: { judges: [] }
},
activeTab: 'leaderboard',
selectedRiddleId: null,
filters: {
categories: new Set(['all']),
picarats: new Set(['all']),
successRates: new Set(['all']),
disabledAnalyticsModels: new Set(), // For toggling in legend
selectedAnalyticsCategory: null // New: for category performance analysis
}
};
let categorySelect = null;
let picaratsSelect = null;
let successRateSelect = null;
let analyticsCategorySelect = null; // New selector for analytics tab
// Color helper
function getModelColor(modelName, provider, index, total) {
const baseColor = PROVIDER_COLORS[provider] || PROVIDER_COLORS['default'];
const hexToRgb = (hex) => {
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result ? {
r: parseInt(result[1], 16),
g: parseInt(result[2], 16),
b: parseInt(result[3], 16)
} : { r: 107, g: 114, b: 128 };
};
const rgbToHsl = (r, g, b) => {
r /= 255; g /= 255; b /= 255;
const max = Math.max(r, g, b), min = Math.min(r, g, b);
let h, s, l = (max + min) / 2;
if (max === min) {
h = s = 0;
} else {
const d = max - min;
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
switch (max) {
case r: h = (g - b) / d + (g < b ? 6 : 0); break;
case g: h = (b - r) / d + 2; break;
case b: h = (r - g) / d + 4; break;
}
h /= 6;
}
return [h * 360, s * 100, l * 100];
};
const rgb = hexToRgb(baseColor);
const [h, s, l] = rgbToHsl(rgb.r, rgb.g, rgb.b);
let finalLightness;
if (total <= 1) {
finalLightness = Math.max(45, l);
} else {
const minL = 45;
const maxL = 85;
finalLightness = minL + (index / (total - 1)) * (maxL - minL);
}
// Convert HSL back to RGB for better browser compatibility
const hslToRgb = (h, s, l) => {
s /= 100; l /= 100;
const k = n => (n + h / 30) % 12;
const a = s * Math.min(l, 1 - l);
const f = n => l - a * Math.max(-1, Math.min(k(n) - 3, 9 - k(n), 1));
return [
Math.round(255 * f(0)),
Math.round(255 * f(8)),
Math.round(255 * f(4))
];
};
const [r, g, b] = hslToRgb(h, Math.min(100, s + 15), finalLightness);
return `rgb(${r}, ${g}, ${b})`;
}
// DOM Elements
const elements = {
splitSelect: document.getElementById('split-select'),
tabPanes: document.querySelectorAll('.tab-pane'),
leaderboardBody: document.querySelector('#leaderboard-table tbody'),
rankChart: document.getElementById('rank-chart'),
radarMainContainer: document.getElementById('radar-chart-main-container'),
radarLegend: document.getElementById('radar-chart-legend'),
riddleGrid: document.getElementById('riddle-grid'),
riddleSearch: document.getElementById('riddle-search'),
modal: document.getElementById('riddle-modal'),
modalBody: document.getElementById('modal-body'),
modalTitle: document.getElementById('modal-title'),
closeModal: document.querySelector('.close-modal')
};
// Init
document.addEventListener('DOMContentLoaded', () => {
initEventListeners();
loadSplit('llm'); // Load default
// Resize handler with debounce
let resizeTimer;
window.addEventListener('resize', () => {
clearTimeout(resizeTimer);
resizeTimer = setTimeout(() => {
if (state.activeTab === 'leaderboard') {
renderLeaderboard();
} else if (state.activeTab === 'analytics') {
renderAnalytics();
}
}, 250);
});
});
class MultiSelect {
constructor(containerId, placeholder, onChange) {
this.container = document.getElementById(containerId);
this.placeholder = placeholder;
this.onChange = onChange;
this.selectedValues = new Set(['all']);
this.optionsMap = new Map();
this.allOptions = []; // Store original options for searching
if (!this.container) return;
this.trigger = this.container.querySelector('.multiselect-trigger');
this.dropdown = this.container.querySelector('.multiselect-dropdown');
this.triggerSpan = this.trigger.querySelector('span'); // First span
// Search support
this.searchInput = this.container.querySelector('.model-search-input');
if (this.searchInput) {
this.searchInput.addEventListener('input', () => this.filterOptions());
this.searchInput.addEventListener('click', (e) => e.stopPropagation());
}
this.initEvents();
}
initEvents() {
this.trigger.addEventListener('click', (e) => {
e.stopPropagation();
this.toggle();
});
// Close when clicking outside
document.addEventListener('click', (e) => {
if (!this.container.contains(e.target)) {
this.close();
}
});
}
toggle() {
// Close others
document.querySelectorAll('.multiselect-dropdown').forEach(d => {
if (d !== this.dropdown) d.classList.remove('show');
});
document.querySelectorAll('.multiselect-trigger').forEach(t => {
if (t !== this.trigger) t.classList.remove('active');
});
this.dropdown.classList.toggle('show');
this.trigger.classList.toggle('active');
if (this.dropdown.classList.contains('show') && this.searchInput) {
this.searchInput.focus();
this.filterOptions(); // Reset filter on open
}
}
close() {
this.dropdown.classList.remove('show');
this.trigger.classList.remove('active');
}
setOptions(options) {
this.allOptions = options;
this.optionsMap = new Map(options.map(o => [String(o.value), o.label]));
this.renderOptions(options);
this.updateTrigger();
}
filterOptions() {
if (!this.searchInput) return;
const query = this.searchInput.value.toLowerCase();
const filtered = this.allOptions.filter(o =>
o.label.toLowerCase().includes(query) ||
(o.provider && o.provider.toLowerCase().includes(query))
);
this.renderOptions(filtered, query.length > 0);
}
renderOptions(options, isSearching = false) {
// Find or create options list container
let listContainer = this.dropdown.querySelector('.model-options-list') || this.dropdown;
// If it's the dropdown itself, we need to preserve the header and search wrapper
const header = this.dropdown.querySelector('.multiselect-header');
const searchWrapper = this.dropdown.querySelector('.model-search-wrapper');
// Clear only the options
if (listContainer === this.dropdown) {
// Keep header and search
const children = Array.from(this.dropdown.children);
children.forEach(child => {
if (child !== header && child !== searchWrapper) {
this.dropdown.removeChild(child);
}
});
} else {
listContainer.innerHTML = '';
}
if (!header && !isSearching) {
// Header with Clear button (only if not already there)
const newHeader = document.createElement('div');
newHeader.className = 'multiselect-header';
newHeader.innerHTML = `
<span>Select ${this.placeholder}</span>
<button class="btn-clear">Clear</button>
`;
newHeader.querySelector('.btn-clear').onclick = (e) => {
e.stopPropagation();
this.selectAll();
};
if (searchWrapper) {
this.dropdown.insertBefore(newHeader, searchWrapper);
} else {
this.dropdown.prepend(newHeader);
}
}
// All Option (only if not searching)
if (!isSearching) {
this.addOption('all', `All ${this.placeholder}`, listContainer);
}
// Other Options
options.forEach(opt => {
this.addOption(opt.value, opt.label, listContainer);
});
if (options.length === 0) {
const noRes = document.createElement('div');
noRes.className = 'multiselect-option no-results';
noRes.style.color = 'var(--text-muted)';
noRes.style.justifyContent = 'center';
noRes.textContent = 'No matches found';
listContainer.appendChild(noRes);
}
}
addOption(value, label, container) {
const div = document.createElement('div');
div.className = 'multiselect-option';
const strValue = String(value);
div.innerHTML = `
<input type="checkbox" value="${strValue}" ${this.selectedValues.has(strValue) ? 'checked' : ''}>
<span>${label}</span>
`;
const checkbox = div.querySelector('input');
div.onclick = (e) => {
e.stopPropagation();
if (e.target !== checkbox) {
checkbox.checked = !checkbox.checked;
this.handleSelection(strValue, checkbox.checked);
}
};
checkbox.onclick = (e) => {
e.stopPropagation();
this.handleSelection(strValue, checkbox.checked);
};
container.appendChild(div);
}
handleSelection(value, isChecked) {
if (value === 'all') {
if (isChecked) {
this.selectAll();
} else {
this.selectedValues.clear();
this.selectedValues.add('all');
}
} else {
if (isChecked) {
this.selectedValues.delete('all');
this.selectedValues.add(value);
} else {
this.selectedValues.delete(value);
if (this.selectedValues.size === 0) {
this.selectedValues.add('all');
}
}
}
this.renderOptionsState();
this.updateTrigger();
if (this.onChange) this.onChange(this.selectedValues);
}
selectAll() {
this.selectedValues.clear();
this.selectedValues.add('all');
this.renderOptionsState();
this.updateTrigger();
if (this.onChange) this.onChange(this.selectedValues);
}
renderOptionsState() {
const checkboxes = this.dropdown.querySelectorAll('input');
checkboxes.forEach(cb => {
cb.checked = this.selectedValues.has(cb.value);
});
}
updateTrigger() {
if (this.selectedValues.has('all')) {
this.triggerSpan.textContent = `All ${this.placeholder}`;
} else {
const count = this.selectedValues.size;
if (count === 1) {
const val = Array.from(this.selectedValues)[0];
this.triggerSpan.textContent = this.optionsMap.get(val) || val;
} else {
this.triggerSpan.textContent = `${count} ${this.placeholder}`;
}
}
}
}
class SearchableSelect {
constructor(container, options, initialValue, onSelect, placeholder = 'Select an option') {
this.container = container;
this.options = options; // [{value, label, provider}]
this.filteredOptions = options;
this.onSelect = onSelect;
this.selectedValue = initialValue;
this.placeholder = placeholder;
this.highlightedIndex = -1;
this.isOpen = false;
this.render();
}
render() {
this.container.innerHTML = `
<div class="model-selector-wrapper">
<button class="model-select-trigger">
<span class="current-value"></span>
<span class="arrow">▼</span>
</button>
<div class="model-select-dropdown">
<input type="text" class="model-search-input" placeholder="${this.placeholder}...">
<div class="model-options-list"></div>
</div>
</div>
`;
this.trigger = this.container.querySelector('.model-select-trigger');
this.dropdown = this.container.querySelector('.model-select-dropdown');
this.searchInput = this.container.querySelector('.model-search-input');
this.optionsList = this.container.querySelector('.model-options-list');
this.currentValueSpan = this.container.querySelector('.current-value');
this.updateTriggerText();
this.renderOptions(this.options);
this.trigger.onclick = (e) => {
e.stopPropagation();
this.toggle();
};
this.searchInput.onclick = (e) => e.stopPropagation();
this.searchInput.oninput = () => {
const query = this.searchInput.value.toLowerCase();
this.filteredOptions = this.options.filter(o =>
o.label.toLowerCase().includes(query) ||
(o.provider && o.provider.toLowerCase().includes(query))
);
this.highlightedIndex = this.filteredOptions.length > 0 ? 0 : -1;
this.renderOptions(this.filteredOptions);
};
this.searchInput.onkeydown = (e) => {
if (e.key === 'ArrowDown') {
e.preventDefault();
this.highlightedIndex = (this.highlightedIndex + 1) % this.filteredOptions.length;
this.renderOptions(this.filteredOptions);
this.scrollToHighlighted();
} else if (e.key === 'ArrowUp') {
e.preventDefault();
this.highlightedIndex = (this.highlightedIndex - 1 + this.filteredOptions.length) % this.filteredOptions.length;
this.renderOptions(this.filteredOptions);
this.scrollToHighlighted();
} else if (e.key === 'Enter') {
e.preventDefault();
if (this.highlightedIndex >= 0 && this.highlightedIndex < this.filteredOptions.length) {
this.select(this.filteredOptions[this.highlightedIndex].value);
}
} else if (e.key === 'Escape') {
this.close();
}
};
document.addEventListener('click', () => this.close());
}
scrollToHighlighted() {
const highlightedEl = this.optionsList.querySelector('.model-option.highlighted');
if (highlightedEl) {
highlightedEl.scrollIntoView({ block: 'nearest' });
}
}
updateTriggerText() {
const selected = this.options.find(o => o.value === this.selectedValue);
if (selected) {
const providerPrefix = selected.provider ? `<span class="provider-prefix">${selected.provider}:</span> ` : '';
this.currentValueSpan.innerHTML = `${providerPrefix}${selected.label}`;
} else {
this.currentValueSpan.textContent = this.placeholder;
}
}
renderOptions(options) {
this.optionsList.innerHTML = '';
options.forEach((opt, index) => {
const div = document.createElement('div');
const isSelected = opt.value === this.selectedValue;
const isHighlighted = index === this.highlightedIndex;
div.className = `model-option ${isSelected ? 'selected' : ''} ${isHighlighted ? 'highlighted' : ''}`;
const providerPrefix = opt.provider ? `<span class="provider-prefix">${opt.provider}:</span> ` : '';
div.innerHTML = `${providerPrefix}${opt.label}`;
div.onclick = (e) => {
e.stopPropagation();
this.select(opt.value);
};
this.optionsList.appendChild(div);
});
}
toggle() {
this.isOpen = !this.isOpen;
this.dropdown.classList.toggle('show', this.isOpen);
if (this.isOpen) {
this.searchInput.value = '';
this.filteredOptions = this.options;
// Set highlighted to current selection if it exists in filtered options
this.highlightedIndex = this.filteredOptions.findIndex(o => o.value === this.selectedValue);
if (this.highlightedIndex === -1 && this.filteredOptions.length > 0) {
this.highlightedIndex = 0;
}
this.renderOptions(this.filteredOptions);
this.searchInput.focus();
setTimeout(() => this.scrollToHighlighted(), 0);
}
}
close() {
this.isOpen = false;
this.dropdown.classList.remove('show');
}
select(value) {
this.selectedValue = value;
this.updateTriggerText();
this.close();
if (this.onSelect) this.onSelect(value);
}
}
function initEventListeners() {
// Split Selector
elements.splitSelect.addEventListener('change', (e) => {
loadSplit(e.target.value);
});
// Tabs
const tabs = document.querySelectorAll('.nav-btn');
tabs.forEach(btn => {
btn.addEventListener('click', () => {
switchTab(btn.dataset.tab);
});
});
// Riddle Search
elements.riddleSearch.addEventListener('input', () => filterRiddleGrid());
// Filters - Init MultiSelects
categorySelect = new MultiSelect('category-filter-container', 'Categories', (selected) => {
state.filters.categories = new Set(selected);
filterRiddleGrid();
});
picaratsSelect = new MultiSelect('picarats-filter-container', 'Picarats', (selected) => {
state.filters.picarats = new Set(selected);
filterRiddleGrid();
});
successRateSelect = new MultiSelect('success-filter-container', 'Success Rates', (selected) => {
state.filters.successRates = new Set(selected);
filterRiddleGrid();
});
// Modal Events
elements.closeModal.addEventListener('click', closeModal);
window.addEventListener('click', (e) => {
if (e.target === elements.modal) {
closeModal();
}
});
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape' && elements.modal.style.display === 'block') {
closeModal();
}
});
}
function switchTab(tabId) {
state.activeTab = tabId;
// Update buttons
const tabs = document.querySelectorAll('.nav-btn');
tabs.forEach(btn => {
btn.classList.toggle('active', btn.dataset.tab === tabId);
});
// Update panes
elements.tabPanes.forEach(pane => {
pane.classList.toggle('active', pane.id === tabId);
});
// Trigger render if needed (e.g. chart resize)
if (tabId === 'leaderboard') {
renderLeaderboard(); // Re-render to ensure chart size is correct
} else if (tabId === 'analytics') {
renderAnalytics();
} else if (tabId === 'paper') {
loadPaperContent();
}
}
async function loadSplit(split) {
console.log(`loadSplit called for: ${split}`);
state.currentSplit = split;
// Check cache
if (state.cache[split].loaded) {
console.log(`Split ${split} already loaded, using cache.`);
onDataLoaded();
return;
}
const config = SPLITS[split];
if (!config) {
console.error(`No configuration found for split: ${split}`);
return;
}
try {
console.log(`Loading data files for split: ${split}...`);
// Load all data in parallel for better performance
const [results, metadata, ppi] = await Promise.all([
loadJSONL(config.results),
loadJSONL(config.metadata),
loadJSONL(config.ppi)
]);
console.log(`Data files received for ${split}. Processing...`);
state.cache[split].results = results;
// Build model-to-provider map
state.cache[split].modelProviders = new Map(results.map(r => [r.model, r.provider]));
// Index Metadata by ID
state.cache[split].riddles = new Map(metadata.map(r => [r.id, r]));
// Attach provider to PPI if missing
ppi.forEach(p => {
if (!p.provider) {
p.provider = getProviderFromModelName(p.model, state.cache[split].modelProviders);
}
});
state.cache[split].ppi = ppi;
// Identify all judges for this split
const judges = new Set();
ppi.forEach(p => {
Object.keys(p).forEach(k => {
if (k.startsWith('both_correct_')) {
judges.add(k.replace('both_correct_', ''));
}
});
});
state.cache[split].judges = Array.from(judges).sort();
state.cache[split].loaded = true;
console.log(`Successfully loaded and processed ${results.length} results, ${metadata.length} riddles, and ${ppi.length} predictions.`);
onDataLoaded();
} catch (e) {
console.error("Failed to load data for split " + split, e);
if (split !== 'llm') {
alert(`Data for ${split} split not found or incomplete. Check console.`);
}
}
}
async function loadJSONL(url) {
try {
console.log(`Fetching: ${url}`);
const response = await fetch(url);
if (!response.ok) {
console.error(`Failed to fetch ${url}: ${response.status} ${response.statusText}`);
throw new Error(`HTTP ${response.status}`);
}
const text = await response.text();
const lines = text.trim().split('\n');
console.log(`Received ${lines.length} lines from ${url}`);
return lines
.filter(line => line.trim())
.map((line, index) => {
try {
return JSON.parse(line);
} catch (e) {
if (index === 0) {
console.warn(`Potential JSON parse error on first line of ${url}. Check for BOM or encoding issues.`, e);
}
return null;
}
})
.filter(item => item !== null);
} catch (e) {
console.warn(`Could not load ${url}. Error:`, e);
return []; // Return empty array on failure
}
}
function onDataLoaded() {
renderLeaderboard();
populateRiddleList();
if (state.activeTab === 'analytics') {
renderAnalytics();
}
}
// --- Leaderboard Logic ---
function renderLeaderboard() {
const data = state.cache[state.currentSplit].results;
if (!data) return;
// Clear table
elements.leaderboardBody.innerHTML = '';
// Render Rows
data.forEach(row => {
const tr = document.createElement('tr');
// Rank
const tdRank = document.createElement('td');
tdRank.textContent = row.rank;
tr.appendChild(tdRank);
// Model
const tdModel = document.createElement('td');
tdModel.textContent = row.model;
if (row.provider) {
// Optional: Add provider badge or color
}
tr.appendChild(tdModel);
// Hints
const tdHints = document.createElement('td');
tdHints.textContent = row.n_hints !== undefined ? row.n_hints : '0';
tr.appendChild(tdHints);
// Score
const tdScore = document.createElement('td');
tdScore.textContent = row.score.toFixed(1);
tr.appendChild(tdScore);
// CI
const tdCI = document.createElement('td');
tdCI.textContent = `±${row['95% CI (±)']}`;
tr.appendChild(tdCI);
// Rank Spread
const tdSpread = document.createElement('td');
// Format: "1 <--> 2" -> "[1] ⟷ [2]"
const spreadParts = row.rank_spread.split('<-->').map(s => s.trim());
if (spreadParts.length === 2) {
tdSpread.innerHTML = `<span class="rank-spread-arrow">[${spreadParts[0]}] ⟷ [${spreadParts[1]}]</span>`;
} else {
tdSpread.textContent = row.rank_spread;
}
tr.appendChild(tdSpread);
// Provider
const tdProvider = document.createElement('td');
tdProvider.textContent = row.provider || '-';
tr.appendChild(tdProvider);
elements.leaderboardBody.appendChild(tr);
});
// Render Chart
renderRankChart(data);
}
function renderRankChart(data) {
const container = elements.rankChart;
container.innerHTML = '';
const isMobile = window.innerWidth <= 768;
const width = isMobile ? 800 : (container.clientWidth || 800);
const modelHeight = isMobile ? 25 : 30; // pixels per model
const height = Math.max(isMobile ? 300 : 400, data.length * modelHeight + (isMobile ? 100 : 150)); // Dynamic height
const padding = {
top: 40,
right: isMobile ? 20 : 60,
bottom: isMobile ? 50 : 60,
left: isMobile ? 180 : 300 // Increased left padding for model names
};
// Detect Score Range (0-1 or 0-100)
let maxScore = 100;
const allScoresSmall = data.every(d => d.score <= 1);
if (allScoresSmall) maxScore = 1;
// Calculate dynamic Score range
let minDataScore = maxScore;
let maxDataScore = 0;
data.forEach(d => {
const ci = d['95% CI (±)'];
const low = d.score - ci;
const high = d.score + ci;
if (low < minDataScore) minDataScore = low;
if (high > maxDataScore) maxDataScore = high;
});
const paddingVal = allScoresSmall ? 0.01 : 1;
let axisMin = Math.max(0, minDataScore - paddingVal);
let axisMax = Math.min(maxScore, maxDataScore + paddingVal);
if (axisMin >= axisMax) {
axisMin = 0;
axisMax = maxScore;
}
const chartHeight = height - padding.top - padding.bottom;
const chartWidth = width - padding.left - padding.right;
// SVG
const svgNS = "http://www.w3.org/2000/svg";
const svg = document.createElementNS(svgNS, "svg");
svg.setAttribute("width", width); // Force width to allow scroll
svg.setAttribute("height", height);
svg.setAttribute("viewBox", `0 0 ${width} ${height}`);
svg.style.display = "block";
svg.style.width = width + "px"; // Ensure width is strictly applied
svg.style.minWidth = width + "px"; // Ensure width is strictly applied
container.appendChild(svg);
// X Scale function (Score)
const xScale = (score) => {
return padding.left + ((score - axisMin) / (axisMax - axisMin)) * chartWidth;
};
// Y Scale function (Model Index)
const yScale = (index) => {
const step = chartHeight / data.length;
return padding.top + step * index + step / 2;
};
// Draw Grid Lines (Vertical - Score Ticks)
const tickCount = isMobile ? 5 : 10; // Fewer ticks on mobile
for (let i = 0; i <= tickCount; i++) {
const val = axisMin + (i / tickCount) * (axisMax - axisMin);
const x = xScale(val);
// Grid Line
const gridLine = document.createElementNS(svgNS, "line");
gridLine.setAttribute("x1", x);
gridLine.setAttribute("y1", padding.top);
gridLine.setAttribute("x2", x);
gridLine.setAttribute("y2", height - padding.bottom);
gridLine.setAttribute("stroke", "var(--border-color)");
gridLine.setAttribute("stroke-opacity", "0.3");
svg.appendChild(gridLine);
// Label (Bottom)
const text = document.createElementNS(svgNS, "text");
text.setAttribute("x", x);
text.setAttribute("y", height - padding.bottom + 20);
text.setAttribute("text-anchor", "middle");
text.setAttribute("fill", "var(--text-muted)");
text.setAttribute("font-size", isMobile ? "9px" : "11px");
text.textContent = val.toFixed(allScoresSmall ? 2 : 0);
svg.appendChild(text);
// Label (Top - optional)
if (!isMobile) {
const textTop = text.cloneNode(true);
textTop.setAttribute("y", padding.top - 10);
svg.appendChild(textTop);
}
}
// Draw Grid Lines (Horizontal) - Model Ticks
data.forEach((_, index) => {
const y = yScale(index);
const gridLine = document.createElementNS(svgNS, "line");
gridLine.setAttribute("x1", padding.left);
gridLine.setAttribute("y1", y);
gridLine.setAttribute("x2", width - padding.right);
gridLine.setAttribute("y2", y);
gridLine.setAttribute("stroke", "var(--border-color)");
gridLine.setAttribute("stroke-opacity", "0.2");
svg.appendChild(gridLine);
});
// Draw Data Points
data.forEach((row, index) => {
const y = yScale(index);
const score = row.score;
const ci = row['95% CI (±)'];
const color = PROVIDER_COLORS[row.provider] || PROVIDER_COLORS['default'];
const xScore = xScale(score);
const xLow = xScale(score - ci);
const xHigh = xScale(score + ci);
const g = document.createElementNS(svgNS, "g");
// Horizontal CI Line
const line = document.createElementNS(svgNS, "line");
line.setAttribute("x1", xLow);
line.setAttribute("y1", y);
line.setAttribute("x2", xHigh);
line.setAttribute("y2", y);
line.setAttribute("stroke", color);
line.setAttribute("stroke-width", "2");
line.setAttribute("opacity", "0.6");
g.appendChild(line);
// Caps
const capHeight = isMobile ? 6 : 10;
// Left Cap
const cap1 = document.createElementNS(svgNS, "line");
cap1.setAttribute("x1", xLow);
cap1.setAttribute("y1", y - capHeight/2);
cap1.setAttribute("x2", xLow);
cap1.setAttribute("y2", y + capHeight/2);
cap1.setAttribute("stroke", color);
cap1.setAttribute("stroke-width", "2");
g.appendChild(cap1);
// Right Cap
const cap2 = document.createElementNS(svgNS, "line");
cap2.setAttribute("x1", xHigh);
cap2.setAttribute("y1", y - capHeight/2);
cap2.setAttribute("x2", xHigh);
cap2.setAttribute("y2", y + capHeight/2);
cap2.setAttribute("stroke", color);
cap2.setAttribute("stroke-width", "2");
g.appendChild(cap2);
// Score Point
const circle = document.createElementNS(svgNS, "circle");
circle.setAttribute("cx", xScore);
circle.setAttribute("cy", y);
circle.setAttribute("r", isMobile ? "3" : "4");
circle.setAttribute("fill", "var(--bg-surface)");
circle.setAttribute("stroke", color);
circle.setAttribute("stroke-width", "2");
g.appendChild(circle);
// Model Name Label (Horizontal on Y-Axis)
const nameLabel = document.createElementNS(svgNS, "text");
nameLabel.setAttribute("x", padding.left - 10);
nameLabel.setAttribute("y", y + 4);
nameLabel.setAttribute("text-anchor", "end");
nameLabel.setAttribute("fill", color);
nameLabel.setAttribute("font-size", isMobile ? "10px" : "12px");
nameLabel.setAttribute("font-weight", "500");
// Truncate model name if too long
let modelName = row.model;
const maxLen = isMobile ? 28 : 45; // Increased to 45 for 300px padding
if (modelName.length > maxLen) {
modelName = modelName.substring(0, maxLen - 3) + "...";
}
nameLabel.textContent = modelName;
g.appendChild(nameLabel);
svg.appendChild(g);
});
// Add X-axis label "Model Score" with info icon
const xAxisLabel = document.createElementNS(svgNS, "text");
xAxisLabel.setAttribute("x", padding.left + chartWidth / 2);
xAxisLabel.setAttribute("y", height - 10);
xAxisLabel.setAttribute("text-anchor", "middle");
xAxisLabel.setAttribute("fill", "var(--text-header)");
xAxisLabel.setAttribute("font-size", isMobile ? "11px" : "13px");
xAxisLabel.setAttribute("font-weight", "600");
xAxisLabel.style.cursor = "help";
xAxisLabel.textContent = "Model Score";
svg.appendChild(xAxisLabel);
// Add info icon next to axis label (smaller, positioned above and to the right)
const iconOffset = isMobile ? 50 : 48; // Increased from 42 to 50 to avoid overlap
const infoIconX = padding.left + chartWidth / 2 + iconOffset;
const infoIconY = height - (isMobile ? 18 : 22);
const tooltipText = "Model score is a 95%-CI estimation of the % of correct answers a human annotator would have attributed to the model. Answer correctness is based on both answer and justification.";
const infoGroup = document.createElementNS(svgNS, "g");
infoGroup.setAttribute("class", "svg-info-icon");
infoGroup.style.cursor = "help";
infoGroup.setAttribute("pointer-events", "all");