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):
|
def pgn_strip_headers(headers):
|
||||||
# PGN Format: [<Header> "<Value>"]
|
# PGN Format: [<Header> "<Value>"]
|
||||||
desired = [ 'White', 'Black', 'Result', 'PlyCount', 'FEN', 'TimeControl' ]
|
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):
|
def pgn_strip_movelist(move_text, compact):
|
||||||
|
|
||||||
@@ -61,18 +61,20 @@ def pgn_strip_movelist(move_text, compact):
|
|||||||
# PGNs expect trailing game result text
|
# PGNs expect trailing game result text
|
||||||
return stripped + result_regex.search(move_text).group(1)
|
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 = ''
|
stripped = ''
|
||||||
for header_dict, move_text in pgn_iterator(sys.argv[1]):
|
for header_dict, move_text in pgn_iterator(file_name):
|
||||||
stripped += pgn_strip_headers(header_dict) + '\n'
|
stripped += pgn_strip_headers(header_dict) + '\n\n'
|
||||||
stripped += pgn_strip_movelist(move_text, compact) + '\n'
|
stripped += pgn_strip_movelist(move_text, compact) + '\n\n'
|
||||||
|
|
||||||
return stripped
|
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)
|
return bz2.compress(text.encode())
|
||||||
|
|
||||||
compressed = bz2.compress(text.encode())
|
|
||||||
+26
-9
@@ -42,12 +42,12 @@ from subprocess import PIPE, Popen, call, STDOUT
|
|||||||
from itertools import combinations_with_replacement
|
from itertools import combinations_with_replacement
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
|
|
||||||
# from client import BadVersionException
|
|
||||||
|
|
||||||
from client import BadVersionException
|
from client import BadVersionException
|
||||||
from client import url_join
|
from client import url_join
|
||||||
from client import try_forever
|
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
|
## Basic configuration of the Client. These timeouts can be changed at will
|
||||||
|
|
||||||
CLIENT_VERSION = 22 # Client version to send to the Server
|
CLIENT_VERSION = 22 # Client version to send to the Server
|
||||||
@@ -492,12 +492,7 @@ class Cutechess:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def pgnout_settings(config, timestamp, cutechess_idx):
|
def pgnout_settings(config, timestamp, cutechess_idx):
|
||||||
|
return '-pgnout %s' % (Cutechess.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 '-pgnout PGNs/%d.%d.%d.%d.pgn' % (test_id, result_id, timestamp, cutechess_idx)
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def update_results(results, line):
|
def update_results(results, line):
|
||||||
@@ -562,6 +557,16 @@ class Cutechess:
|
|||||||
subprocess.run(['taskkill', '/f', '/im', dev_process])
|
subprocess.run(['taskkill', '/f', '/im', dev_process])
|
||||||
subprocess.run(['taskkill', '/f', '/im', base_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:
|
class PGNHelper:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -694,7 +699,7 @@ class ResultsReporter(object):
|
|||||||
for x in range(cutechess_cnt):
|
for x in range(cutechess_cnt):
|
||||||
|
|
||||||
# Reuse logic that was given to Cutechess to decide the PGN name
|
# 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 any game with weird Termination, report it
|
||||||
for header, moves in PGNHelper.slice_pgn_file(fname):
|
for header, moves in PGNHelper.slice_pgn_file(fname):
|
||||||
@@ -1088,6 +1093,18 @@ def complete_workload(config):
|
|||||||
Cutechess.kill_everything(dev_name, base_name)
|
Cutechess.kill_everything(dev_name, base_name)
|
||||||
raise
|
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):
|
def download_opening_book(config):
|
||||||
|
|
||||||
# Log our attempts to download and verify the book
|
# Log our attempts to download and verify the book
|
||||||
|
|||||||
@@ -158,6 +158,7 @@ def workload_to_dictionary(test, result, machine):
|
|||||||
'win_adj' : test.win_adj,
|
'win_adj' : test.win_adj,
|
||||||
'draw_adj' : test.draw_adj,
|
'draw_adj' : test.draw_adj,
|
||||||
'workload_size' : test.workload_size,
|
'workload_size' : test.workload_size,
|
||||||
|
'upload_pgns' : test.upload_pgns,
|
||||||
}
|
}
|
||||||
|
|
||||||
workload['test']['book'] = {
|
workload['test']['book'] = {
|
||||||
|
|||||||
Reference in new issue
Block a user