]> git.sesse.net Git - foosball/blobdiff - www/index.pl
Show the number of games.
[foosball] / www / index.pl
index c1ab7d17a2993e2dab12c7a66cfcb31556c88645..9d439751bde488156435cfd3f898a7a9c6b8878f 100755 (executable)
@@ -10,7 +10,7 @@ my $dbh = foosball::db_connect();
 
 # Single score board (whoa, inefficient)
 my @single_top = ();
-my $q = $dbh->prepare('select username from users');
+my $q = $dbh->prepare('select username,count(*) as num_games from single_rating group by username');
 $q->execute();
 while (my $ref = $q->fetchrow_hashref) {
        my $username = $ref->{'username'};
@@ -30,13 +30,14 @@ while (my $ref = $q->fetchrow_hashref) {
                'rd' => foosball::round($rd),
                'lowerbound' => foosball::round($rating - 3.0*$rd),
                'trend' => $trend,
+               'numgames' => $ref->{'num_games'},
        };
 }
 @single_top = sort { $b->{'lowerbound'} <=> $a->{'lowerbound'} } @single_top;
 
 # Double score board
 my @double_top = ();
-$q = $dbh->prepare('select username from users');
+$q = $dbh->prepare('select username,count(*) as num_games from double_rating group by username');
 $q->execute();
 while (my $ref = $q->fetchrow_hashref) {
        my $username = $ref->{'username'};
@@ -56,6 +57,7 @@ while (my $ref = $q->fetchrow_hashref) {
                'rd' => foosball::round($rd),
                'lowerbound' => foosball::round($rating - 3.0*$rd),
                'trend' => $trend,
+               'numgames' => $ref->{'num_games'},
        };
 }
 @double_top = sort { $b->{'lowerbound'} <=> $a->{'lowerbound'} } @double_top;