From ff8c01bf2d4f0fb22546f6798052fa618d259d0a Mon Sep 17 00:00:00 2001 From: andrew Date: Mon, 27 Nov 2023 14:17:58 -0500 Subject: [PATCH] Compress after playing all games --- Client/pgn_util.py | 20 +++++++++-------- Client/worker.py | 35 +++++++++++++++++++++-------- OpenBench/workloads/get_workload.py | 1 + 3 files changed, 38 insertions(+), 18 deletions(-) diff --git a/Client/pgn_util.py b/Client/pgn_util.py index 52c80ea..f070d5c 100644 --- a/Client/pgn_util.py +++ b/Client/pgn_util.py @@ -38,7 +38,7 @@ def pgn_list_to_headers(lines): def pgn_strip_headers(headers): # PGN Format: [
""] desired = [ 'White', 'Black', 'Result', 'PlyCount', 'FEN', 'TimeControl' ] - return '\n'.join('[%s "%s"]' % (f, headers[f]) for f in desired) + return '\n'.join('[%s "%s"]' % (f, headers[f]) for f in desired if f in headers) def pgn_strip_movelist(move_text, compact): @@ -61,18 +61,20 @@ def pgn_strip_movelist(move_text, compact): # PGNs expect trailing game result text return stripped + result_regex.search(move_text).group(1) -def strip_entire_pgn(file_name, compact=True): +def strip_entire_pgn(file_name, compact): stripped = '' - for header_dict, move_text in pgn_iterator(sys.argv[1]): - stripped += pgn_strip_headers(header_dict) + '\n' - stripped += pgn_strip_movelist(move_text, compact) + '\n' + for header_dict, move_text in pgn_iterator(file_name): + stripped += pgn_strip_headers(header_dict) + '\n\n' + stripped += pgn_strip_movelist(move_text, compact) + '\n\n' return stripped +def compress_list_of_pgns(file_names, compact): -if __name__ == '__main__': + text = '' + for fname in file_names: + print ('Compressing %s...' % (fname)) + text += strip_entire_pgn(fname, compact) - text = strip_entire_pgn(sys.argv[1], compact=True) - - compressed = bz2.compress(text.encode()) + return bz2.compress(text.encode()) diff --git a/Client/worker.py b/Client/worker.py index 07f7340..f41eacf 100644 --- a/Client/worker.py +++ b/Client/worker.py @@ -42,12 +42,12 @@ from subprocess import PIPE, Popen, call, STDOUT from itertools import combinations_with_replacement from concurrent.futures import ThreadPoolExecutor -# from client import BadVersionException - from client import BadVersionException from client import url_join from client import try_forever +from pgn_util import compress_list_of_pgns + ## Basic configuration of the Client. These timeouts can be changed at will CLIENT_VERSION = 22 # Client version to send to the Server @@ -492,12 +492,7 @@ class Cutechess: @staticmethod def pgnout_settings(config, timestamp, cutechess_idx): - - test_id = int(config.workload['test']['id']) - result_id = int(config.workload['result']['id']) - - # Format: --