]> git.sesse.net Git - remoteglot-book/blobdiff - www/opening-stats.pl
Indent fix.
[remoteglot-book] / www / opening-stats.pl
index 0da6e0546f54e1b20382c0d39787cd9292c35df0..58a0f9be02a9ed230808fb00ce281abeef3531e9 100755 (executable)
@@ -48,6 +48,9 @@ eval {
        $root_game->{'eco'} = $pgn->eco;
        $root_game->{'moves'} = int(((scalar @{$pgn->moves}) + 1) / 2);
 };
+if ($@) {
+       print STDERR "Error while getting root move: $@\n";
+}
 
 # Explore one move out.
 my $white_left = $json_root_pos->{'white'};
@@ -128,6 +131,7 @@ sub read_root_pgn {
                or die "../pgnnames.txt: $!";
        while (<$pgnnamesfh>) {
                chomp;
+               s/^comp://;
                push @pgnnames, $_;
        }
        close $pgnnamesfh;
@@ -170,14 +174,14 @@ sub get_json_move {
 
        my ($white, $draw, $black, $computer, $opening_num, $white_sum_elo, $black_sum_elo, $num_elo, $timestamp, $pgn_file_number, $pgn_start_position, @moves) = split / /, $line;
        my $json_pos = {
-               white => $white,
-               draw => $draw,
-               black => $black,
-               computer => $computer,
+               white => int($white),
+               draw => int($draw),
+               black => int($black),
+               computer => int($computer),
                white_avg_elo => $num_elo == 0 ? undef : $white_sum_elo / $num_elo,
                black_avg_elo => $num_elo == 0 ? undef : $black_sum_elo / $num_elo,
-               num_elo => $num_elo,
-               opening_num => $opening_num,
+               num_elo => int($num_elo),
+               opening_num => $opening_num,  # Keep as string.
        };
        my $aux_data = {  # Only relevant for the root.
                pos_hash => $pos_hash * 1,