]> git.sesse.net Git - wloh/commitdiff
Factor out fetching of the covariance matrix into its own function.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 25 Mar 2012 15:23:22 +0000 (17:23 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 25 Mar 2012 15:23:22 +0000 (17:23 +0200)
www/index.pl

index b754d4cffc98f44c72cbc91e9f1de1a3d5f5bf1a..ec6428c5f6072545110821b20adec298c8f4f9c7 100755 (executable)
@@ -121,6 +121,21 @@ EOF
 EOF
 }
 
+sub get_covariance_matrix {
+       my ($dbh, @players) = @_;
+
+       my $player_sql = '{' . join(',', @players ) . '}';
+       my $q = $dbh->prepare('SELECT * FROM covariance WHERE player1=ANY(?::smallint[]) AND player2=ANY(?::smallint[])', { pg_prepare_now => 0 });
+       $q->execute($player_sql, $player_sql);
+
+       my $cov = {};
+       while (my $ref = $q->fetchrow_hashref) {
+               $cov->{$ref->{'player1'}}{$ref->{'player2'}} = $ref->{'cov'};
+       }
+
+       return $cov;
+}
+
 sub make_table {
        my ($lowest_division, $used_ratings, $used_cov) = @_;
 
@@ -303,15 +318,7 @@ while (my $ref = $q->fetchrow_hashref) {
 }
 $q->finish;
 
-# Pick up covariance matrix
-my $player_sql = '{' . join(',', keys %players ) . '}';
-my $q = $dbh->prepare('SELECT * FROM covariance WHERE player1=ANY(?::smallint[]) AND player2=ANY(?::smallint[])', { pg_prepare_now => 0 });
-$q->execute($player_sql, $player_sql);
-
-my $cov = {};
-while (my $ref = $q->fetchrow_hashref) {
-       $cov->{$ref->{'player1'}}{$ref->{'player2'}} = $ref->{'cov'};
-}
+my $cov = get_covariance_matrix($dbh, keys %players);
 
 my $max_division = $divisions[$#divisions];
 my $lowest_division = ($division == $max_division);