]> git.sesse.net Git - remoteglot-book/blobdiff - www/opening-stats.pl
Fix a warning.
[remoteglot-book] / www / opening-stats.pl
index 3fb8946f3122fcf10fab9f73519bd801ee8ca10f..696bfa147c2d5e2017bc8ff8737231e4828e2b54 100755 (executable)
@@ -68,8 +68,20 @@ for my $move (@{$root_aux_data->{'moves'}}) {
        push @json_moves, $json_pos;
 }
 
+# Get stats for the root position, for the human index.
+my $start_pos = Position->start_pos("white", "black");
+my ($json_start_pos, undef) = get_json_move($start_pos, 0, $chld_in, $chld_out);
+my $total_games = $json_start_pos->{'white'} + $json_start_pos->{'draw'} + $json_start_pos->{'black'};
+my $computer_games = $json_start_pos->{'computer'} * 1;
+
 print $cgi->header(-type=>'application/json');
-print JSON::XS::encode_json({ moves => \@json_moves, opening => $opening, root_game => $root_game });
+print JSON::XS::encode_json({
+       moves => \@json_moves,
+       opening => $opening,
+       root_game => $root_game,
+       total_games => $total_games,
+       computer_games => $computer_games
+});
 
 sub read_openings {
        open my $fh, "../openings.txt"
@@ -133,11 +145,12 @@ sub get_json_move {
                return (undef, undef);
        }
 
-       my ($white, $draw, $black, $opening_num, $white_sum_elo, $black_sum_elo, $num_elo, $timestamp, $pgn_file_number, $pgn_start_position, @moves) = split / /, $line;
+       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_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,