]> git.sesse.net Git - remoteglot-book/commitdiff
Store and handle the PGN start position.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 12 Dec 2014 21:56:30 +0000 (22:56 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 13 Dec 2014 00:07:33 +0000 (01:07 +0100)
binloader.cpp
binlookup.cpp
binmerger.cpp
count.proto
find-pgn-split-point.sh [moved from partition-pgn.sh with 100% similarity]
opening-stats.pl
www/opening-stats.pl

index 6472f1009f73a0f0348e43ddd1656a4df86adfca..5bf2502c6867610fbb963c91d63aaf3f717312c8 100644 (file)
@@ -25,6 +25,7 @@ struct Element {
        Result result;
        int opening_num, white_elo, black_elo;
        time_t timestamp;
+       long start_position;
 
        bool operator< (const Element& other) const {
                return bpfen < other.bpfen;
@@ -68,6 +69,7 @@ int main(int argc, char **argv)
 
                        int opening_num, white_elo, black_elo;
                        time_t timestamp;
+                       long start_position;
                        if (fread(&white_elo, sizeof(white_elo), 1, fp) != 1) {
                                perror("fread()");
                                //exit(1);
@@ -88,6 +90,12 @@ int main(int argc, char **argv)
                                //exit(1);
                                break;
                        }
+                       if (fread(&start_position, sizeof(start_position), 1, fp) != 1) {
+                               perror("fread()");
+                               //exit(1);
+                               break;
+                       }
+
 
                        l = getc(fp);
                        if (l == -1) {
@@ -102,7 +110,7 @@ int main(int argc, char **argv)
                        }
 
                        int bucket = hash_key_to_bucket(bpfen.data(), bpfen.size(), num_buckets);
-                       elems[bucket].emplace_back(Element {std::move(bpfen), std::move(move), Result(r), opening_num, white_elo, black_elo, timestamp});
+                       elems[bucket].emplace_back(Element {std::move(bpfen), std::move(move), Result(r), opening_num, white_elo, black_elo, timestamp, start_position});
                        ++num_elems;
                }
                fclose(fp);
@@ -145,6 +153,7 @@ int main(int argc, char **argv)
                                        c.set_first_timestamp(e.timestamp);
                                }
                                c.set_opening_num(e.opening_num);
+                               c.set_pgn_start_position(e.start_position);
                        }
                        if (!moves.count(e.move)) {
                                moves.insert(e.move);
index 958a7bfc6be82fce622ee02e825457c3e8d335f9..179515b44a0477a06bc2bcdc3946e4e678c4478e 100644 (file)
@@ -61,11 +61,12 @@ int main(int argc, char **argv)
                while (mtbl_iter_next(it, &key, &len_key, &val, &len_val)) {
                        Count c;
                        c.ParseFromArray(val, len_val);
-                       printf("%d %d %d %u %f %f %d %ld",
+                       printf("%d %d %d %u %f %f %d %ld %ld",
                                c.white(), c.draw(), c.black(), c.opening_num(),
                                double(c.sum_white_elo()) / c.num_elo(),
                                double(c.sum_black_elo()) / c.num_elo(),
-                               c.num_elo(), c.first_timestamp());
+                               c.num_elo(), c.first_timestamp(),
+                               c.pgn_start_position());
                        for (int j = 0; j < c.move_size(); ++j) {
                                printf(" %s", c.move(j).c_str());
                        }
index 9bd969ead0d3795ed0a495047ad5e2ae77232a0c..7e341592eec4d75c7f94e5702e53fd83926d26b0 100644 (file)
@@ -32,11 +32,13 @@ void merge_count(void* userdata,
                if (c0.has_first_timestamp()) {
                        c.set_first_timestamp(c0.first_timestamp());
                }
+               c.set_pgn_start_position(c0.pgn_start_position());
        } else {
                c.set_opening_num(c1.opening_num());
                if (c1.has_first_timestamp()) {
                        c.set_first_timestamp(c1.first_timestamp());
                }
+               c.set_pgn_start_position(c1.pgn_start_position());
        }
 
        // Merge the moves, with deduplication.
index 7712f97649ed84de2d6c8191c29b3a7aac57a1a0..9ee285919a82142d6126b0ed9b81d58c50698a8c 100644 (file)
@@ -12,8 +12,10 @@ message Count {
        optional int64 sum_black_elo = 6;
        optional int32 num_elo = 7;
 
-       // First timestamp this position/move was seen. 
+       // First timestamp this position/move was seen, and the byte offset
+       // into the PGN file for that game.
        optional int64 first_timestamp = 8 [default=32503680000];
+       optional int64 pgn_start_position = 10;
 
        // Moves seen from this position.
        repeated string move = 9;
similarity index 100%
rename from partition-pgn.sh
rename to find-pgn-split-point.sh
index 324b1582fc20d0e569fd383b4df77414063f5d44..a90ca0b543535c86c7caf1e07ede2ccda37c5e79 100755 (executable)
@@ -21,7 +21,7 @@ my $line = <$chld_out>;
 print $line;
 chomp $line;
 
-my ($white, $draw, $black, $opening_num, $white_avg_elo, $black_avg_elo, $num_elo, $timestamp, @moves) = split / /, $line;
+my ($white, $draw, $black, $opening_num, $white_avg_elo, $black_avg_elo, $num_elo, $timestamp, $pgn_start_position, @moves) = split / /, $line;
 
 # Explore one move out.
 for my $move (@moves) {
index f9e85484eb0ca749df78fbd604b9a10a7f748319..3a02cf9fde6fcd917b5d3cbc6237c9a3949c4ce2 100755 (executable)
@@ -21,7 +21,7 @@ my $hex = unpack('H*', $pos->bitpacked_fen);
 print $chld_in $hex, "\n";
 chomp (my $line = <$chld_out>);
 
-my ($white, $draw, $black, $opening_num, $white_avg_elo, $black_avg_elo, $num_elo, $timestamp, @moves) = split / /, $line;
+my ($white, $draw, $black, $opening_num, $white_avg_elo, $black_avg_elo, $num_elo, $timestamp, $pgn_start_position, @moves) = split / /, $line;
 my $opening = $openings{$opening_num} // 'A00: Start position';
 
 # Explore one move out.