|
| 1 | +import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; |
| 2 | +import { Badge } from "@/components/ui/badge"; |
| 3 | +import { FolderGit2, Users, LinkIcon, UsersRound, Tags } from "lucide-react"; |
| 4 | +import { |
| 5 | + getSubmissionStats, |
| 6 | + getTrackCounts, |
| 7 | + getTeamSizeDistribution, |
| 8 | + getSubmissionTimeline, |
| 9 | +} from "@/lib/queries"; |
| 10 | +import { TrackChart, TimelineChart, TeamSizeChart } from "@/components/admin/charts"; |
| 11 | + |
| 12 | +export const metadata = { title: "Admin · Stats" }; |
| 13 | + |
| 14 | +function StatCard({ |
| 15 | + label, |
| 16 | + value, |
| 17 | + hint, |
| 18 | + icon: Icon, |
| 19 | +}: { |
| 20 | + label: string; |
| 21 | + value: string | number; |
| 22 | + hint?: string; |
| 23 | + icon: React.ComponentType<{ className?: string }>; |
| 24 | +}) { |
| 25 | + return ( |
| 26 | + <Card> |
| 27 | + <CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2"> |
| 28 | + <CardTitle className="text-sm font-medium text-muted-foreground">{label}</CardTitle> |
| 29 | + <Icon className="size-4 text-muted-foreground" /> |
| 30 | + </CardHeader> |
| 31 | + <CardContent> |
| 32 | + <div className="text-3xl font-semibold tracking-tight">{value}</div> |
| 33 | + {hint && <p className="mt-1 text-xs text-muted-foreground">{hint}</p>} |
| 34 | + </CardContent> |
| 35 | + </Card> |
| 36 | + ); |
| 37 | +} |
| 38 | + |
| 39 | +export default async function StatsPage() { |
| 40 | + const [stats, tracks, teamSizes, timeline] = await Promise.all([ |
| 41 | + getSubmissionStats(), |
| 42 | + getTrackCounts(), |
| 43 | + getTeamSizeDistribution(), |
| 44 | + getSubmissionTimeline(), |
| 45 | + ]); |
| 46 | + |
| 47 | + const devpostPct = |
| 48 | + stats.totalProjects > 0 |
| 49 | + ? Math.round((stats.withDevpost / stats.totalProjects) * 100) |
| 50 | + : 0; |
| 51 | + |
| 52 | + return ( |
| 53 | + <div className="space-y-6"> |
| 54 | + <div> |
| 55 | + <h2 className="text-xl font-semibold tracking-tight">Submission stats</h2> |
| 56 | + <p className="text-sm text-muted-foreground"> |
| 57 | + Live from the submissions database. |
| 58 | + </p> |
| 59 | + </div> |
| 60 | + |
| 61 | + <div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-5"> |
| 62 | + <StatCard label="Projects" value={stats.totalProjects} icon={FolderGit2} /> |
| 63 | + <StatCard label="Hackers" value={stats.totalHackers} hint="across all teams" icon={Users} /> |
| 64 | + <StatCard |
| 65 | + label="Avg team size" |
| 66 | + value={stats.avgTeamSize} |
| 67 | + hint="members per project" |
| 68 | + icon={UsersRound} |
| 69 | + /> |
| 70 | + <StatCard label="Tracks" value={stats.distinctTracks} hint="distinct tracks entered" icon={Tags} /> |
| 71 | + <StatCard |
| 72 | + label="Devpost links" |
| 73 | + value={`${devpostPct}%`} |
| 74 | + hint={`${stats.withDevpost} of ${stats.totalProjects} projects`} |
| 75 | + icon={LinkIcon} |
| 76 | + /> |
| 77 | + </div> |
| 78 | + |
| 79 | + <div className="grid gap-6 lg:grid-cols-2"> |
| 80 | + <Card> |
| 81 | + <CardHeader> |
| 82 | + <CardTitle>Projects per track</CardTitle> |
| 83 | + <CardDescription>Top tracks by number of submissions</CardDescription> |
| 84 | + </CardHeader> |
| 85 | + <CardContent> |
| 86 | + <TrackChart data={tracks} /> |
| 87 | + </CardContent> |
| 88 | + </Card> |
| 89 | + |
| 90 | + <div className="space-y-6"> |
| 91 | + <Card> |
| 92 | + <CardHeader> |
| 93 | + <CardTitle>Submissions over time</CardTitle> |
| 94 | + <CardDescription>Cumulative submissions by hour</CardDescription> |
| 95 | + </CardHeader> |
| 96 | + <CardContent> |
| 97 | + <TimelineChart data={timeline} /> |
| 98 | + </CardContent> |
| 99 | + </Card> |
| 100 | + <Card> |
| 101 | + <CardHeader> |
| 102 | + <CardTitle>Team sizes</CardTitle> |
| 103 | + <CardDescription>Projects by number of members</CardDescription> |
| 104 | + </CardHeader> |
| 105 | + <CardContent> |
| 106 | + <TeamSizeChart data={teamSizes} /> |
| 107 | + </CardContent> |
| 108 | + </Card> |
| 109 | + </div> |
| 110 | + </div> |
| 111 | + |
| 112 | + <Card> |
| 113 | + <CardHeader> |
| 114 | + <CardTitle className="flex items-center gap-2"> |
| 115 | + All tracks |
| 116 | + <Badge variant="secondary">{tracks.length}</Badge> |
| 117 | + </CardTitle> |
| 118 | + <CardDescription>Full breakdown, including smaller tracks</CardDescription> |
| 119 | + </CardHeader> |
| 120 | + <CardContent> |
| 121 | + <div className="flex flex-wrap gap-2"> |
| 122 | + {tracks.map((t) => ( |
| 123 | + <Badge key={t.track} variant="outline" className="font-normal"> |
| 124 | + {t.track} |
| 125 | + <span className="ml-1.5 text-muted-foreground">{t.count}</span> |
| 126 | + </Badge> |
| 127 | + ))} |
| 128 | + </div> |
| 129 | + </CardContent> |
| 130 | + </Card> |
| 131 | + </div> |
| 132 | + ); |
| 133 | +} |
0 commit comments