Compress after playing all games
This commit is contained in:
1 parent
ca630c80f2
commit
ff8c01bf2d
3 files changed
+38
-18
No files matched your search
+11
-9
@@ -38,7 +38,7 @@ def pgn_list_to_headers(lines):
|
||||
def pgn_strip_headers(headers):
|
||||
# PGN Format: [<Header> "<Value>"]
|
||||
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())
|
||||
+26
-9
@@ -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: <Test>-<Result>-<Time>-<Index>.pgn
|
||||
return '-pgnout PGNs/%d.%d.%d.%d.pgn' % (test_id, result_id, timestamp, cutechess_idx)
|
||||
return '-pgnout %s' % (Cutechess.pgn_name(config, timestamp, cutechess_idx))
|
||||
|
||||
@staticmethod
|
||||
def update_results(results, line):
|
||||
@@ -562,6 +557,16 @@ class Cutechess:
|
||||
subprocess.run(['taskkill', '/f', '/im', dev_process])
|
||||
subprocess.run(['taskkill', '/f', '/im', base_process])
|
||||
|
||||
@staticmethod
|
||||
def pgn_name(config, timestamp, cutechess_idx):
|
||||
|
||||
test_id = int(config.workload['test']['id'])
|
||||
result_id = int(config.workload['result']['id'])
|
||||
|
||||
# Format: <Test>-<Result>-<Time>-<Index>.pgn
|
||||
return 'PGNs/%d.%d.%d.%d.pgn' % (test_id, result_id, timestamp, cutechess_idx)
|
||||
|
||||
|
||||
class PGNHelper:
|
||||
|
||||
@staticmethod
|
||||
@@ -694,7 +699,7 @@ class ResultsReporter(object):
|
||||
for x in range(cutechess_cnt):
|
||||
|
||||
# Reuse logic that was given to Cutechess to decide the PGN name
|
||||
fname = Cutechess.pgnout_settings(self.config, timestamp, x).split()[1]
|
||||
fname = Cutechess.pgn_name(self.config, timestamp, x)
|
||||
|
||||
# For any game with weird Termination, report it
|
||||
for header, moves in PGNHelper.slice_pgn_file(fname):
|
||||
@@ -1088,6 +1093,18 @@ def complete_workload(config):
|
||||
Cutechess.kill_everything(dev_name, base_name)
|
||||
raise
|
||||
|
||||
if config.workload['test']['upload_pgns'] == 'FALSE':
|
||||
return
|
||||
|
||||
compact = config.workload['test']['upload_pgns'] == 'COMPACT'
|
||||
pgn_files = [Cutechess.pgn_name(config, timestamp, x) for x in range(cutechess_cnt)]
|
||||
compressed = compress_list_of_pgns(pgn_files, compact)
|
||||
|
||||
with open('compressed.pgn.bz2', 'wb') as fout:
|
||||
fout.write(compressed)
|
||||
|
||||
sys.exit()
|
||||
|
||||
def download_opening_book(config):
|
||||
|
||||
# Log our attempts to download and verify the book
|
||||
|
||||
Reference in new issue
Block a user