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

+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({})
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #