-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathanalytics-content.tsx
More file actions
1485 lines (1410 loc) · 67 KB
/
analytics-content.tsx
File metadata and controls
1485 lines (1410 loc) · 67 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
"use client";
import { useMemo, useState, useEffect } from "react";
import { motion } from "framer-motion";
import {
Star,
GitFork,
Eye,
Download,
TrendingUp,
Calendar,
Award,
ExternalLink,
BarChart3,
ArrowUpDown,
ArrowUp,
ArrowDown,
Package,
Github,
Info,
} from "lucide-react";
import Image from "next/image";
import { getAssetPath } from "@/lib/utils";
import type { User } from '@vector-institute/aieng-auth-core';
import MeaningfulnessChart from '@/components/MeaningfulnessChart';
import CodeConfigChart from '@/components/CodeConfigChart';
import GeographicChart from '@/components/GeographicChart';
// Types
interface RepoSnapshot {
repo_id: string;
name: string;
timestamp: string;
stars: number;
forks: number;
watchers: number;
open_issues: number;
size: number;
views_14d: number | null;
unique_visitors_14d: number | null;
clones_14d: number | null;
unique_cloners_14d: number | null;
language: string | null;
created_at: string | null;
updated_at: string | null;
topics: string[];
}
interface RepoHistory {
name: string;
snapshots: RepoSnapshot[];
}
interface HistoricalData {
repos: Record<string, RepoHistory>;
last_updated: string | null;
}
interface RepoMetrics {
repo_id: string;
name: string;
stars: number;
forks: number;
unique_visitors: number;
unique_cloners: number;
language: string | null;
description?: string;
}
interface RepositoryInfo {
repo_id: string;
description: string;
package_name?: string;
}
interface PyPISnapshot {
package_name: string;
name: string;
repo_id: string;
type: string;
timestamp: string;
downloads_last_day: number | null;
downloads_last_week: number | null;
downloads_last_month: number | null;
total_downloads: number | null;
version: string | null;
release_date: string | null;
}
interface PyPIPackageHistory {
name: string;
repo_id: string;
type: string;
snapshots: PyPISnapshot[];
}
interface PyPIHistoricalData {
packages: Record<string, PyPIPackageHistory>;
last_updated: string | null;
}
interface PyPIMetrics {
package_name: string;
name: string;
repo_id: string;
type: string;
downloads_last_day: number;
downloads_last_week: number;
downloads_last_month: number;
version: string | null;
description?: string;
}
interface GeographicData {
country: string;
count: number;
}
interface ForkSummary {
total_forks: number;
active_forks: number;
meaningful_forks: number;
not_meaningful_forks: number;
meaningful_rate: number;
total_files_changed: number;
code_files: number;
config_files: number;
}
interface ForkAnalysis {
summary: ForkSummary;
geographic_distribution: GeographicData[];
last_updated: string;
}
type SortColumn = "name" | "language" | "stars" | "forks" | "unique_visitors" | "unique_cloners";
type PyPISortColumn = "name" | "downloads_last_day" | "downloads_last_week" | "downloads_last_month" | "version";
type SortDirection = "asc" | "desc";
type ActiveTab = "github" | "pypi";
type PyPIFilter = "all" | "tool" | "bootcamp" | "applied-research";
interface AnalyticsPageProps {
user: User | null;
}
export default function AnalyticsPage({ user }: AnalyticsPageProps) {
// Load data dynamically to ensure fresh data during development
const [historicalData, setHistoricalData] = useState<HistoricalData | null>(null);
const [pypiData, setPypiData] = useState<PyPIHistoricalData | null>(null);
const [forkData, setForkData] = useState<ForkAnalysis | null>(null);
const [isLoading, setIsLoading] = useState(true);
const [repoDescriptions, setRepoDescriptions] = useState<Record<string, string>>({});
const [sortColumn, setSortColumn] = useState<SortColumn>("unique_cloners");
const [pypiSortColumn, setPypiSortColumn] = useState<PyPISortColumn>("downloads_last_month");
const [sortDirection, setSortDirection] = useState<SortDirection>("desc");
const [pypiSortDirection, setPypiSortDirection] = useState<SortDirection>("desc");
const [activeTab, setActiveTab] = useState<ActiveTab>("github");
const [pypiFilter, setPypiFilter] = useState<PyPIFilter>("all");
const handleLogout = async () => {
try {
await fetch('/analytics/api/auth/logout', { method: 'POST' });
window.location.href = '/analytics/login';
} catch (error) {
console.error('Logout failed:', error);
}
};
useEffect(() => {
const loadData = async () => {
try {
// With basePath: '/analytics' in next.config.ts, use empty string for public assets
// Next.js automatically serves public files at /analytics/*
const basePath = "/analytics";
// Load historical metrics data
const metricsResponse = await fetch(
`${basePath}/data/github_metrics_history.json`
);
if (!metricsResponse.ok) throw new Error("Failed to fetch metrics data");
const metricsData = await metricsResponse.json();
setHistoricalData(metricsData);
// Load PyPI metrics data
try {
const pypiResponse = await fetch(
`${basePath}/data/pypi_metrics_history.json`
);
if (pypiResponse.ok) {
const pypiMetricsData = await pypiResponse.json();
setPypiData(pypiMetricsData);
}
} catch (error) {
console.warn("No PyPI metrics data found:", error);
}
// Load repository descriptions
try {
const reposResponse = await fetch(`${basePath}/data/repositories.json`);
if (reposResponse.ok) {
const reposData = await reposResponse.json();
const descriptions: Record<string, string> = {};
reposData.repositories?.forEach((repo: RepositoryInfo) => {
descriptions[repo.repo_id] = repo.description;
});
setRepoDescriptions(descriptions);
}
} catch (error) {
console.warn("No repository descriptions found:", error);
}
// Load fork analysis data
try {
const forkResponse = await fetch(`${basePath}/data/fork_metrics.json`);
if (forkResponse.ok) {
const forkMetricsData = await forkResponse.json();
setForkData(forkMetricsData);
}
} catch (error) {
console.warn("No fork metrics data found:", error);
}
} catch (error) {
console.warn("No historical metrics data found:", error);
setHistoricalData(null);
} finally {
setIsLoading(false);
}
};
loadData();
}, []);
// Calculate all repository metrics
const allRepoMetrics = useMemo(() => {
if (!historicalData?.repos) return [];
return Object.entries(historicalData.repos)
.map(([repo_id, repo]) => {
if (repo.snapshots.length === 0) return null;
const latest = repo.snapshots[repo.snapshots.length - 1];
return {
repo_id,
name: repo.name,
stars: latest.stars || 0,
forks: latest.forks || 0,
unique_visitors: latest.unique_visitors_14d || 0,
unique_cloners: latest.unique_cloners_14d || 0,
language: latest.language,
description: repoDescriptions[repo_id],
} as RepoMetrics;
})
.filter((r): r is RepoMetrics => r !== null);
}, [historicalData, repoDescriptions]);
// Calculate aggregate metrics
const aggregateMetrics = useMemo(() => {
const totalStars = allRepoMetrics.reduce((sum, r) => sum + r.stars, 0);
const totalForks = allRepoMetrics.reduce((sum, r) => sum + r.forks, 0);
const totalVisitors = allRepoMetrics.reduce(
(sum, r) => sum + r.unique_visitors,
0
);
const totalCloners = allRepoMetrics.reduce(
(sum, r) => sum + r.unique_cloners,
0
);
return {
totalStars,
totalForks,
totalVisitors,
totalCloners,
totalRepos: allRepoMetrics.length,
avgStarsPerRepo:
allRepoMetrics.length > 0
? Math.round(totalStars / allRepoMetrics.length)
: 0,
};
}, [allRepoMetrics]);
// Get top performers
const topPerformers = useMemo(() => {
return {
byStars: [...allRepoMetrics].sort((a, b) => b.stars - a.stars).slice(0, 5),
byVisitors: [...allRepoMetrics]
.sort((a, b) => b.unique_visitors - a.unique_visitors)
.slice(0, 5),
byCloners: [...allRepoMetrics]
.sort((a, b) => b.unique_cloners - a.unique_cloners)
.slice(0, 5),
};
}, [allRepoMetrics]);
// Sort repository metrics
const sortedRepoMetrics = useMemo(() => {
const sorted = [...allRepoMetrics].sort((a, b) => {
let aValue: string | number | null = a[sortColumn];
let bValue: string | number | null = b[sortColumn];
// Handle null/undefined values
if (aValue === null || aValue === undefined) aValue = "";
if (bValue === null || bValue === undefined) bValue = "";
// For strings, use locale compare
if (typeof aValue === "string" && typeof bValue === "string") {
return sortDirection === "asc"
? aValue.localeCompare(bValue)
: bValue.localeCompare(aValue);
}
// For numbers
return sortDirection === "asc"
? (aValue as number) - (bValue as number)
: (bValue as number) - (aValue as number);
});
return sorted;
}, [allRepoMetrics, sortColumn, sortDirection]);
// Handle column header click
const handleSort = (column: SortColumn) => {
if (sortColumn === column) {
setSortDirection(sortDirection === "asc" ? "desc" : "asc");
} else {
setSortColumn(column);
setSortDirection("desc");
}
};
// Get sort icon for a column
const getSortIcon = (column: SortColumn) => {
if (sortColumn !== column) {
return <ArrowUpDown className="w-3 h-3 opacity-50" />;
}
return sortDirection === "asc" ? (
<ArrowUp className="w-3 h-3" />
) : (
<ArrowDown className="w-3 h-3" />
);
};
// PyPI Metrics Calculations
const allPypiMetrics = useMemo(() => {
if (!pypiData?.packages) return [];
return Object.entries(pypiData.packages)
.map(([package_name, pkg]) => {
if (pkg.snapshots.length === 0) return null;
const latest = pkg.snapshots[pkg.snapshots.length - 1];
return {
package_name,
name: pkg.name,
repo_id: pkg.repo_id,
type: pkg.type || "tool", // Default to "tool" for backward compatibility
downloads_last_day: latest.downloads_last_day || 0,
downloads_last_week: latest.downloads_last_week || 0,
downloads_last_month: latest.downloads_last_month || 0,
version: latest.version,
description: repoDescriptions[pkg.repo_id],
} as PyPIMetrics;
})
.filter((p): p is PyPIMetrics => p !== null);
}, [pypiData, repoDescriptions]);
// Filter PyPI metrics based on selected filter
const filteredPypiMetrics = useMemo(() => {
if (pypiFilter === "all") return allPypiMetrics;
return allPypiMetrics.filter((pkg) => pkg.type === pypiFilter);
}, [allPypiMetrics, pypiFilter]);
// Calculate aggregate PyPI metrics (using filtered data)
const aggregatePypiMetrics = useMemo(() => {
const totalDownloadsDay = filteredPypiMetrics.reduce(
(sum, p) => sum + p.downloads_last_day,
0
);
const totalDownloadsWeek = filteredPypiMetrics.reduce(
(sum, p) => sum + p.downloads_last_week,
0
);
const totalDownloadsMonth = filteredPypiMetrics.reduce(
(sum, p) => sum + p.downloads_last_month,
0
);
return {
totalDownloadsDay,
totalDownloadsWeek,
totalDownloadsMonth,
totalPackages: filteredPypiMetrics.length,
avgDownloadsPerPackage:
filteredPypiMetrics.length > 0
? Math.round(totalDownloadsMonth / filteredPypiMetrics.length)
: 0,
};
}, [filteredPypiMetrics]);
// Get top PyPI performers (using filtered data)
const topPypiPerformers = useMemo(() => {
return {
byDay: [...filteredPypiMetrics]
.sort((a, b) => b.downloads_last_day - a.downloads_last_day)
.slice(0, 5),
byWeek: [...filteredPypiMetrics]
.sort((a, b) => b.downloads_last_week - a.downloads_last_week)
.slice(0, 5),
byMonth: [...filteredPypiMetrics]
.sort((a, b) => b.downloads_last_month - a.downloads_last_month)
.slice(0, 5),
};
}, [filteredPypiMetrics]);
// Sort PyPI metrics (using filtered data)
const sortedPypiMetrics = useMemo(() => {
const sorted = [...filteredPypiMetrics].sort((a, b) => {
let aValue: string | number | null = a[pypiSortColumn];
let bValue: string | number | null = b[pypiSortColumn];
// Handle null/undefined values
if (aValue === null || aValue === undefined) aValue = "";
if (bValue === null || bValue === undefined) bValue = "";
// For strings, use locale compare
if (typeof aValue === "string" && typeof bValue === "string") {
return pypiSortDirection === "asc"
? aValue.localeCompare(bValue)
: bValue.localeCompare(aValue);
}
// For numbers
return pypiSortDirection === "asc"
? (aValue as number) - (bValue as number)
: (bValue as number) - (aValue as number);
});
return sorted;
}, [filteredPypiMetrics, pypiSortColumn, pypiSortDirection]);
// Handle PyPI column header click
const handlePypiSort = (column: PyPISortColumn) => {
if (pypiSortColumn === column) {
setPypiSortDirection(pypiSortDirection === "asc" ? "desc" : "asc");
} else {
setPypiSortColumn(column);
setPypiSortDirection("desc");
}
};
// Get PyPI sort icon
const getPypiSortIcon = (column: PyPISortColumn) => {
if (pypiSortColumn !== column) {
return <ArrowUpDown className="w-3 h-3 opacity-50" />;
}
return pypiSortDirection === "asc" ? (
<ArrowUp className="w-3 h-3" />
) : (
<ArrowDown className="w-3 h-3" />
);
};
return (
<div className="min-h-screen bg-gradient-to-br from-gray-50 via-white to-gray-100 dark:from-gray-900 dark:via-gray-900 dark:to-gray-800">
{/* Header */}
<div className="bg-gradient-to-r from-vector-magenta to-vector-cobalt text-white">
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-12">
<motion.div
initial={{ opacity: 0, y: 20 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.6 }}
className="flex items-center justify-between"
>
<div className="flex items-center gap-4">
<div className="bg-white/95 rounded-md px-2 py-1.5 shadow-sm flex-shrink-0">
<Image
src={getAssetPath("vector-logo.webp")}
alt="Vector Institute"
width={70}
height={15}
priority
/>
</div>
<div>
<h1 className="text-4xl md:text-5xl font-bold mb-2">
Repository Analytics
</h1>
<p className="text-white/90 text-lg">
Engagement & Community Impact Metrics
</p>
</div>
</div>
<div className="flex items-center gap-4">
{historicalData?.last_updated && (
<div className="hidden lg:flex items-center gap-2 text-white/90">
<Calendar className="w-5 h-5" />
<div className="text-right">
<div className="text-xs uppercase tracking-wide opacity-80">
Last Updated
</div>
<div className="text-sm font-medium">
{new Date(historicalData.last_updated)
.toISOString()
.split("T")[0]}
</div>
</div>
</div>
)}
{user && (
<div className="text-right">
<p className="text-xs text-white/70 uppercase tracking-wide">Signed in as</p>
<p className="text-sm font-semibold bg-gradient-to-r from-vector-magenta to-vector-violet bg-clip-text text-transparent">{user.email}</p>
</div>
)}
<button
onClick={handleLogout}
className="px-4 py-2 text-sm font-semibold text-white bg-gradient-to-r from-slate-600 to-slate-700 hover:from-vector-magenta hover:to-vector-violet rounded-lg shadow-sm hover:shadow-md transition-all duration-200"
>
Logout
</button>
</div>
</motion.div>
</div>
</div>
{/* Main Content */}
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-12">
{isLoading ? (
<div className="text-center py-20">
<div className="inline-flex items-center justify-center w-16 h-16 rounded-full bg-gray-100 dark:bg-gray-800 mb-4 animate-pulse">
<TrendingUp className="w-8 h-8 text-gray-400" />
</div>
<h3 className="text-xl font-semibold text-gray-900 dark:text-white mb-2">
Loading Analytics...
</h3>
<p className="text-gray-600 dark:text-gray-400 max-w-md mx-auto">
Fetching repository metrics data
</p>
</div>
) : !historicalData?.repos || allRepoMetrics.length === 0 ? (
<div className="text-center py-20">
<div className="inline-flex items-center justify-center w-16 h-16 rounded-full bg-gray-100 dark:bg-gray-800 mb-4">
<TrendingUp className="w-8 h-8 text-gray-400" />
</div>
<h3 className="text-xl font-semibold text-gray-900 dark:text-white mb-2">
No Analytics Data Available
</h3>
<p className="text-gray-600 dark:text-gray-400 max-w-md mx-auto">
Historical metrics data will be available after the first weekly
collection run.
</p>
</div>
) : (
<>
{/* Tabs */}
<div className="mb-8">
<div className="border-b border-gray-200 dark:border-gray-700">
<nav className="-mb-px flex space-x-8" aria-label="Tabs">
<button
onClick={() => setActiveTab("github")}
className={`
${
activeTab === "github"
? "border-vector-magenta text-vector-magenta"
: "border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300 dark:text-gray-400 dark:hover:text-gray-300"
}
group inline-flex items-center py-4 px-1 border-b-2 font-medium text-sm transition-colors
`}
>
<Github
className={`
${
activeTab === "github"
? "text-vector-magenta"
: "text-gray-400 group-hover:text-gray-500 dark:text-gray-500 dark:group-hover:text-gray-400"
}
-ml-0.5 mr-2 h-5 w-5
`}
/>
<span>GitHub Metrics</span>
</button>
<button
onClick={() => setActiveTab("pypi")}
className={`
${
activeTab === "pypi"
? "border-vector-magenta text-vector-magenta"
: "border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300 dark:text-gray-400 dark:hover:text-gray-300"
}
group inline-flex items-center py-4 px-1 border-b-2 font-medium text-sm transition-colors
`}
>
<Package
className={`
${
activeTab === "pypi"
? "text-vector-magenta"
: "text-gray-400 group-hover:text-gray-500 dark:text-gray-500 dark:group-hover:text-gray-400"
}
-ml-0.5 mr-2 h-5 w-5
`}
/>
<span>PyPI Metrics</span>
{allPypiMetrics.length > 0 && (
<span className="ml-2 py-0.5 px-2 rounded-full text-xs font-medium bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-400">
{allPypiMetrics.length}
</span>
)}
</button>
</nav>
</div>
</div>
{/* GitHub Tab Content */}
{activeTab === "github" && (
<>
{/* Key Metrics */}
<section className="mb-12">
<h2 className="text-2xl font-bold text-gray-900 dark:text-white mb-6 flex items-center gap-2">
<BarChart3 className="w-6 h-6 text-vector-magenta" />
Key Metrics
</h2>
<div className="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-4">
<MetricCard
icon={<Star className="w-5 h-5 text-vector-magenta" />}
label="Total Stars"
value={aggregateMetrics.totalStars.toLocaleString()}
/>
<MetricCard
icon={<GitFork className="w-5 h-5 text-vector-magenta" />}
label="Total Forks"
value={aggregateMetrics.totalForks.toLocaleString()}
/>
<MetricCard
icon={<Eye className="w-5 h-5 text-vector-magenta" />}
label="Unique Visitors"
value={aggregateMetrics.totalVisitors.toLocaleString()}
sublabel="14-day period"
/>
<MetricCard
icon={<Download className="w-5 h-5 text-vector-magenta" />}
label="Unique Cloners"
value={aggregateMetrics.totalCloners.toLocaleString()}
sublabel="14-day period"
/>
<MetricCard
icon={<Award className="w-5 h-5 text-vector-magenta" />}
label="Tracked Repos"
value={aggregateMetrics.totalRepos.toLocaleString()}
/>
</div>
</section>
{/* Top Performers */}
<section className="mb-12">
<h2 className="text-2xl font-bold text-gray-900 dark:text-white mb-6 flex items-center gap-2">
<Award className="w-6 h-6 text-vector-magenta" />
Top Performers
</h2>
<div className="grid grid-cols-1 lg:grid-cols-3 gap-6">
{/* Most Cloned */}
<TopPerformerCard
title="Most Cloned (14d)"
icon={<Download className="w-5 h-5 text-vector-magenta" />}
repos={topPerformers.byCloners}
valueKey="unique_cloners"
valueLabel="cloners"
/>
{/* Most Visited */}
<TopPerformerCard
title="Most Visited (14d)"
icon={<Eye className="w-5 h-5 text-vector-magenta" />}
repos={topPerformers.byVisitors}
valueKey="unique_visitors"
valueLabel="visitors"
/>
{/* Most Starred */}
<TopPerformerCard
title="Most Starred"
icon={<Star className="w-5 h-5 text-vector-magenta" />}
repos={topPerformers.byStars}
valueKey="stars"
valueLabel="stars"
/>
</div>
</section>
{/* Active Fork Analysis */}
<section className="mb-12">
<h2 className="text-2xl font-bold text-gray-900 dark:text-white mb-6 flex items-center gap-2">
<GitFork className="w-6 h-6 text-vector-magenta" />
Active Fork Analysis
</h2>
<div className="grid grid-cols-1 lg:grid-cols-3 gap-6">
{/* Column 1 - Meaningfulness Distribution */}
<div className="bg-white dark:bg-gray-800 rounded-xl border border-gray-200 dark:border-gray-700 p-6 shadow-sm">
<h3 className="text-lg font-semibold text-gray-900 dark:text-white mb-4">
Meaningfulness Distribution
</h3>
<div className="mt-4">
<MeaningfulnessChart
meaningful={forkData?.summary.meaningful_forks || 16}
notMeaningful={forkData?.summary.not_meaningful_forks || 22}
/>
</div>
<div className="mt-6 pt-4 border-t border-gray-200 dark:border-gray-700">
<div className="grid grid-cols-2 gap-4 text-center">
<div>
<div className="text-2xl font-bold text-green-600 dark:text-green-400">
{forkData?.summary.meaningful_forks || 16}
</div>
<div className="text-xs text-gray-600 dark:text-gray-400 mt-1">Meaningful</div>
<div className="text-xs text-gray-500 dark:text-gray-500">
({forkData?.summary.meaningful_rate || 42.1}%)
</div>
</div>
<div>
<div className="text-2xl font-bold text-red-600 dark:text-red-400">
{forkData?.summary.not_meaningful_forks || 22}
</div>
<div className="text-xs text-gray-600 dark:text-gray-400 mt-1">Not Meaningful</div>
<div className="text-xs text-gray-500 dark:text-gray-500">
({forkData ? (100 - forkData.summary.meaningful_rate).toFixed(1) : 57.9}%)
</div>
</div>
</div>
<div className="mt-4 text-center">
<div className="text-sm font-medium text-gray-700 dark:text-gray-300">
Active Forks Analyzed: <span className="font-bold text-gray-900 dark:text-white">
{forkData?.summary.active_forks || 38}
</span>
</div>
</div>
</div>
</div>
{/* Column 2 - Code vs Configuration & Geographic Distribution */}
<div className="space-y-6">
{/* Code vs Configuration */}
<div className="bg-white dark:bg-gray-800 rounded-xl border border-gray-200 dark:border-gray-700 p-6 shadow-sm">
<h3 className="text-lg font-semibold text-gray-900 dark:text-white mb-4">
Code vs Configuration
</h3>
<div className="mt-4">
<CodeConfigChart
codeFiles={forkData?.summary.code_files || 182}
configFiles={forkData?.summary.config_files || 70}
/>
</div>
<div className="mt-6 pt-4 border-t border-gray-200 dark:border-gray-700">
<div className="grid grid-cols-2 gap-4 text-center">
<div>
<div className="text-2xl font-bold text-indigo-600 dark:text-indigo-400">
{forkData?.summary.code_files || 182}
</div>
<div className="text-xs text-gray-600 dark:text-gray-400 mt-1">Code Files</div>
<div className="text-xs text-gray-500 dark:text-gray-500">
({forkData ? ((forkData.summary.code_files / (forkData.summary.code_files + forkData.summary.config_files)) * 100).toFixed(1) : 72.2}%)
</div>
</div>
<div>
<div className="text-2xl font-bold text-amber-600 dark:text-amber-400">
{forkData?.summary.config_files || 70}
</div>
<div className="text-xs text-gray-600 dark:text-gray-400 mt-1">Config Files</div>
<div className="text-xs text-gray-500 dark:text-gray-500">
({forkData ? ((forkData.summary.config_files / (forkData.summary.code_files + forkData.summary.config_files)) * 100).toFixed(1) : 27.8}%)
</div>
</div>
</div>
<div className="mt-4 text-center">
<div className="text-sm font-medium text-gray-700 dark:text-gray-300">
Total Files Changed: <span className="font-bold text-gray-900 dark:text-white">
{forkData ? (forkData.summary.code_files + forkData.summary.config_files) : 252}
</span>
</div>
</div>
</div>
</div>
{/* Geographic Distribution */}
<div className="bg-white dark:bg-gray-800 rounded-xl border border-gray-200 dark:border-gray-700 p-6 shadow-sm">
<h3 className="text-lg font-semibold text-gray-900 dark:text-white mb-4">
Geographic Distribution
</h3>
<div className="mt-4">
{forkData?.geographic_distribution && forkData.geographic_distribution.length > 0 ? (
<GeographicChart data={forkData.geographic_distribution} />
) : (
<div className="text-center py-8 text-gray-500 dark:text-gray-400">
No geographic data available
</div>
)}
</div>
<div className="mt-6 pt-4 border-t border-gray-200 dark:border-gray-700">
<div className="text-center">
<div className="text-sm font-medium text-gray-700 dark:text-gray-300">
Countries Represented: <span className="font-bold text-gray-900 dark:text-white">
{forkData?.geographic_distribution.length || 7}
</span>
</div>
</div>
</div>
</div>
</div>
{/* Column 3 - Key Statistics */}
<div className="bg-white dark:bg-gray-800 rounded-xl border border-gray-200 dark:border-gray-700 p-6 shadow-sm">
<h3 className="text-lg font-semibold text-gray-900 dark:text-white mb-4">
Key Statistics
</h3>
<div className="grid grid-cols-2 gap-4">
{/* Active Forks */}
<div className="bg-gradient-to-br from-gray-50 to-gray-100 dark:from-gray-900 dark:to-gray-800 rounded-lg p-4 text-center">
<div className="text-2xl font-bold text-indigo-600 dark:text-indigo-400">
{forkData?.summary.active_forks || 38}
</div>
<div className="text-xs text-gray-600 dark:text-gray-400 mt-1 uppercase tracking-wide">Active Forks</div>
</div>
{/* Meaningful */}
<div className="bg-gradient-to-br from-green-50 to-green-100 dark:from-green-900/20 dark:to-green-800/20 rounded-lg p-4 text-center">
<div className="text-2xl font-bold text-green-600 dark:text-green-400">
{forkData?.summary.meaningful_forks || 16}
</div>
<div className="text-xs text-gray-600 dark:text-gray-400 mt-1 uppercase tracking-wide">Meaningful</div>
</div>
{/* Not Meaningful */}
<div className="bg-gradient-to-br from-red-50 to-red-100 dark:from-red-900/20 dark:to-red-800/20 rounded-lg p-4 text-center">
<div className="text-2xl font-bold text-red-600 dark:text-red-400">
{forkData?.summary.not_meaningful_forks || 22}
</div>
<div className="text-xs text-gray-600 dark:text-gray-400 mt-1 uppercase tracking-wide">Not Meaningful</div>
</div>
{/* Meaningful Rate */}
<div className="bg-gradient-to-br from-gray-50 to-gray-100 dark:from-gray-900 dark:to-gray-800 rounded-lg p-4 text-center">
<div className="text-2xl font-bold text-indigo-600 dark:text-indigo-400">
{forkData?.summary.meaningful_rate || 42.1}%
</div>
<div className="text-xs text-gray-600 dark:text-gray-400 mt-1 uppercase tracking-wide">Meaningful Rate</div>
</div>
{/* New Functions */}
<div className="bg-gradient-to-br from-gray-50 to-gray-100 dark:from-gray-900 dark:to-gray-800 rounded-lg p-4 text-center">
<div className="text-2xl font-bold text-indigo-600 dark:text-indigo-400">0</div>
<div className="text-xs text-gray-600 dark:text-gray-400 mt-1 uppercase tracking-wide">New Functions</div>
</div>
{/* New Classes */}
<div className="bg-gradient-to-br from-gray-50 to-gray-100 dark:from-gray-900 dark:to-gray-800 rounded-lg p-4 text-center">
<div className="text-2xl font-bold text-indigo-600 dark:text-indigo-400">0</div>
<div className="text-xs text-gray-600 dark:text-gray-400 mt-1 uppercase tracking-wide">New Classes</div>
</div>
{/* Files Changed */}
<div className="bg-gradient-to-br from-gray-50 to-gray-100 dark:from-gray-900 dark:to-gray-800 rounded-lg p-4 text-center">
<div className="text-2xl font-bold text-indigo-600 dark:text-indigo-400">
{forkData?.summary.total_files_changed || 1267}
</div>
<div className="text-xs text-gray-600 dark:text-gray-400 mt-1 uppercase tracking-wide">Files Changed</div>
</div>
{/* Code Files */}
<div className="bg-gradient-to-br from-gray-50 to-gray-100 dark:from-gray-900 dark:to-gray-800 rounded-lg p-4 text-center">
<div className="text-2xl font-bold text-indigo-600 dark:text-indigo-400">
{forkData?.summary.code_files || 182}
</div>
<div className="text-xs text-gray-600 dark:text-gray-400 mt-1 uppercase tracking-wide">Code Files</div>
</div>
</div>
</div>
</div>
</section>
{/* All Repositories Table */}
<section>
<h2 className="text-2xl font-bold text-gray-900 dark:text-white mb-6">
All Repositories
</h2>
<div className="bg-white dark:bg-gray-800 rounded-xl border border-gray-200 dark:border-gray-700 overflow-hidden shadow-sm">
<div className="overflow-x-auto">
<table className="w-full">
<thead className="bg-gray-50 dark:bg-gray-900 border-b border-gray-200 dark:border-gray-700">
<tr>
<th
className="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors"
onClick={() => handleSort("name")}
>
<div className="flex items-center gap-2">
Repository
{getSortIcon("name")}
</div>
</th>
<th
className="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors"
onClick={() => handleSort("language")}
>
<div className="flex items-center gap-2">
Language
{getSortIcon("language")}
</div>
</th>
<th
className="px-6 py-3 text-right text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors"
onClick={() => handleSort("stars")}
>
<div className="flex items-center justify-end gap-1">
<Star className="w-3 h-3" />
Stars
{getSortIcon("stars")}
</div>
</th>
<th
className="px-6 py-3 text-right text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors"
onClick={() => handleSort("forks")}
>
<div className="flex items-center justify-end gap-1">
<GitFork className="w-3 h-3" />
Forks
{getSortIcon("forks")}
</div>
</th>
<th
className="px-6 py-3 text-right text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors"
onClick={() => handleSort("unique_visitors")}
>
<div className="flex items-center justify-end gap-1">
<Eye className="w-3 h-3" />
Visitors (14d)
{getSortIcon("unique_visitors")}
</div>
</th>
<th
className="px-6 py-3 text-right text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors"
onClick={() => handleSort("unique_cloners")}
>
<div className="flex items-center justify-end gap-1">
<Download className="w-3 h-3" />
Cloners (14d)
{getSortIcon("unique_cloners")}
</div>
</th>
</tr>
</thead>
<tbody className="divide-y divide-gray-200 dark:divide-gray-700">
{sortedRepoMetrics.map((repo, index) => {
// Show tooltip below for first 3 rows, above for the rest
const showTooltipBelow = index < 3;
return (
<motion.tr
key={repo.repo_id}
initial={{ opacity: 0, y: 10 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.3, delay: index * 0.02 }}
className="hover:bg-gray-50 dark:hover:bg-gray-750 transition-colors group"
>
<td
className="px-6 py-4 whitespace-nowrap relative"
>
<a
href={`https://github.com/${repo.repo_id}`}
target="_blank"
rel="noopener noreferrer"
className="flex items-center gap-2 text-sm font-medium text-vector-magenta hover:text-vector-cobalt dark:text-vector-magenta dark:hover:text-vector-cobalt"
>
{repo.name}
<ExternalLink className="w-3 h-3" />
</a>
{repo.description && (
<div className={`hidden group-hover:block absolute left-0 ${showTooltipBelow ? 'top-full mt-2' : 'bottom-full mb-2'} z-50 bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 text-sm rounded-lg py-3 px-4 w-96 max-w-[calc(100vw-2rem)] shadow-xl border-2 border-gray-200 dark:border-gray-600 leading-relaxed whitespace-normal break-words`}>
{repo.description}
<div className={`absolute ${showTooltipBelow ? '-top-2 left-8 border-l-2 border-t-2' : '-bottom-2 left-8 border-r-2 border-b-2'} w-4 h-4 bg-white dark:bg-gray-800 border-gray-200 dark:border-gray-600 transform rotate-45`}></div>
</div>
)}
</td>
<td className="px-6 py-4 whitespace-nowrap">
{repo.language ? (
<span className="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-gray-100 dark:bg-gray-700 text-gray-800 dark:text-gray-200">
{repo.language}
</span>
) : (
<span className="text-xs text-gray-400">—</span>
)}
</td>
<td className="px-6 py-4 whitespace-nowrap text-right text-sm font-medium text-gray-900 dark:text-white">
{repo.stars.toLocaleString()}
</td>
<td className="px-6 py-4 whitespace-nowrap text-right text-sm text-gray-600 dark:text-gray-400">
{repo.forks.toLocaleString()}
</td>
<td className="px-6 py-4 whitespace-nowrap text-right text-sm text-gray-600 dark:text-gray-400">
{repo.unique_visitors > 0
? repo.unique_visitors.toLocaleString()
: "—"}
</td>
<td className="px-6 py-4 whitespace-nowrap text-right text-sm text-gray-600 dark:text-gray-400">
{repo.unique_cloners > 0
? repo.unique_cloners.toLocaleString()