X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=www%2Fopening-stats.pl;h=d74f1add083bddcc89ec6551b4091df760f0e16e;hb=e6cab1e6d437e7ca15b32795c14a49baf08df5dc;hp=47bae771d4b3eb8b37ce46e9f242ff50e8765c40;hpb=62de36318c4a6347a3bd6f2128de649d209e804b;p=remoteglot-book diff --git a/www/opening-stats.pl b/www/opening-stats.pl index 47bae77..d74f1ad 100755 --- a/www/opening-stats.pl +++ b/www/opening-stats.pl @@ -5,16 +5,16 @@ 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", $hex + or die "../binlookup: $!"; my $opening; @@ -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; +}