]> git.sesse.net Git - remoteglot-book/blobdiff - www/opening-stats.pl
Use the new opening data from pgn-extract.
[remoteglot-book] / www / opening-stats.pl
index 06f67b26931905884642f75c9210b03f7e56f842..d74f1add083bddcc89ec6551b4091df760f0e16e 100755 (executable)
@@ -5,9 +5,9 @@ use CGI;
 use JSON::XS;
 use lib '..';
 use Position;
-use ECO;
 
-ECO::unpersist("../openings.txt");
+our %openings = ();
+read_openings();
 
 my $cgi = CGI->new;
 my $fen = $cgi->param('fen');
@@ -31,7 +31,7 @@ while (<$fh>) {
                black_avg_elo => $black_avg_elo * 1,
                num_elo => $num_elo * 1
        };
-       $opening = $ECO::openings[$opening_num];
+       $opening = $openings{$opening_num};
 }
 close $fh;
 
@@ -44,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;
+}