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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Checker-V1.1: Dynamic-SUPERB Validator</title>
    <style>
        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            margin: 0;
            padding: 20px;
            background: linear-gradient(120deg, #f8fafc 0%, #e9ecef 100%);
            color: #212529;
        }
        
        /* Menu Styles */
        .menu-container {
            position: fixed;
            top: 15px;
            left: 15px;
            z-index: 1000;
        }
        
        .menu-icon {
            font-size: 28px;
            cursor: pointer;
            user-select: none;
            color: #667eea;
            background: white;
            padding: 8px 12px;
            border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.15);
            transition: all 0.2s ease;
        }
        
        .menu-icon:hover {
            background: #667eea;
            color: white;
            transform: scale(1.05);
        }
        
        .menu-list {
            display: none;
            position: absolute;
            top: 50px;
            left: 0;
            background: white;
            border: 1px solid #dee2e6;
            border-radius: 8px;
            box-shadow: 0 4px 16px rgba(0,0,0,0.15);
            min-width: 220px;
            font-size: 14px;
            overflow: hidden;
        }
        
        .menu-list.show {
            display: block;
            animation: slideDown 0.2s ease;
        }
        
        @keyframes slideDown {
            from { opacity: 0; transform: translateY(-10px); }
            to { opacity: 1; transform: translateY(0); }
        }
        
        .menu-list a {
            display: block;
            padding: 12px 16px;
            color: #495057;
            text-decoration: none;
            border-bottom: 1px solid #f8f9fa;
            transition: background-color 0.2s ease;
        }
        
        .menu-list a:last-child {
            border-bottom: none;
        }
        
        .menu-list a:hover {
            background-color: #667eea;
            color: white;
        }
        
        .menu-list a::before {
            content: "β†’ ";
            margin-right: 8px;
            opacity: 0;
            transition: opacity 0.2s ease;
        }
        
        .menu-list a:hover::before {
            opacity: 1;
        }
        
        .container {
            max-width: 800px;
            margin: 0 auto;
            background: white;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            overflow: hidden;
        }
        
        .header {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 30px;
            text-align: center;
        }
        
        .header h1 {
            margin: 0;
            font-size: 2.5em;
            font-weight: 300;
        }
        
        .controls {
            padding: 20px 30px;
            border-bottom: 1px solid #dee2e6;
            background: #f8f9fa;
        }
        
        .upload-section {
            background: #f5f7fa;
            border-radius: 10px;
            padding: 24px;
            margin-bottom: 24px;
            border: 1.5px solid #e0e3e8;
        }
        
        label {
            display: block;
            margin-bottom: 5px;
            font-weight: 600;
            color: #495057;
        }
        
        input[type="file"] {
            width: 100%;
            margin: 10px 0;
            padding: 12px;
            border: 2px solid #dee2e6;
            border-radius: 6px;
            background: white;
        }
        
        .btn {
            background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 12px 28px;
            border: none;
            border-radius: 6px;
            cursor: pointer;
            font-size: 1.08em;
            font-weight: 600;
            margin: 8px 12px 0 0;
            transition: transform 0.2s;
        }
        
        .btn:hover {
            transform: translateY(-1px);
        }
        
        .btn:disabled {
            opacity: 0.7;
            cursor: not-allowed;
        }
        
        .btn-download {
            background: #e9ecef;
            color: #495057;
        }
        
        .validation-panel {
            margin: 24px 0;
            border-radius: 12px;
            overflow: hidden;
            box-shadow: 0 2px 8px rgba(80,80,160,0.04);
        }
        
        .validation-header {
            padding: 16px 24px;
            font-weight: 600;
            font-size: 1.1em;
        }
        
        .validation-content {
            padding: 20px 24px;
            background: white;
        }
        
        .error-list {
            margin: 0;
            padding-left: 24px;
        }
        
        .error-list li {
            margin-bottom: 8px;
            padding: 6px 0;
            border-bottom: 1px solid #eee;
        }
        
        .success { background: #d4edda; color: #155724; }
        .error { background: #f8d7da; color: #721c24; }
        .warning { background: #fff3cd; color: #856404; }
        
        .stats {
            padding: 15px 30px;
            background: #e9ecef;
            font-size: 14px;
            color: #495057;
        }
    </style>
</head>
<body>
    <!-- Menu Container -->
    <div class="menu-container">
        <div class="menu-icon" id="menuIcon">☰</div>
        <div class="menu-list" id="menuList">
            <a href="index.html">Leaderboard</a>
            <a href="https://github.com/dynamic-superb/dynamic-superb" target="_blank">GitHub Repository</a>
            <a href="https://arxiv.org/abs/2411.05361" target="_blank">Paper on arXiv</a>
        </div>
    </div>

    <div class="container">
        <div class="header">
            <h1>Dynamic-SUPERB Submission Validator</h1>
        </div>
        
        <div class="controls">
            <div class="upload-section">
                <label for="submissionFile">Upload Model CSV:</label>
                <input type="file" id="submissionFile" accept=".csv">
                <button id="validateBtn" class="btn" onclick="validateSubmission()">Validate</button>
                <button id="downloadBtn" class="btn btn-download" style="display:none;" onclick="downloadErrors()">Download Error Report</button>
            </div>
            
            <div id="validationResult"></div>
        </div>
        
        <div class="stats">
            Dynamic-SUPERB Submission Validator
        </div>
    </div>

    <script>
        // Menu functionality
        const menuIcon = document.getElementById('menuIcon');
        const menuList = document.getElementById('menuList');
        
        menuIcon.addEventListener('click', (e) => {
            e.stopPropagation();
            menuList.classList.toggle('show');
        });
        
        // Close menu if clicked outside
        document.addEventListener('click', (e) => {
            if (!menuIcon.contains(e.target) && !menuList.contains(e.target)) {
                menuList.classList.remove('show');
            }
        });

        let errorReport = [];
        
        // Enhanced CSV parsing
        function parseCSVLine(line) {
            const result = [];
            let current = '';
            let inQuotes = false;
            
            for (let i = 0; i < line.length; i++) {
                const char = line[i];
                
                if (char === '"') {
                    inQuotes = !inQuotes;
                } else if (char === ',' && !inQuotes) {
                    result.push(current.trim());
                    current = '';
                } else {
                    current += char;
                }
            }
            
            result.push(current.trim());
            return result;
        }

        function normalizeTaskName(name) {
            return name.trim().toLowerCase().replace(/[_\s]+/g, ' ');
        }

        class SimplifiedDynamicSUPERBValidator {
            constructor() {
                this.reference = new Map();
                this.existingModelNames = new Set();
                this.loadReference();
            }

            async loadReference() {
                try {
                    const response = await fetch('data.csv');
                    const csvText = await response.text();
                    const lines = csvText.trim().split('\n');
                    const headers = parseCSVLine(lines[0]);
                    
                    // Find HigherBetter and Taxonomy column indices in REFERENCE data only
                    const higherBetterIndex = headers.findIndex(h => h.trim().toLowerCase() === 'higherbetter');
                    const taxonomyIndex = headers.findIndex(h => h.trim().toLowerCase() === 'taxonomy');
                    
                    // Extract existing model names from reference data
                    const modelStartIndex = higherBetterIndex + 1;
                    const modelEndIndex = taxonomyIndex;
                    for (let i = modelStartIndex; i < modelEndIndex; i++) {
                        this.existingModelNames.add(headers[i].trim());
                    }
                    
                    for (let i = 1; i < lines.length; i++) {
                        const row = parseCSVLine(lines[i]);
                        if (row.length < 4) continue;
                        
                        const taskName = normalizeTaskName(row[0]);
                        const metric = row[1];
                        
                        if (metric === 'X') continue;
                        
                        if (!this.reference.has(taskName)) {
                            this.reference.set(taskName, {
                                originalName: row[0],
                                metrics: [],
                                narMetrics: []
                            });
                        }
                        
                        const task = this.reference.get(taskName);
                        if (!task.metrics.includes(metric)) task.metrics.push(metric);
                        
                        // Track NAR metrics specifically
                        if (metric.includes('NAR')) {
                            task.narMetrics.push(metric);
                        }
                    }
                    
                    // Sort metrics with NAR first
                    this.reference.forEach(task => {
                        task.metrics.sort((a, b) => {
                            if (a.includes('NAR')) return -1;
                            if (b.includes('NAR')) return 1;
                            return a.localeCompare(b);
                        });
                    });
                    
                } catch (error) {
                    console.error('Error loading reference:', error);
                }
            }

            async validate(file) {
                const csvText = await this.readFile(file);
                const lines = csvText.trim().split('\n');
                const header = parseCSVLine(lines[0]);
                
                console.log('Submission CSV Headers:', header);
                
                // SIMPLIFIED: Model columns are everything after "Metric" (index 1)
                const modelStartIndex = 2; // After "Task Name" and "Metric"
                const submissionModelNames = header.slice(modelStartIndex);
                
                console.log('Found models in submission:', submissionModelNames);
                console.log('Model count:', submissionModelNames.length);
                
                const result = {
                    isValid: true,
                    errors: [],
                    warnings: [],
                    stats: { total: 0, valid: 0, invalid: 0 },
                    tasks: new Map(),
                    modelNames: submissionModelNames
                };

                // Check for model name overlaps
                const overlappingModels = submissionModelNames.filter(modelName => 
                    this.existingModelNames.has(modelName.trim())
                );
                
                if (overlappingModels.length > 0) {
                    result.isValid = false;
                    result.errors.push({
                        line: 'Header',
                        task: 'Model Names',
                        error: `Model name overlap detected: ${overlappingModels.join(', ')} already exist in data.csv`
                    });
                }

                // Validate each row
                for (let i = 1; i < lines.length; i++) {
                    result.stats.total++;
                    const row = parseCSVLine(lines[i]);
                    const errors = [];
                    
                    // Basic structure check - must have at least Task Name, Metric, and one model column
                    if (row.length < 3) {
                        errors.push('Invalid row format (minimum: Task Name, Metric, and at least one model score)');
                        result.errors.push({
                            line: i+1,
                            task: row[0] || 'Unknown',
                            error: 'Invalid row format (minimum: Task Name, Metric, and at least one model score)'
                        });
                        result.isValid = false;
                        result.stats.invalid++;
                        continue;
                    }
                    
                    const taskName = normalizeTaskName(row[0]);
                    const metric = row[1];
                    
                    // Skip X metrics
                    if (metric === 'X') {
                        result.warnings.push(`Line ${i+1}: Skipped metric "X"`);
                        continue;
                    }
                    
                    // Task existence check
                    if (!this.reference.has(taskName)) {
                        errors.push(`Unknown task: "${row[0]}"`);
                    } else {
                        const refTask = this.reference.get(taskName);
                        
                        // Metric check
                        if (!refTask.metrics.includes(metric)) {
                            errors.push(`Invalid metric: "${metric}" for task "${row[0]}"`);
                        }
                        
                        // Track metrics per task for NAR check
                        if (!result.tasks.has(taskName)) {
                            result.tasks.set(taskName, { metrics: new Map() });
                        }
                        
                        const taskData = result.tasks.get(taskName);
                        if (!taskData.metrics.has(metric)) {
                            taskData.metrics.set(metric, []);
                        }
                        
                        // Track which models have this metric
                        for (let j = 0; j < submissionModelNames.length; j++) {
                            const modelValue = row[modelStartIndex + j];
                            if (modelValue && modelValue !== '-' && modelValue !== '') {
                                taskData.metrics.get(metric).push(submissionModelNames[j]);
                            }
                        }
                    }
                    
                    // Record errors
                    if (errors.length > 0) {
                        result.isValid = false;
                        result.stats.invalid++;
                        errors.forEach(error => {
                            result.errors.push({
                                line: i+1,
                                task: row[0],
                                error: error
                            });
                        });
                    } else {
                        result.stats.valid++;
                    }
                }
                
                // Check for missing NAR metrics for each model
                result.tasks.forEach((taskData, taskName) => {
                    if (!this.reference.has(taskName)) return;
                    
                    const refTask = this.reference.get(taskName);
                    if (refTask.narMetrics.length === 0) return; // No NAR metrics for this task
                    
                    // For each NAR metric in reference
                    refTask.narMetrics.forEach(narMetric => {
                        // Check if this NAR metric is reported
                        const reportedModels = taskData.metrics.has(narMetric) 
                            ? taskData.metrics.get(narMetric) 
                            : [];
                        
                        // Find models missing this NAR metric
                        const missingModels = submissionModelNames.filter(model => 
                            !reportedModels.includes(model)
                        );
                        
                        if (missingModels.length > 0) {
                            result.isValid = false;
                            result.errors.push({
                                line: 'Multiple',
                                task: refTask.originalName,
                                error: `Missing NAR metric "${narMetric}" for models: ${missingModels.join(', ')}`
                            });
                        }
                    });
                });
                
                return result;
            }

            readFile(file) {
                return new Promise((resolve, reject) => {
                    const reader = new FileReader();
                    reader.onload = () => resolve(reader.result);
                    reader.onerror = reject;
                    reader.readAsText(file);
                });
            }
        }

        // UI Handling
        const validator = new SimplifiedDynamicSUPERBValidator();
        let currentErrors = [];

        async function validateSubmission() {
            const fileInput = document.getElementById('submissionFile');
            const resultDiv = document.getElementById('validationResult');
            const downloadBtn = document.getElementById('downloadBtn');
            const validateBtn = document.getElementById('validateBtn');
            
            if (!fileInput.files.length) {
                resultDiv.innerHTML = `<div class="validation-panel error">
                    <div class="validation-header">Error</div>
                    <div class="validation-content">Please select a CSV file</div>
                </div>`;
                return;
            }

            validateBtn.disabled = true;
            validateBtn.textContent = 'Validating...';
            downloadBtn.style.display = 'none';
            currentErrors = [];
            
            try {
                const result = await validator.validate(fileInput.files[0]);
                let html = '';
                
                if (result.isValid) {
                    html = `<div class="validation-panel success">
                        <div class="validation-header">Validation Successful!</div>
                        <div class="validation-content">
                            <p><strong>Total Rows:</strong> ${result.stats.total}</p>
                            <p><strong>Valid Rows:</strong> ${result.stats.valid}</p>
                            <p><strong>Models:</strong> ${result.modelNames.length}</p>
                            <p>βœ… All NAR metrics are properly reported for all models!</p>
                            <p>βœ… No model name conflicts detected!</p>
                            <p>βœ… All tasks and metrics are valid!</p>
                        </div>
                    </div>`;
                } else {
                    currentErrors = result.errors;
                    downloadBtn.style.display = 'inline-block';
                    
                    html = `<div class="validation-panel error">
                        <div class="validation-header">Validation Failed</div>
                        <div class="validation-content">
                            <p><strong>Total Rows:</strong> ${result.stats.total}</p>
                            <p><strong>Valid Rows:</strong> ${result.stats.valid}</p>
                            <p><strong>Errors Found:</strong> ${result.errors.length}</p>
                            <ul class="error-list">${result.errors.map(e => `
                                <li><strong>Line ${e.line}:</strong> ${e.error} (${e.task})</li>
                            `).join('')}</ul>
                        </div>
                    </div>`;
                }
                
                if (result.warnings.length > 0) {
                    html += `<div class="validation-panel warning">
                        <div class="validation-header">Warnings</div>
                        <div class="validation-content">
                            <ul class="error-list">${result.warnings.map(w => `
                                <li>${w}</li>
                            `).join('')}</ul>
                        </div>
                    </div>`;
                }
                
                resultDiv.innerHTML = html;
                
            } catch (error) {
                resultDiv.innerHTML = `<div class="validation-panel error">
                    <div class="validation-header">Error</div>
                    <div class="validation-content">${error.message}</div>
                </div>`;
            }
            
            validateBtn.disabled = false;
            validateBtn.textContent = 'Validate';
        }

        function downloadErrors() {
            if (currentErrors.length === 0) return;
            
            const csvContent = [
                ['Line', 'Task', 'Error'],
                ...currentErrors.map(e => [e.line, `"${e.task}"`, `"${e.error}"`])
            ].map(row => row.join(',')).join('\n');
            
            const blob = new Blob([csvContent], { type: 'text/csv' });
            const url = URL.createObjectURL(blob);
            const a = document.createElement('a');
            a.href = url;
            a.download = 'validation_errors.csv';
            document.body.appendChild(a);
            a.click();
            document.body.removeChild(a);
            URL.revokeObjectURL(url);
        }
    </script>
</body>
</html>