Upload the PGNs and save them. Last step for that

This commit is contained in:
andrew authored and Andrew Grant committed 2023-12-04 07:57:33 -05:00
1 parent c4e27d393f
commit 5f97fd9e6a
4 files changed
+52 -14

No files matched your search

+25 -13
View File
@@ -262,13 +262,13 @@ class ServerReporter:
## differing payloads. Payloads must always include the machine id, and secret token
@staticmethod
def report(config, endpoint, payload):
def report(config, endpoint, payload, files=None):
payload['machine_id'] = config.machine_id
payload['secret'] = config.secret_token
target = url_join(config.server, endpoint)
response = requests.post(target, data=payload, timeout=TIMEOUT_HTTP)
response = requests.post(target, data=payload, files=files, timeout=TIMEOUT_HTTP)
# Check for a json repsone, to look for Client Version Errors
try: as_json = response.json()
@@ -392,6 +392,24 @@ class ServerReporter:
return ServerReporter.report(config, 'clientHeartbeat', payload)
@staticmethod
def report_pgn(config, compressed_pgn_text):
payload = {
'test_id' : config.workload['test']['id'],
'result_id' : config.workload['result']['id'],
'book_index' : config.workload['test']['book_index'],
'Content-Type' : 'application/octet-stream',
}
files = {
'file' : ('games.pgn', compressed_pgn_text)
}
print (type(compressed_pgn_text))
return ServerReporter.report(config, 'clientSubmitPGN', payload, files)
class Cutechess:
## Handles building the very long string of arguments that need to be passed
@@ -1094,17 +1112,11 @@ 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()
# Upload the PGN if requested
if config.workload['test']['upload_pgns'] != 'FALSE':
compact = config.workload['test']['upload_pgns'] == 'COMPACT'
pgn_files = [Cutechess.pgn_name(config, timestamp, x) for x in range(cutechess_cnt)]
ServerReporter.report_pgn(config, compress_list_of_pgns(pgn_files, compact))
def download_opening_book(config):
+10 -1
View File
@@ -197,4 +197,13 @@ class Network(Model):
return '[{}] {} ({})'.format(self.engine, self.name, self.sha256)
class PGN(Model):
pass
test_id = IntegerField(default=0)
result_id = IntegerField(default=0)
book_index = IntegerField(default=0)
def __str__(self):
return self.filename()
def filename(self):
return '%s.%s.%s.pgn.bz2' % (self.test_id, self.result_id, self.book_index)
+1
View File
@@ -79,6 +79,7 @@ urlpatterns = [
django.urls.path(r'clientSubmitError/', OpenBench.views.client_submit_error),
django.urls.path(r'clientSubmitResults/', OpenBench.views.client_submit_results),
django.urls.path(r'clientHeartbeat/', OpenBench.views.client_heartbeat),
django.urls.path(r'clientSubmitPGN/', OpenBench.views.client_submit_pgn),
# Nice endpoints, which can be hit from the website or with credentials cleanly
django.urls.path(r'api/config/', OpenBench.views.api_configs),
+16
View File
@@ -758,6 +758,22 @@ def client_heartbeat(request, machine):
test = Test.objects.get(id=int(request.POST['test_id']))
return JsonResponse([{}, { 'stop' : True }][test.finished])
@csrf_exempt
@verify_worker
def client_submit_pgn(request, machine):
# Format: test.result.book-index.pgn.bz2
pgn = PGN()
pgn.test_id = int(request.POST['test_id'] )
pgn.result_id = int(request.POST['result_id'] )
pgn.book_index = int(request.POST['book_index'])
pgn.save()
# Save the .pgn.bz2 to /Media/
FileSystemStorage().save(pgn.filename(), ContentFile(request.FILES['file'].read()))
return JsonResponse({})
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #