]> git.sesse.net Git - remoteglot-book/blobdiff - www/opening-stats.pl
Partition the SSTable; somewhat less efficient space-wise, it seems, but we avoid...
[remoteglot-book] / www / opening-stats.pl
index 3b2b2ff78c8f66b34a00336430e3482eec4eda0e..33d3c082dcd551a657a7c5847360c47d0a26046c 100755 (executable)
@@ -5,32 +5,33 @@ use CGI;
 use JSON::XS;
 use lib '..';
 use Position;
-use ECO;
 
-ECO::unpersist("../book/openings.txt");
+our %openings = ();
+read_openings();
 
 my $cgi = CGI->new;
 my $fen = $cgi->param('fen');
 my $pos = Position->from_fen($fen);
 my $hex = unpack('H*', $pos->bitpacked_fen);
-open my $fh, "-|", "../book/binlookup", "../book/open.mtbl", $hex
-       or die "../book/binlookup: $!";
+open my $fh, "-|", "../binlookup", "../open.mtbl", "40", $hex
+       or die "../binlookup: $!";
 
 my $opening;
 
 my @moves = ();
 while (<$fh>) {
        chomp;
-       my ($move, $white, $draw, $black, $opening_num, $white_avg_elo, $black_avg_elo) = split;
+       my ($move, $white, $draw, $black, $opening_num, $white_avg_elo, $black_avg_elo, $num_elo) = split;
        push @moves, {
                move => $move,
                white => $white * 1,
                draw => $draw * 1,
                black => $black * 1,
                white_avg_elo => $white_avg_elo * 1,
-               black_avg_elo => $black_avg_elo * 1
+               black_avg_elo => $black_avg_elo * 1,
+               num_elo => $num_elo * 1
        };
-       $opening = $ECO::openings[$opening_num];
+       $opening = $openings{$opening_num} // 'A00: Start position';
 }
 close $fh;
 
@@ -43,3 +44,18 @@ sub num {
        my $x = shift;
        return $x->{'white'} + $x->{'draw'} + $x->{'black'};
 }
+
+sub read_openings {
+       open my $fh, "../openings.txt"
+               or die "../openings.txt: $!";
+       for my $line (<$fh>) {
+               chomp $line;
+               my ($hash, $eco, $opening, $variation, $subvariation) = split /\t/, $line;
+               if ($variation eq '') {
+                       $openings{$hash} = $eco . ": " . $opening;
+               } else {
+                       $openings{$hash} = $eco . ": " . $opening . ": " . $variation;
+               }
+       }
+       close $fh;
+}