-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
915 lines (825 loc) · 40.6 KB
/
index.html
File metadata and controls
915 lines (825 loc) · 40.6 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SkillForge AI Bootcamp Dashboard</title>
<link rel="icon" type="image/svg+xml" href="favicon.svg">
<link rel="stylesheet" href="styles.css">
<script src="https://cdn.jsdelivr.net/npm/chart.js@4/dist/chart.umd.min.js"></script>
</head>
<body>
<header>
<div class="header-title">
<img src="favicon.png" alt="SkillForge" class="header-logo">
<h1>SkillForge AI Bootcamp</h1>
</div>
<div class="controls">
<span class="server-address" id="server-address"></span>
<span class="refresh-countdown" id="countdown"></span>
<button class="refresh-btn" onclick="refresh()"><span class="refresh-text">Refresh Now</span><span class="refresh-icon">🔄</span></button>
<button class="team-names-btn" onclick="showTeamModal()">Team Names</button>
</div>
</header>
<div class="stale-banner hidden" id="stale-banner">
<span id="stale-banner-text"></span>
</div>
<div class="topboard" id="topboard">
<h2>Hall of Fame</h2>
<div class="topboard-grid" id="topboard-grid"></div>
</div>
<div class="leaderboard" id="leaderboard">
<h2>Team Leaderboard</h2>
<div class="leaderboard-grid" id="leaderboard-grid"></div>
<div id="tests-chart-container" style="display:none; padding: 1rem 0;">
<button onclick="toggleMetricsChart(activeChartMetric)" style="margin-bottom:1rem;font-size:0.85rem;padding:4px 12px;cursor:pointer;background:#1e293b;border:1px solid #475569;color:#e2e8f0;border-radius:4px;">← Back to List</button>
<canvas id="tests-chart" style="max-height: 400px;"></canvas>
</div>
</div>
<div class="view-switcher">
<button id="view-btn-cards" class="view-btn active" onclick="showView('cards')">🗂️ Cards</button>
<button id="view-btn-board" class="view-btn" onclick="showView('board')">📋 Board</button>
</div>
<div class="teams-grid" id="teams-grid">
<div class="loading">Loading...</div>
</div>
<div id="board-section" style="display:none;">
<div class="board-nav">
<div class="board-team-tabs" id="board-team-tabs"></div>
</div>
<div class="board-columns" id="board-columns"></div>
</div>
<div class="token-modal hidden" id="team-modal">
<div class="token-dialog team-dialog">
<h2>Assign Team Names</h2>
<p>Select the actual team name for each color team.</p>
<div class="team-selectors" id="team-selectors"></div>
<div class="buttons">
<button onclick="hideTeamModal()">Cancel</button>
<button class="btn-primary" onclick="saveTeamNames()">Save</button>
</div>
</div>
</div>
<script>
const REPOS = [
{ name: 'Obsidian', repo: 'itenium-be/Bootcamp-AI-Obsidian', color: '#8b5cf6', logo: 'logos/Team-Obsidian.png', frontendPort: 5180 },
{ name: 'RoyalPurple', repo: 'itenium-be/Bootcamp-AI-RoyalPurple', color: '#7851a9', logo: 'logos/Team-RoyalPurple.png', frontendPort: 5181 },
{ name: 'Teal', repo: 'itenium-be/Bootcamp-AI-Teal', color: '#008080', logo: 'logos/Team-Teal.png', frontendPort: 5182 },
{ name: 'Emerald', repo: 'itenium-be/Bootcamp-AI-Emerald', color: '#50c878', logo: 'logos/Team-Emerald.png', frontendPort: 5183 },
{ name: 'Crimson', repo: 'itenium-be/Bootcamp-AI-Crimson', color: '#dc143c', logo: 'logos/Team-Crimson.png', frontendPort: 5184 },
{ name: 'MidnightBlue', repo: 'itenium-be/Bootcamp-AI-MidnightBlue', color: '#6366f1', logo: 'logos/Team-MidnightBlue.png', frontendPort: 5185 },
];
const GITHUB_TO_NAME = {
'CtrlAltSell': 'Willem Meylemans',
'Iggy-LetItSnow': 'Igor Romy',
'TimoVersonnen': 'Timo Versonnen',
'Runekid': 'Onur Bugdayci',
'JochemVH1': 'Jochem Van Hespen',
'borosseel': 'Bo Rosseel',
'joriswijnant-ctrl': 'Joris Wijnant',
'Brauwer': 'Thomas De Brauwer',
'Mikedonna': 'Michael Dumortier',
'TimRanson': 'Tim Ranson',
'TomNok': 'Tom Marroyen',
'Stevenrobijns': 'Steven Robijns',
'bossepierreai': 'Pierre Bossé',
'Ninarchive': 'Nina Van Hoof',
'bertforge': 'Bert Maes',
'TyaraSchetgens': 'Tyara Schetgens',
'GitHired': 'Jelle Muijzelaar',
'Bvervaele': 'Bert Vervaele',
'YannickManfroy': 'Yannick Manfroy',
'BernelliG': 'Bernard Giorgino',
'remcoverbruggen-itenium': 'Remco Verbruggen',
'GClaeskens1978': 'Gert Claeskens',
'heleendemeue': 'Heleen de Meue',
'Jonathanrasquin': 'Jonathan Rasquin',
'dsverdlo': 'David Sverdlov',
'JelleMaes': 'Jelle Maes',
'Plekker': 'Bram De Plekker',
'A-Ryckeboer': 'Alexander Ryckeboer',
'NicolasHub': 'Nicolas Legrand',
'JoachimDhondtItenium': 'Joachim D\'hondt',
'jvanloock': 'Jos Van Loock',
'Tomm-commits': 'Tom Mennes',
'michael-itenium': 'Michael Branders',
'laoujin': 'Wouter Van Schandevijl',
};
const TEAM_MEMBERS = {
'Obsidian': ['Willem Meylemans (BO)', 'Igor Romy (.NET)', 'Timo Versonnen (POA)', 'Onur Bugdayci (Java)', 'Jochem Van Hespen (.NET)'],
'RoyalPurple': ['Bo Rosseel (BO)', 'Joris Wijnant (.NET)', 'Thomas De Brauwer (Java)', 'Michael Dumortier (POA)', 'Tim Ranson (Java)', 'Tom Marroyen (POA)'],
'Teal': ['Steven Robijns (BO)', 'Pierre Bossé (.NET)', 'Nina Van Hoof (Java)', 'Bert Maes (POA)', 'Tyara Schetgens (Java)'],
'Emerald': ['Jelle Muijzelaar (BO)', 'Bert Vervaele (.NET)', 'Yannick Manfroy (Java)', 'Bernard Giorgino (POA)', 'Remco Verbruggen (QA)', 'Gert Claeskens (Java)'],
'Crimson': ['Heleen de Meue (BO)', 'Jonathan Rasquin (.NET)', 'David Sverdlov (Java)', 'Jelle Maes (POA)', 'Bram De Plekker (.NET)'],
'MidnightBlue': ['Alexander Ryckeboer (QA)', 'Nicolas Legrand (.NET)', 'Joachim D\'hondt (Java)', 'Jos Van Loock (POA)', 'Tom Mennes (POA)'],
};
const ACTUAL_TEAMS = [
{ id: 'hallucination-hunters', name: 'The Hallucination Hunters', tagline: 'We chase what shouldn\'t exist.', description: 'The Hallucination Hunters track down every rogue AI hallucination and keep our models from running wild. Precision and patience are our secret weapons.' },
{ id: 'prompt-injectors', name: 'The Prompt Injectors', tagline: 'Prompts in, magic out.', description: 'The Prompt Injectors masterfully craft and inject prompts to coax the best results from our AI. Creativity meets chaos here.' },
{ id: 'token-burners', name: 'The Token Burners', tagline: 'We learn by burning.', description: 'The Token Burners throw caution to the wind and feed our AI models token after token, seeing what survives the fire.' },
{ id: 'ai-slop-sommeliers', name: 'The AI Slop Sommeliers', tagline: 'We taste the chaos.', description: 'The AI Slop Sommeliers sample every output from our models, rating quality, flavor, and absurdity — connoisseurs of AI chaos.' },
{ id: 'yolo-deployers', name: 'The YOLO Deployers', tagline: 'Deploy now, debug later.', description: 'The YOLO Deployers thrive on adrenaline. They deploy to production without hesitation and let the AI do its thing.' },
{ id: 'tab-tab-tab-engineers', name: 'The Tab Tab Tab Engineers', tagline: 'Automation over hesitation.', description: 'The Tab Tab Tab Engineers embody ultimate AI trust — every suggestion gets accepted with a tap of Tab. No thinking, no debating, just flow and speed.' },
{ id: 'vibe-driven-developers', name: 'The Vibe-Driven Developers', tagline: 'Good vibes, great code.', description: 'The Vibe-Driven Developers balance focus and relaxation, producing solid code while keeping the energy high and stress low.' },
{ id: 'prompt-pray-engineers', name: 'The Prompt & Pray Engineers', tagline: 'Prompt. Pray. Repeat.', description: 'The Prompt & Pray Engineers trust the AI — and a little bit of luck — to get the job done, embodying the true spirit of bootcamp chaos.' },
{ id: 'claude-carried-us', name: 'The "Claude Carried Us" Department', tagline: 'We typed. Claude decided.', description: 'Claude Carried Us shows what happens when you let AI take the lead — the team did some typing, but Claude did all the heavy lifting.' },
{ id: 'tests-are-for-cowards', name: 'The "Tests Are For Cowards" Club', tagline: 'Bravery over coverage.', description: 'The Tests Are For Cowards Club embraces risk and shuns tests, proving that confidence sometimes outweighs caution… barely.' },
{ id: 'model-collapse-survivors', name: 'The Model Collapse Survivors', tagline: 'Rising from the ashes of failed models.', description: 'The Model Collapse Survivors thrive in post-disaster recovery, salvaging AI models and learning from every spectacular failure.' },
{ id: 'main-branch-pushers', name: 'The Main Branch Pushers', tagline: 'No staging, no fear.', description: 'The Main Branch Pushers live on the edge, merging code straight into main and proving that speed and confidence are everything in bootcamp chaos.' },
];
let teamMappingCache = null;
async function loadTeamMapping() {
try {
const res = await fetch('/api/team-mapping');
teamMappingCache = await res.json();
} catch {
teamMappingCache = {};
}
}
function getTeamMapping() {
return teamMappingCache || {};
}
async function saveTeamMapping(mapping) {
teamMappingCache = mapping;
await fetch('/api/team-mapping', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(mapping),
});
}
function getActualTeam(colorName) {
const mapping = getTeamMapping();
const actualId = mapping[colorName];
return ACTUAL_TEAMS.find(t => t.id === actualId) || null;
}
function resolveName(handle) {
if (!handle) return null;
// Case-insensitive lookup
const key = Object.keys(GITHUB_TO_NAME).find(k => k.toLowerCase() === handle.toLowerCase());
return key ? GITHUB_TO_NAME[key] : handle;
}
// Map a person's name to their team
function getTeamForPerson(name) {
if (!name) return null;
const nameLower = name.toLowerCase();
for (const [team, members] of Object.entries(TEAM_MEMBERS)) {
for (const member of members) {
// Strip role suffix like "(POA)" from "Tom Mennes (POA)"
const memberName = member.replace(/\s*\([^)]+\)\s*$/, '').toLowerCase();
if (memberName === nameLower) {
return team;
}
}
}
return null;
}
function aggregateUsageByTeam(usage) {
const teamUsage = {};
for (const repo of REPOS) {
teamUsage[repo.name] = { input: 0, output: 0, total: 0, cost: 0, color: repo.color, logo: repo.logo };
}
for (const entry of usage || []) {
const team = getTeamForPerson(entry.name);
if (team && teamUsage[team]) {
teamUsage[team].input += entry.input || 0;
teamUsage[team].output += entry.output || 0;
teamUsage[team].total += (entry.input || 0) + (entry.output || 0);
teamUsage[team].cost += entry.cost || 0;
}
}
return teamUsage;
}
function formatTokens(n) {
if (n >= 1_000_000) return (n / 1_000_000).toFixed(1) + 'M';
if (n >= 1_000) return (n / 1_000).toFixed(1) + 'K';
return n.toString();
}
const REFRESH_INTERVAL = 120000; // 2 minutes
let countdownInterval;
let nextRefresh;
let activeChartMetric = null;
let metricsChartInstance = null;
let currentView = 'cards';
let currentBoardTeam = null;
let latestTeamsData = null;
let avatarsByHandle = {}; // handle (lowercase) → avatar_url
function buildAvatarMap(teamsData) {
for (const team of teamsData) {
for (const commit of (team.allCommits || [])) {
if (commit.authorHandle && commit.avatarUrl) {
avatarsByHandle[commit.authorHandle.toLowerCase()] = commit.avatarUrl;
}
}
for (const commit of (team.allCommitStats || [])) {
if (commit.authorHandle && commit.avatarUrl) {
avatarsByHandle[commit.authorHandle.toLowerCase()] = commit.avatarUrl;
}
}
}
}
function getAvatar(handle) {
if (!handle) return null;
return avatarsByHandle[handle.toLowerCase()] || null;
}
function avatarImg(handle, size = 20) {
const src = getAvatar(handle);
if (!src) return '';
return `<img src="${src}" alt="${handle}" class="contributor-avatar" style="width:${size}px;height:${size}px;border-radius:50%;vertical-align:middle;margin-right:4px;">`;
}
const CHART_METRIC_LABELS = {
testsPassing: 'Tests Passing',
totalCommits: 'Total Commits',
linesAdded: 'Lines Added',
mergedPRs: 'PRs Merged',
tokensBurned: 'Tokens Burned',
};
async function toggleMetricsChart(key) {
const grid = document.getElementById('leaderboard-grid');
const chartContainer = document.getElementById('tests-chart-container');
if (activeChartMetric === key) {
// Same button clicked — close chart
activeChartMetric = null;
grid.style.display = '';
chartContainer.style.display = 'none';
if (metricsChartInstance) { metricsChartInstance.destroy(); metricsChartInstance = null; }
} else {
// Open (or switch) chart
activeChartMetric = key;
grid.style.display = 'none';
chartContainer.style.display = 'block';
await renderMetricsChart();
}
// Refresh button labels
document.querySelectorAll('[data-chart-key]').forEach(btn => {
btn.textContent = btn.dataset.chartKey === activeChartMetric ? '📋 List' : '📈 Chart';
});
}
async function renderMetricsChart() {
if (metricsChartInstance) { metricsChartInstance.destroy(); metricsChartInstance = null; }
const canvas = document.getElementById('tests-chart');
const ctx = canvas.getContext('2d');
let history = [];
try {
const res = await fetch('/api/metrics-history');
history = await res.json();
} catch (e) {
console.error('Failed to fetch metrics history:', e);
}
if (!history || history.length === 0) {
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = '#94a3b8';
ctx.font = '16px sans-serif';
ctx.textAlign = 'center';
canvas.height = 80;
ctx.fillText('No history yet — data is recorded every 10 minutes.', canvas.width / 2, 40);
return;
}
const key = activeChartMetric;
const label = CHART_METRIC_LABELS[key] || key;
const labels = history.map(s => {
const d = new Date(s.timestamp);
return d.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
});
const datasets = REPOS.map(repo => ({
label: repo.name,
data: history.map(s => {
const t = s.teams.find(t => t.name === repo.name);
return t !== undefined ? (t[key] ?? null) : null;
}),
borderColor: repo.color,
backgroundColor: repo.color + '33',
tension: 0.3,
pointRadius: 4,
spanGaps: true,
}));
metricsChartInstance = new Chart(ctx, {
type: 'line',
data: { labels, datasets },
options: {
responsive: true,
plugins: {
legend: { position: 'top', labels: { color: '#e2e8f0' } },
title: { display: true, text: `${label} Over Time`, color: '#e2e8f0', font: { size: 16 } },
},
scales: {
x: { ticks: { color: '#94a3b8' }, grid: { color: '#334155' } },
y: {
ticks: { color: '#94a3b8' },
grid: { color: '#334155' },
beginAtZero: true,
title: { display: true, text: label, color: '#94a3b8' },
},
},
},
});
}
function showTeamModal() {
const container = document.getElementById('team-selectors');
const mapping = getTeamMapping();
container.innerHTML = REPOS.map(repo => `
<div class="team-selector">
<label style="color: ${repo.color}">${repo.name}</label>
<select id="team-select-${repo.name}">
<option value="">-- Select Team --</option>
${ACTUAL_TEAMS.map(t => `
<option value="${t.id}" ${mapping[repo.name] === t.id ? 'selected' : ''}>${t.name}</option>
`).join('')}
</select>
</div>
`).join('');
document.getElementById('team-modal').classList.remove('hidden');
}
function hideTeamModal() {
document.getElementById('team-modal').classList.add('hidden');
}
async function saveTeamNames() {
const mapping = {};
REPOS.forEach(repo => {
const select = document.getElementById(`team-select-${repo.name}`);
if (select.value) {
mapping[repo.name] = select.value;
}
});
await saveTeamMapping(mapping);
hideTeamModal();
refresh();
}
function getTimeAgo(dateString) {
if (!dateString) return 'Never';
const date = new Date(dateString);
const now = new Date();
const diffMs = now - date;
const diffMins = Math.floor(diffMs / 60000);
const diffHours = Math.floor(diffMs / 3600000);
const diffDays = Math.floor(diffMs / 86400000);
if (diffMins < 1) return 'Just now';
if (diffMins < 60) return `${diffMins}m ago`;
if (diffHours < 24) return `${diffHours}h ago`;
return `${diffDays}d ago`;
}
function getTimeAgoClass(dateString) {
if (!dateString) return 'stuck';
const diffMs = new Date() - new Date(dateString);
const diffMins = Math.floor(diffMs / 60000);
if (diffMins < 15) return 'recent';
if (diffMins < 60) return 'stale';
return 'stuck';
}
function getBuildStatusClass(status) {
if (status === 'success') return 'success';
if (status === 'failure') return 'failure';
return 'pending';
}
function getBuildStatusIcon(status) {
if (status === 'success') return '✓';
if (status === 'failure') return '✗';
if (status === 'in_progress' || status === 'queued') return '○';
return '?';
}
function renderTestResult(label, result) {
if (!result) {
return `<div class="test-result"><span class="test-label">${label}:</span> <span class="test-pending">-</span></div>`;
}
const { passed, failed, total } = result;
const allPassed = failed === 0 && total > 0;
const statusClass = allPassed ? 'test-pass' : (failed > 0 ? 'test-fail' : 'test-pending');
return `
<div class="test-result ${statusClass}">
<span class="test-label">${label}:</span>
<span class="test-passed">${passed}</span>/<span class="test-total">${total}</span>
${failed > 0 ? `<span class="test-failed">(${failed} failed)</span>` : ''}
</div>
`;
}
function renderTopboard(teamsData, tokenUsage) {
const validTeams = teamsData.filter(t => !t.error);
// Collect all commits with stats across teams (full history)
const allCommitsWithStats = [];
const contributorStats = {}; // { name: { commits: 0, prs: 0, linesChanged: 0, team: '', logo: '' } }
for (const team of validTeams) {
// Process all commits with stats for hall of fame metrics
for (const commit of (team.allCommitStats || [])) {
const handle = commit.authorHandle || 'Unknown';
const name = resolveName(handle);
const lines = (commit.additions || 0) + (commit.deletions || 0);
allCommitsWithStats.push({
name,
handle,
team: team.name,
teamColor: team.color,
teamLogo: team.logo,
lines,
date: commit.date,
message: commit.message || '',
});
if (!contributorStats[name]) {
contributorStats[name] = { handle, commits: 0, prs: 0, linesChanged: 0, team: team.name, teamColor: team.color, teamLogo: team.logo };
}
contributorStats[name].linesChanged += lines;
}
// Process all commits for count
for (const commit of (team.allCommits || [])) {
const handle = commit.authorHandle || 'Unknown';
const name = resolveName(handle);
if (!contributorStats[name]) {
contributorStats[name] = { handle, commits: 0, prs: 0, linesChanged: 0, team: team.name, teamColor: team.color, teamLogo: team.logo };
}
contributorStats[name].commits++;
}
// Process PRs
for (const pr of (team.mergedPRs || [])) {
const handle = pr.author || 'Unknown';
const name = resolveName(handle);
if (!contributorStats[name]) {
contributorStats[name] = { handle, commits: 0, prs: 0, linesChanged: 0, team: team.name, teamColor: team.color, teamLogo: team.logo };
}
contributorStats[name].prs++;
}
}
// Collect all commits (with just date/author) for First Commit detection
const allCommitDates = [];
for (const team of validTeams) {
for (const commit of (team.allCommits || [])) {
if (commit.date) {
const handle = commit.authorHandle || 'Unknown';
allCommitDates.push({ name: resolveName(handle), handle, date: commit.date, team: team.name, teamColor: team.color, teamLogo: team.logo });
}
}
}
// Find winners
const largestCommit = allCommitsWithStats.sort((a, b) => b.lines - a.lines)[0];
const firstCommit = allCommitDates.sort((a, b) => new Date(a.date) - new Date(b.date))[0];
const contributors = Object.entries(contributorStats).map(([name, stats]) => ({ name, ...stats }));
const mostCommits = contributors.sort((a, b) => b.commits - a.commits)[0];
const mostPRs = contributors.sort((a, b) => b.prs - a.prs)[0];
const mostChurn = contributors.sort((a, b) => b.linesChanged - a.linesChanged)[0];
const activeContributors = contributors.filter(c => c.commits > 0);
const leastChurn = activeContributors.filter(c => c.linesChanged > 0 || c.prs === 0).sort((a, b) => a.linesChanged - b.linesChanged)[0];
// Find top token burner
let topTokenBurner = null;
if (tokenUsage && tokenUsage.length > 0) {
const sorted = [...tokenUsage].sort((a, b) => ((b.input || 0) + (b.output || 0)) - ((a.input || 0) + (a.output || 0)));
const top = sorted[0];
if (top) {
const team = getTeamForPerson(top.name);
const teamRepo = REPOS.find(r => r.name === team);
topTokenBurner = {
name: top.name,
handle: top.name,
team: team || 'Unknown',
teamColor: teamRepo?.color || '#888',
teamLogo: teamRepo?.logo || '',
value: top.cost ? `$${top.cost.toFixed(2)}` : formatTokens((top.input || 0) + (top.output || 0)),
};
}
}
const awards = [
{ title: 'First Commit', icon: '🚀', winner: firstCommit ? { name: firstCommit.name, handle: firstCommit.handle, team: firstCommit.team, teamColor: firstCommit.teamColor, teamLogo: firstCommit.teamLogo, value: new Date(firstCommit.date).toLocaleTimeString('en-GB', { hour: '2-digit', minute: '2-digit' }) } : null },
{ title: 'Most Commits', icon: '⚡', winner: mostCommits ? { name: mostCommits.name, handle: mostCommits.handle, team: mostCommits.team, teamColor: mostCommits.teamColor, teamLogo: mostCommits.teamLogo, value: mostCommits.commits } : null },
{ title: 'Most PRs', icon: '🔀', winner: mostPRs?.prs > 0 ? { name: mostPRs.name, handle: mostPRs.handle, team: mostPRs.team, teamColor: mostPRs.teamColor, teamLogo: mostPRs.teamLogo, value: mostPRs.prs } : null },
{ title: 'Largest Commit', icon: '💪', winner: largestCommit?.lines > 0 ? { name: largestCommit.name, handle: largestCommit.handle, team: largestCommit.team, teamColor: largestCommit.teamColor, teamLogo: largestCommit.teamLogo, value: `${largestCommit.lines.toLocaleString()} lines` } : null },
{ title: 'Most Churn', icon: '🌀', winner: mostChurn?.linesChanged > 0 ? { name: mostChurn.name, handle: mostChurn.handle, team: mostChurn.team, teamColor: mostChurn.teamColor, teamLogo: mostChurn.teamLogo, value: `${mostChurn.linesChanged.toLocaleString()} lines` } : null },
{ title: 'Slacker', icon: '🛋️', hidden: true, winner: leastChurn ? { name: leastChurn.name, handle: leastChurn.handle, team: leastChurn.team, teamColor: leastChurn.teamColor, teamLogo: leastChurn.teamLogo, value: `${leastChurn.linesChanged} lines` } : null },
...(topTokenBurner ? [{ title: 'AI Spender', icon: '💸', winner: topTokenBurner }] : []),
];
const grid = document.getElementById('topboard-grid');
grid.innerHTML = awards.filter(a => !a.hidden).map(award => {
const actualTeam = award.winner ? getActualTeam(award.winner.team) : null;
return `
<div class="topboard-item" ${award.winner?.teamLogo ? `style="background-image: url('${award.winner.teamLogo}')"` : ''}>
<div class="award-icon">${award.icon}</div>
<div class="award-title">${award.title}</div>
${award.winner ? `
<div class="award-winner">${avatarImg(award.winner.handle, 28)}${award.winner.name}</div>
<div class="award-handle">@${award.winner.handle}</div>
<div class="award-team" style="color: ${award.winner.teamColor}">
<span>${actualTeam ? actualTeam.name : award.winner.team}</span>
</div>
<div class="award-value"><span>${award.winner.value}</span></div>
` : `<div class="award-empty">-</div>`}
</div>
`;
}).join('');
}
function renderLeaderboard(teamsData, teamUsage) {
const validTeams = teamsData.filter(t => !t.error);
const categories = [
{
title: 'Tests Passing',
icon: '✅',
chartKey: 'testsPassing',
getData: (t) => {
const be = t.testResults?.backend?.passed || 0;
const feUnit = t.testResults?.frontend?.unit?.passed || 0;
const feE2e = t.testResults?.frontend?.e2e?.passed || 0;
return be + feUnit + feE2e;
},
},
{
title: 'Total Commits',
icon: '⚡',
chartKey: 'totalCommits',
getData: (t) => t.totalCommits || 0,
},
{
title: 'Lines Added',
icon: '📈',
chartKey: 'linesAdded',
getData: (t) => t.totalLinesAdded || 0,
format: v => v.toLocaleString(),
},
{
title: 'PRs Merged',
icon: '🔀',
chartKey: 'mergedPRs',
getData: (t) => t.mergedPRsCount || 0,
},
...(Object.values(teamUsage || {}).some(u => u.cost > 0) ? [{
title: 'AI Cost',
icon: '💸',
chartKey: 'tokensBurned',
getData: (t) => teamUsage?.[t.name]?.cost || 0,
format: v => `$${v.toFixed(2)}`,
}] : []),
];
const grid = document.getElementById('leaderboard-grid');
grid.innerHTML = categories.map((cat) => {
const sorted = [...validTeams].sort((a, b) => cat.getData(b) - cat.getData(a));
const winner = sorted[0];
if (!winner) return '';
const winnerScore = cat.getData(winner);
const bgStyle = winnerScore > 0 ? `style="background-image: url('${winner.logo}')"` : '';
const formatFn = cat.format || (v => v);
const chartBtn = cat.chartKey
? `<button data-chart-key="${cat.chartKey}" onclick="toggleMetricsChart('${cat.chartKey}')" style="margin-left:auto;font-size:0.7rem;padding:2px 8px;cursor:pointer;background:#1e293b;border:1px solid #475569;color:#e2e8f0;border-radius:4px;">${activeChartMetric === cat.chartKey ? '📋 List' : '📈 Chart'}</button>`
: '';
return `
<div class="leaderboard-category" ${bgStyle}>
<h3 style="display:flex;align-items:center;gap:0.5rem;">${cat.icon || ''} ${cat.title}${chartBtn}</h3>
${sorted.map((t, idx) => {
const actualTeam = getActualTeam(t.name);
const score = cat.getData(t);
return `
<div class="leaderboard-item ${idx === 0 ? 'leader' : ''}">
<div class="leaderboard-names">
${actualTeam ? `<span class="leaderboard-actual">${actualTeam.name}</span>` : ''}
<span class="leaderboard-color" style="border-color: ${t.color}; color: ${t.color}; text-align: center">${t.name}</span>
</div>
<span class="score">${formatFn(score)}</span>
</div>
`;
}).join('')}
</div>
`;
}).join('');
}
function renderTeamCard(team) {
if (team.error) {
// Server should never send error data — but if it slips through, show a neutral placeholder
team = {
...team,
commits: [], allCommits: [], allCommitStats: [],
openIssues: [], openIssuesCount: 0, closedIssuesCount: 0, allIssues: [],
openPRs: [], openPRsCount: 0, mergedPRs: [], mergedPRsCount: 0,
lastPush: null, buildStatus: 'unknown', testResults: null,
contributorStats: [], totalCommits: 0,
error: null,
};
}
const buildClass = getBuildStatusClass(team.buildStatus);
const buildIcon = getBuildStatusIcon(team.buildStatus);
const lastPushClass = getTimeAgoClass(team.lastPush);
const actualTeam = getActualTeam(team.name);
return `
<div class="team-card">
<div class="team-header">
<div class="team-name-title">
<img src="${team.logo}" alt="${team.name}" class="team-logo">
<div class="team-names">
${actualTeam ? `<div class="actual-team-name">${actualTeam.name}</div>` : ''}
<a href="https://github.com/${team.repo}" target="_blank" class="color-team-name" style="color: ${team.color}">${team.name}</a>
<a href="http://localhost:${team.frontendPort}" target="_blank" class="frontend-link">:${team.frontendPort}</a>
</div>
</div>
<div class="team-status">
<span class="build-status ${buildClass}">${buildIcon} ${team.buildStatus}</span>
<span class="last-push ${lastPushClass}">${getTimeAgo(team.lastPush)}</span>
</div>
</div>
<div class="team-content">
<div class="section">
<div class="section-title">Recent Commits <span class="commit-count">${(team.commits || []).length}</span></div>
<div class="section-subtitle">All commits <span class="commit-count">${(team.allCommits || []).length}</span></div>
<ul class="commit-list">
${(team.commits || []).map(c => `
<li class="commit-item">
<div class="commit-message">${escapeHtml(c.message || '')}</div>
<div class="commit-meta">
<span class="author">${avatarImg(c.authorHandle, 16)}${c.author}</span>
<span class="time">${getTimeAgo(c.date)}</span>
<span class="commit-stats">
<span class="additions">+${c.additions || 0}</span>
<span class="deletions">-${c.deletions || 0}</span>
</span>
</div>
</li>
`).join('')}
</ul>
</div>
<div class="section">
<div class="section-title">Tests</div>
<div class="test-results">
${renderTestResult('Backend', team.testResults?.backend)}
${renderTestResult('Unit', team.testResults?.frontend?.unit)}
${renderTestResult('E2E', team.testResults?.frontend?.e2e)}
</div>
</div>
<div class="section">
<div class="stats-row">
<div class="stat">
<span class="stat-label">Issues:</span>
<span>${team.openIssuesCount || 0} open, ${team.closedIssuesCount || 0} closed</span>
</div>
<div class="stat">
<span class="stat-label">PRs:</span>
<span>${team.openPRsCount || 0} open, ${team.mergedPRsCount || 0} merged</span>
</div>
</div>
</div>
${(team.openPRs || []).length > 0 ? `
<div class="section">
<div class="section-title">Open PRs</div>
<ul class="pr-list">
${team.openPRs.map(pr => `
<li class="pr-item">
<a href="${pr.url}" target="_blank">#${pr.number}: ${escapeHtml(pr.title)}</a>
</li>
`).join('')}
</ul>
</div>
` : ''}
${(team.openIssues || []).length > 0 ? `
<div class="section">
<div class="section-title">Open Issues</div>
<ul class="issue-list">
${team.openIssues.map(issue => `
<li class="issue-item">
<a href="${issue.url}" target="_blank">#${issue.number}: ${escapeHtml(issue.title)}</a>
</li>
`).join('')}
</ul>
</div>
` : ''}
</div>
<div class="team-footer" style="height: 100%">
${actualTeam ? `
<div class="team-tagline">${actualTeam.tagline}</div>
<div class="team-description">${actualTeam.description}</div>
` : ''}
<div class="team-members">
<span class="members-label">Team:</span>
${(TEAM_MEMBERS[team.name] || []).map(member => {
const cleanName = member.replace(/\s*\([^)]+\)\s*$/, '');
const handle = Object.keys(GITHUB_TO_NAME).find(k => GITHUB_TO_NAME[k].toLowerCase() === cleanName.toLowerCase());
return `<span class="team-member-entry">${avatarImg(handle, 18)}${member}</span>`;
}).join('')}
</div>
</div>
</div>
`;
}
function escapeHtml(text) {
const div = document.createElement('div');
div.textContent = text;
return div.innerHTML;
}
const IN_PROGRESS_LABELS = ['in progress', 'in-progress', 'in_progress', 'wip', 'doing', 'started'];
function showView(view) {
currentView = view;
document.getElementById('teams-grid').style.display = view === 'cards' ? '' : 'none';
document.getElementById('board-section').style.display = view === 'board' ? '' : 'none';
document.getElementById('view-btn-cards').classList.toggle('active', view === 'cards');
document.getElementById('view-btn-board').classList.toggle('active', view === 'board');
if (view === 'board' && latestTeamsData) renderBoard(latestTeamsData);
}
function selectBoardTeam(name) {
currentBoardTeam = name;
if (latestTeamsData) renderBoard(latestTeamsData);
}
function renderBoard(teamsData) {
const validTeams = teamsData.filter(t => !t.error && t.allIssues);
if (!validTeams.length) {
document.getElementById('board-columns').innerHTML = '<div class="loading">No issue data available.</div>';
return;
}
if (!currentBoardTeam || !validTeams.find(t => t.name === currentBoardTeam)) {
currentBoardTeam = validTeams[0].name;
}
// Render team tabs
document.getElementById('board-team-tabs').innerHTML = validTeams.map(t => {
const active = t.name === currentBoardTeam;
const actualTeam = getActualTeam(t.name);
return `<button class="board-team-tab ${active ? 'active' : ''}"
style="border-color:${t.color};${active ? `background:${t.color}22;color:${t.color}` : ''}"
onclick="selectBoardTeam('${t.name}')">
${actualTeam ? actualTeam.name : t.name}
</button>`;
}).join('');
// Render columns for selected team
const team = validTeams.find(t => t.name === currentBoardTeam);
const issues = team.allIssues || [];
const backlog = issues.filter(i => i.state === 'open' && !i.labels.some(l => IN_PROGRESS_LABELS.includes(l.name.toLowerCase())));
const inProgress = issues.filter(i => i.state === 'open' && i.labels.some(l => IN_PROGRESS_LABELS.includes(l.name.toLowerCase())));
const done = issues.filter(i => i.state === 'closed');
const columns = [
{ title: 'Backlog', icon: '📋', issues: backlog, accent: '#58a6ff' },
{ title: 'In Progress', icon: '⚡', issues: inProgress, accent: '#d29922' },
{ title: 'Done', icon: '✅', issues: done.slice(0, 30), accent: '#3fb950' },
];
document.getElementById('board-columns').innerHTML = columns.map(col => `
<div class="board-column">
<div class="board-column-header" style="border-bottom-color:${col.accent}">
<span>${col.icon} ${col.title}</span>
<span class="board-column-count" style="background:${col.accent}22;color:${col.accent}">${col.issues.length}</span>
</div>
<div class="board-cards">
${col.issues.length === 0
? '<div class="board-empty">No issues</div>'
: col.issues.map(issue => `
<a href="${issue.url}" target="_blank" class="board-card">
<div class="board-card-meta">
<span class="board-card-number">#${issue.number}</span>
${issue.assignee ? `<span class="board-assignee">@${resolveName(issue.assignee)}</span>` : ''}
</div>
<div class="board-card-title">${escapeHtml(issue.title)}</div>
${issue.labels.length > 0 ? `
<div class="board-labels">
${issue.labels.map(l => `<span class="board-label" style="background:#${l.color}22;border-color:#${l.color};color:#${l.color}">${escapeHtml(l.name)}</span>`).join('')}
</div>` : ''}
</a>
`).join('')}
</div>
</div>
`).join('');
}
function startCountdown() {
if (countdownInterval) clearInterval(countdownInterval);
nextRefresh = Date.now() + REFRESH_INTERVAL;
countdownInterval = setInterval(() => {
const remaining = Math.max(0, nextRefresh - Date.now());
const secs = Math.ceil(remaining / 1000);
document.getElementById('countdown').textContent = `Refresh in ${secs}s`;
}, 1000);
}
async function refresh() {
const grid = document.getElementById('teams-grid');
grid.innerHTML = '<div class="loading">Loading...</div>';
try {
const response = await fetch('/api/data');
if (!response.ok) throw new Error('API error');
const data = await response.json();
const teamsData = data.teams || [];
const tokenUsage = data.tokenUsage || [];
const teamUsage = aggregateUsageByTeam(tokenUsage);
latestTeamsData = teamsData;
buildAvatarMap(teamsData);
const banner = document.getElementById('stale-banner');
const bannerText = document.getElementById('stale-banner-text');
const fetchedAt = data.lastGoodFetchAt;
const isStale = !fetchedAt || (Date.now() - fetchedAt > 60 * 1000);
if (isStale && fetchedAt) {
bannerText.textContent = `Showing cached data — last live update: ${getTimeAgo(new Date(fetchedAt).toISOString())}`;
banner.classList.remove('hidden');
} else if (isStale && !fetchedAt) {
bannerText.textContent = 'Showing cached data — GitHub API unavailable';
banner.classList.remove('hidden');
} else {
banner.classList.add('hidden');
}
renderTopboard(teamsData, tokenUsage);
renderLeaderboard(teamsData, teamUsage);
// Restore chart state after re-render
if (activeChartMetric) {
document.getElementById('leaderboard-grid').style.display = 'none';
document.getElementById('tests-chart-container').style.display = 'block';
await renderMetricsChart();
}
grid.innerHTML = teamsData.map(renderTeamCard).join('');
if (currentView === 'board') renderBoard(teamsData);
} catch (error) {
console.error('Failed to fetch data:', error);
grid.innerHTML = '<div class="error">Failed to load data. Check server logs.</div>';
}
startCountdown();
}
// Display server address
document.getElementById('server-address').textContent = `${location.hostname}:8080`;
// Initial load
(async () => {
await loadTeamMapping();
refresh();
setInterval(refresh, REFRESH_INTERVAL);
})();
</script>
</body>
</html>