]> git.ais-ucla.org Git - stats.ais-ucla.org.git/commitdiff
add leaderboard
authorChristopher Milan <chrismilan@ucla.edu>
Mon, 17 Mar 2025 04:53:52 +0000 (21:53 -0700)
committerChristopher Milan <chrismilan@ucla.edu>
Mon, 17 Mar 2025 05:05:20 +0000 (22:05 -0700)
leader.cgi [new file with mode: 0755]

diff --git a/leader.cgi b/leader.cgi
new file mode 100755 (executable)
index 0000000..f73668d
--- /dev/null
@@ -0,0 +1,62 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use CGI qw(:standard);
+use DBI;
+
+print header(-type => 'text/html', -charset => 'utf-8');
+print start_html(-title => "GPU Leaderboard",
+                 -style => "background-image: url('/bg.gif')");
+
+my $db_file = "/www/leader/gpu.db";
+my $dbh = DBI->connect("dbi:SQLite:dbname=$db_file", "", "", {
+  RaiseError => 1,
+  AutoCommit => 1
+}) or die $DBI::errstr;
+
+my $query = qq{
+  SELECT u.name, SUM(g.util * (1.0/60.0)) AS gpu_hours
+  FROM usage g
+  JOIN users u ON g.uid = u.uid
+  GROUP BY u.uid
+  ORDER BY gpu_hours DESC;
+};
+
+my $sth = $dbh->prepare($query);
+$sth->execute();
+
+print h1("GPU Leaderboard");
+
+print "<table border='1' cellspacing='0' cellpadding='5'>";
+print "<tr><th>Name</th><th>GPU Hours</th></tr>";
+
+while (my $row = $sth->fetchrow_hashref) {
+    print "<tr>";
+    print "<td>$row->{name}</td>";
+    print "<td>" . sprintf("%.2f", $row->{gpu_hours} || 0) . "</td>";
+    print "</tr>";
+}
+
+print "</table>";
+
+print <<'END';
+<hr />
+<footer style="text-align:center">
+<a href="https://acme.com/software/thttpd/"><img src="/badges/thttpd.gif" alt="powered by thttpd" height="31" width="88"></a>
+<a href="https://www.freebsd.org/"><img src="/badges/freebsd.gif" alt="powered by FreeBSD" height="31" width="88"></a>
+<a href="//cherf.ais-ucla.org/"><img src="/badges/cherf.gif" alt="powered by cherf" height="31" width="88"></a>
+<address>
+&copy; 2025 Christopher Milan
+<br />
+<a href="/">stats.ais-ucla.org</a>
+</address>
+</footer>
+</body>
+</html>
+END
+
+# Finish HTML and cleanup
+print end_html;
+$sth->finish();
+$dbh->disconnect();
+