]> git.sesse.net Git - wloh/blobdiff - www/index.pl
Output when we last synced.
[wloh] / www / index.pl
index c7cfa40bd53c66e87d68193e2efa022b6cfb43d9..ec7318a4079685aca9f500b41123ab4df27f24b8 100755 (executable)
@@ -12,6 +12,7 @@ use Encode;
 use utf8;
 use locale;
 require '../config.pm';
+require '../common.pm';
 
 my $cgi = CGI->new;
 
@@ -41,7 +42,7 @@ sub color {
 }
 
 sub make_table {
-       my ($lowest_division, $used_ratings, $used_ratings_stddev) = @_;
+       my ($lowest_division, $used_ratings, $used_cov) = @_;
 
        print <<"EOF";
 
@@ -61,8 +62,19 @@ EOF
 
        for my $id (keys %players) {
                my $rating = $used_ratings->{$id} // 1500.0;
-               my $rating_stddev = $used_ratings_stddev->{$id} // $parms{-3};
-               printf MCCALC "%s %f %f\n", $id, $rating, $rating_stddev;
+               printf MCCALC "%s %f\n", $id, $rating;
+       }
+
+       # covariance matrix
+       for my $id1 (keys %players) {
+               for my $id2 (keys %players) {
+                       if ($id1 == $id2) {
+                               printf MCCALC "%f ", ($used_cov->{$id1}{$id2} // $parms{-3});
+                       } else {
+                               printf MCCALC "%f ", ($used_cov->{$id1}{$id2} // 0.0);
+                       }
+               }
+               printf MCCALC "\n";
        }
 
        for my $match (@matches) {
@@ -263,6 +275,16 @@ 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 $lowest_division = ($division == $max_division);
 make_table($lowest_division, {}, {});
 
@@ -271,9 +293,11 @@ print <<"EOF";
       se <a href="/rating">ratingsiden</a>.</p>
 EOF
 
-make_table($lowest_division, \%ratings, \%ratings_stddev);
+make_table($lowest_division, \%ratings, $cov);
 
-print << "EOF";
+wloh_common::output_last_sync($dbh);
+
+print <<"EOF";
   </body>
 </html>
 EOF