X-Git-Url: https://git.sesse.net/?p=remoteglot-book;a=blobdiff_plain;f=www%2Fopening-stats.pl;h=d74f1add083bddcc89ec6551b4091df760f0e16e;hp=06f67b26931905884642f75c9210b03f7e56f842;hb=e6cab1e6d437e7ca15b32795c14a49baf08df5dc;hpb=b3c16087f728142f36620ed6be3919e7a551e261 diff --git a/www/opening-stats.pl b/www/opening-stats.pl index 06f67b2..d74f1ad 100755 --- a/www/opening-stats.pl +++ b/www/opening-stats.pl @@ -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; +}