Initial step for PGN uploading
1. Create the interface code to allow for it. 2. Create pgn_util to strip and compress PGNs
This commit is contained in:
1 parent
1ac76bdcc1
commit
ca630c80f2
8 files changed
+113
-6
No files matched your search
@@ -0,0 +1,78 @@
|
|||||||
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||||
|
# #
|
||||||
|
# OpenBench is a chess engine testing framework by Andrew Grant. #
|
||||||
|
# <https://github.com/AndyGrant/OpenBench> <andrew@grantnet.us> #
|
||||||
|
# #
|
||||||
|
# OpenBench is free software: you can redistribute it and/or modify #
|
||||||
|
# it under the terms of the GNU General Public License as published by #
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or #
|
||||||
|
# (at your option) any later version. #
|
||||||
|
# #
|
||||||
|
# OpenBench is distributed in the hope that it will be useful, #
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
||||||
|
# GNU General Public License for more details. #
|
||||||
|
# #
|
||||||
|
# You should have received a copy of the GNU General Public License #
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
|
||||||
|
# #
|
||||||
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||||
|
|
||||||
|
import bz2
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def pgn_iterator(fname):
|
||||||
|
with open(fname) as pgn:
|
||||||
|
while True:
|
||||||
|
headers = pgn_list_to_headers(iter(lambda: pgn.readline().rstrip(), ''))
|
||||||
|
move_list = ' '.join(iter(lambda: pgn.readline().rstrip(), ''))
|
||||||
|
if not headers or not move_list:
|
||||||
|
break
|
||||||
|
yield (headers, move_list)
|
||||||
|
|
||||||
|
def pgn_list_to_headers(lines):
|
||||||
|
# PGN Format: [<Header> "<Value>"]
|
||||||
|
return { f.split()[0][1:] : re.search(r'"([^"]*)"', f).group(1) for f in 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)
|
||||||
|
|
||||||
|
def pgn_strip_movelist(move_text, compact):
|
||||||
|
|
||||||
|
if not compact: # Captures Score Depth/SelDepth Time Nodes
|
||||||
|
comment_regex = r'([+-]?M?\d+(?:\.\d+)? \d+/\d+ \d+ \d+)[^}]*'
|
||||||
|
|
||||||
|
else: # Captures Score and nothing else
|
||||||
|
comment_regex = r'([+-]?M?\d+(?:\.\d+)?) \d+/\d+ \d+ \d+[^}]*'
|
||||||
|
|
||||||
|
# Captures the Move and Comment, discarding extra commentary and move numbers
|
||||||
|
one_ply_regex = re.compile(r'\s*(?:\d+\. )?([a-zA-Z0-9+=#-]+) {%s}' % (comment_regex))
|
||||||
|
|
||||||
|
# Captures the trailing game result
|
||||||
|
result_regex = re.compile(r'\s*(1-0|0-1|1/2-1/2|\*)')
|
||||||
|
|
||||||
|
stripped = '' # Add each: <Move> {<Comment>}
|
||||||
|
for move, comment in one_ply_regex.findall(move_text):
|
||||||
|
stripped += '%s {%s} ' % (move, comment)
|
||||||
|
|
||||||
|
# PGNs expect trailing game result text
|
||||||
|
return stripped + result_regex.search(move_text).group(1)
|
||||||
|
|
||||||
|
def strip_entire_pgn(file_name, compact=True):
|
||||||
|
|
||||||
|
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'
|
||||||
|
|
||||||
|
return stripped
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
|
||||||
|
text = strip_entire_pgn(sys.argv[1], compact=True)
|
||||||
|
|
||||||
|
compressed = bz2.compress(text.encode())
|
||||||
+10
-5
@@ -29,20 +29,23 @@
|
|||||||
"both_options" : "Threads=1 Hash=64 Minimal=true",
|
"both_options" : "Threads=1 Hash=64 Minimal=true",
|
||||||
"both_time_control" : "60.0+0.6",
|
"both_time_control" : "60.0+0.6",
|
||||||
"workload_size" : 8,
|
"workload_size" : 8,
|
||||||
"test_bounds" : "[0.00, 2.25]"
|
"test_bounds" : "[0.00, 2.25]",
|
||||||
|
"upload_pgns" : "COMPACT"
|
||||||
},
|
},
|
||||||
|
|
||||||
"SMP STC" : {
|
"SMP STC" : {
|
||||||
"both_options" : "Threads=6 Hash=128 Minimal=true",
|
"both_options" : "Threads=6 Hash=128 Minimal=true",
|
||||||
"both_time_control" : "10.0+0.1",
|
"both_time_control" : "10.0+0.1",
|
||||||
"workload_size" : 64
|
"workload_size" : 64,
|
||||||
|
"upload_pgns" : "COMPACT"
|
||||||
},
|
},
|
||||||
|
|
||||||
"SMP LTC" : {
|
"SMP LTC" : {
|
||||||
"both_options" : "Threads=15 Hash=256 Minimal=true",
|
"both_options" : "Threads=15 Hash=256 Minimal=true",
|
||||||
"both_time_control" : "30.0+0.3",
|
"both_time_control" : "30.0+0.3",
|
||||||
"workload_size" : 16,
|
"workload_size" : 16,
|
||||||
"test_bounds" : "[0.50, 2.50]"
|
"test_bounds" : "[0.50, 2.50]",
|
||||||
|
"upload_pgns" : "COMPACT"
|
||||||
},
|
},
|
||||||
|
|
||||||
"STC Simplification" : {
|
"STC Simplification" : {
|
||||||
@@ -56,7 +59,8 @@
|
|||||||
"both_options" : "Threads=1 Hash=64 Minimal=true",
|
"both_options" : "Threads=1 Hash=64 Minimal=true",
|
||||||
"both_time_control" : "60.0+0.6",
|
"both_time_control" : "60.0+0.6",
|
||||||
"workload_size" : 8,
|
"workload_size" : 8,
|
||||||
"test_bounds" : "[-1.75, 0.25]"
|
"test_bounds" : "[-1.75, 0.25]",
|
||||||
|
"upload_pgns" : "COMPACT"
|
||||||
},
|
},
|
||||||
|
|
||||||
"STC Regression" : {
|
"STC Regression" : {
|
||||||
@@ -72,7 +76,8 @@
|
|||||||
"both_time_control" : "60.0+0.6",
|
"both_time_control" : "60.0+0.6",
|
||||||
"workload_size" : 8,
|
"workload_size" : 8,
|
||||||
"book_name" : "8moves_v3.epd",
|
"book_name" : "8moves_v3.epd",
|
||||||
"test_max_games" : 40000
|
"test_max_games" : 40000,
|
||||||
|
"upload_pgns" : "COMPACT"
|
||||||
},
|
},
|
||||||
|
|
||||||
"STC Fixed Games" : {
|
"STC Fixed Games" : {
|
||||||
|
|||||||
@@ -126,6 +126,7 @@ def verify_engine_test_preset(test_preset):
|
|||||||
'test_max_games',
|
'test_max_games',
|
||||||
|
|
||||||
'book_name',
|
'book_name',
|
||||||
|
'upload_pgns',
|
||||||
'priority',
|
'priority',
|
||||||
'throughput',
|
'throughput',
|
||||||
'workload_size',
|
'workload_size',
|
||||||
@@ -159,6 +160,7 @@ def verify_engine_tune_preset(tune_preset):
|
|||||||
'spsa_pairs_per',
|
'spsa_pairs_per',
|
||||||
|
|
||||||
'book_name',
|
'book_name',
|
||||||
|
'upload_pgns',
|
||||||
'priority',
|
'priority',
|
||||||
'throughput',
|
'throughput',
|
||||||
'syzygy_wdl',
|
'syzygy_wdl',
|
||||||
|
|||||||
+5
-1
@@ -90,7 +90,8 @@ class Result(Model):
|
|||||||
class Test(Model):
|
class Test(Model):
|
||||||
|
|
||||||
# Misc information
|
# Misc information
|
||||||
author = CharField(max_length=64)
|
author = CharField(max_length=64)
|
||||||
|
upload_pgns = CharField(max_length=16, default='FALSE')
|
||||||
|
|
||||||
# Opening book settings
|
# Opening book settings
|
||||||
book_name = CharField(max_length=32)
|
book_name = CharField(max_length=32)
|
||||||
@@ -194,3 +195,6 @@ class Network(Model):
|
|||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return '[{}] {} ({})'.format(self.engine, self.name, self.sha256)
|
return '[{}] {} ({})'.format(self.engine, self.name, self.sha256)
|
||||||
|
|
||||||
|
class PGN(Model):
|
||||||
|
pass
|
||||||
@@ -105,6 +105,7 @@ def create_new_test(request):
|
|||||||
test = Test()
|
test = Test()
|
||||||
test.author = request.user.username
|
test.author = request.user.username
|
||||||
test.book_name = request.POST['book_name']
|
test.book_name = request.POST['book_name']
|
||||||
|
test.upload_pgns = request.POST['upload_pgns']
|
||||||
|
|
||||||
test.dev = get_engine(*dev_info)
|
test.dev = get_engine(*dev_info)
|
||||||
test.dev_repo = request.POST['dev_repo']
|
test.dev_repo = request.POST['dev_repo']
|
||||||
@@ -169,6 +170,7 @@ def create_new_tune(request):
|
|||||||
test = Test()
|
test = Test()
|
||||||
test.author = request.user.username
|
test.author = request.user.username
|
||||||
test.book_name = request.POST['book_name']
|
test.book_name = request.POST['book_name']
|
||||||
|
test.upload_pgns = request.POST['upload_pgns']
|
||||||
|
|
||||||
test.dev = test.base = get_engine(*dev_info)
|
test.dev = test.base = get_engine(*dev_info)
|
||||||
test.dev_repo = test.base_repo = request.POST['dev_repo']
|
test.dev_repo = test.base_repo = request.POST['dev_repo']
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ def verify_test_creation(errors, request):
|
|||||||
|
|
||||||
# Verify everything about the Test Settings
|
# Verify everything about the Test Settings
|
||||||
(verify_configuration , 'book_name', 'Book', 'books'),
|
(verify_configuration , 'book_name', 'Book', 'books'),
|
||||||
|
(verify_upload_pgns , 'upload_pgns', 'Upload PGNs'),
|
||||||
(verify_test_mode , 'test_mode'),
|
(verify_test_mode , 'test_mode'),
|
||||||
(verify_sprt_bounds , 'test_bounds'),
|
(verify_sprt_bounds , 'test_bounds'),
|
||||||
(verify_sprt_conf , 'test_confidence'),
|
(verify_sprt_conf , 'test_confidence'),
|
||||||
@@ -124,6 +125,7 @@ def verify_tune_creation(errors, request):
|
|||||||
|
|
||||||
# Verify everything about the Test Settings
|
# Verify everything about the Test Settings
|
||||||
(verify_configuration , 'book_name', 'Book', 'books'),
|
(verify_configuration , 'book_name', 'Book', 'books'),
|
||||||
|
(verify_upload_pgns , 'upload_pgns', 'Upload PGNs'),
|
||||||
|
|
||||||
# Verify everything about the General Settings
|
# Verify everything about the General Settings
|
||||||
(verify_integer , 'priority', 'Priority'),
|
(verify_integer , 'priority', 'Priority'),
|
||||||
@@ -270,6 +272,10 @@ def verify_spsa_distribution_type(errors, request, field, field_name):
|
|||||||
try: assert request.POST[field] in candidates
|
try: assert request.POST[field] in candidates
|
||||||
except: errors.append('%s must be in %s' % (field_name, ', '.join(candidates)))
|
except: errors.append('%s must be in %s' % (field_name, ', '.join(candidates)))
|
||||||
|
|
||||||
|
def verify_upload_pgns(errors, request, field, field_name):
|
||||||
|
try: request.POST[field] in ['FALSE', 'COMPACT', 'VERBOSE']
|
||||||
|
except: errors.append('"%s" must be FALSE, COMPACT, or VERBOSE' % (field_name))
|
||||||
|
|
||||||
|
|
||||||
def collect_github_info(errors, request, field):
|
def collect_github_info(errors, request, field):
|
||||||
|
|
||||||
|
|||||||
@@ -186,6 +186,15 @@
|
|||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<label for="upload_pgns"> Upload PGNs </label>
|
||||||
|
<select id="upload_pgns" name="upload_pgns">
|
||||||
|
<option selected value="FALSE"> False </option>
|
||||||
|
<option value="COMPACT"> Compact </option>
|
||||||
|
<option value="VERBOSE"> Verbose </option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<label for="priority"> Priority </label> <input value="0" id="priority" name="priority">
|
<label for="priority"> Priority </label> <input value="0" id="priority" name="priority">
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -41,6 +41,7 @@
|
|||||||
<tr><td class="td-label">Base Options</td><td>{{test.base_options}}</td></tr>
|
<tr><td class="td-label">Base Options</td><td>{{test.base_options}}</td></tr>
|
||||||
<tr><td class="td-label">Base Time</td><td>{{test.base_time_control}}</td></tr>
|
<tr><td class="td-label">Base Time</td><td>{{test.base_time_control}}</td></tr>
|
||||||
<tr><td class="td-label">Opening Book</td><td><a href="{{test|book_download_link}}">{{test.book_name}}</a></td></tr>
|
<tr><td class="td-label">Opening Book</td><td><a href="{{test|book_download_link}}">{{test.book_name}}</a></td></tr>
|
||||||
|
<tr><td class="td-label">Upload PGNs</td><td>{{test.upload_pgns}}</td></tr>
|
||||||
<tr><td class="td-label">Syzygy WDL</td><td>{{test.syzygy_wdl}}</td></tr>
|
<tr><td class="td-label">Syzygy WDL</td><td>{{test.syzygy_wdl}}</td></tr>
|
||||||
<tr><td class="td-label">Syzygy ADJ.</td><td>{{test.syzygy_adj}}</td></tr>
|
<tr><td class="td-label">Syzygy ADJ.</td><td>{{test.syzygy_adj}}</td></tr>
|
||||||
<tr><td class="td-label">Win ADJ.</td><td>{{test.win_adj}}</td></tr>
|
<tr><td class="td-label">Win ADJ.</td><td>{{test.win_adj}}</td></tr>
|
||||||
|
|||||||
Reference in new issue
Block a user