Update some client hooks. Add clientSubmitError()

This commit is contained in:
Andrew Grant authored and Andrew Grant committed 2020-05-02 17:22:11 -04:00
1 parent 392cb001c7
commit d6a4cb8e6b
3 files changed
+110 -57

No files matched your search

+47 -32
View File
@@ -267,13 +267,13 @@ def getCutechessCommand(arguments, data, nps):
# Options for the Dev Engine # Options for the Dev Engine
devflags = '-engine dir=Engines/ cmd=./{0} proto={1} tc={2}{3} name={4}'.format( devflags = '-engine dir=Engines/ cmd=./{0} proto={1} tc={2}{3} name={4}'.format(
devCommand, data['test']['dev']['protocol'], timecontrol, devoptions, devCommand, data['test']['dev']['protocol'], timecontrol, devoptions,
'{0}-{1}'.format(data['test']['engine'], data['test']['dev']['sha'][:8]) '{0}-{1}'.format(data['test']['engine'], data['test']['dev']['name'])
) )
# Options for the Base Engine # Options for the Base Engine
baseflags = '-engine dir=Engines/ cmd=./{0} proto={1} tc={2}{3} name={4}'.format( baseflags = '-engine dir=Engines/ cmd=./{0} proto={1} tc={2}{3} name={4}'.format(
baseCommand, data['test']['base']['protocol'], timecontrol, baseoptions, baseCommand, data['test']['base']['protocol'], timecontrol, baseoptions,
'{0}-{1}'.format(data['test']['engine'], data['test']['base']['sha'][:8]) '{0}-{1}'.format(data['test']['engine'], data['test']['base']['name'])
) )
# Options for opening selection # Options for opening selection
@@ -446,47 +446,60 @@ def verifyEngine(arguments, data, engine):
# Check for an invalid bench. Signal to the Client and the Server # Check for an invalid bench. Signal to the Client and the Server
if bench != int(engine['bench']): if bench != int(engine['bench']):
reportWrongBenchmark(arguments, data, engine) reportWrongBenchmark(arguments, data, engine, bench)
print ('[ERROR] Invalid Bench. Got {0} Expected {1}'.format(bench, engine['bench'])) raise Exception('Invalid Bench. Got {0} Expected {1}'.format(bench, engine['bench']))
# Return a valid bench or otherwise return None # Return a valid bench or otherwise return None
return nps if bench == int(engine['bench']) else None return nps if bench == int(engine['bench']) else None
def reportWrongBenchmark(arguments, data, engine): def reportWrongBenchmark(arguments, data, engine, bench):
# Server wants user verification, and then information about
# the test that threw the error, and which engine did it
data = { data = {
'username' : arguments.username, 'username' : arguments.username, 'testid' : data['test']['id'],
'password' : arguments.password, 'password' : arguments.password, 'machineid' : data['machine']['id'],
'testid' : data['test']['id'], 'correct' : engine['bench'] , 'wrong' : bench,
'engineid' : engine['id'], 'engine' : engine['name'],
} }
# Hit the server with information about wrong benchmark url = pathjoin(arguments.server, 'clientWrongBench')
url = pathjoin(arguments.server, 'wrongBench') data = requests.post(url, data=data, timeout=HTTP_TIMEOUT).text
return requests.post(url, data=data, timeout=HTTP_TIMEOUT).text if data == 'Bad Machine': raise Exception('Bad Machine')
def reportNodesPerSecond(arguments, data, nps): def reportNodesPerSecond(arguments, data, nps):
# Server wants user verification, and then information about
# nodes per second searched for a specific machine id value
data = { data = {
'username' : arguments.username, 'username' : arguments.username, 'machineid' : data['machine']['id'],
'password' : arguments.password, 'password' : arguments.password, 'nps' : nps,
'machineid' : data['machine']['id'],
'nps' : nps,
} }
# Hit the server with information about nps url = pathjoin(arguments.server, 'clientSubmitNPS')
url = pathjoin(arguments.server, 'submitNPS') data = requests.post(url, data=data, timeout=HTTP_TIMEOUT).text
return requests.post(url, data=data, timeout=HTTP_TIMEOUT).text if data == 'Bad Machine': raise Exception('Bad Machine')
def reportEngineError(arguments, data, line):
pairing = line.split('(')[1].split(')')[0]
white, black = pairing.split(' vs ')
error = line.split('{')[1].rstrip().rstrip('}')
error = error.replace('White', '-'.join(white.split('-')[1:]).rstrip())
error = error.replace('Black', '-'.join(black.split('-')[1:]).rstrip())
data = {
'username' : arguments.username, 'testid' : data['test']['id'],
'password' : arguments.password, 'machineid' : data['machine']['id'],
'error' : error,
}
url = pathjoin(arguments.server, 'clientSubmitError')
data = requests.post(url, data=data, timeout=HTTP_TIMEOUT).text
if data == 'Bad Machine': raise Exception('Bad Machine')
def reportResults(arguments, data, wins, losses, draws, crashes, timelosses): def reportResults(arguments, data, wins, losses, draws, crashes, timelosses):
# Server wants user verification, and then information about the machine,
# the result object, the test, and then the actual updated game results
data = { data = {
'username' : arguments.username, 'wins' : wins, 'username' : arguments.username, 'wins' : wins,
'password' : arguments.password, 'losses' : losses, 'password' : arguments.password, 'losses' : losses,
@@ -495,7 +508,6 @@ def reportResults(arguments, data, wins, losses, draws, crashes, timelosses):
'testid' : data['test']['id'], 'timeloss' : timelosses, 'testid' : data['test']['id'], 'timeloss' : timelosses,
} }
# Hit the server with the updated test results
url = pathjoin(arguments.server, 'submitResults') url = pathjoin(arguments.server, 'submitResults')
try: return requests.post(url, data=data, timeout=HTTP_TIMEOUT).text try: return requests.post(url, data=data, timeout=HTTP_TIMEOUT).text
except KeyboardInterrupt: sys.exit() except KeyboardInterrupt: sys.exit()
@@ -507,6 +519,7 @@ def processCutechess(arguments, data, cutechess, concurrency):
# Tracking for game results # Tracking for game results
crashes = timelosses = 0 crashes = timelosses = 0
score = [0, 0, 0]; sent = [0, 0, 0] score = [0, 0, 0]; sent = [0, 0, 0]
errors = ['on time', 'disconnects', 'connection stalls', 'illegal']
while True: while True:
@@ -515,13 +528,15 @@ def processCutechess(arguments, data, cutechess, concurrency):
if line != '': print(line) if line != '': print(line)
else: cutechess.wait(); return else: cutechess.wait(); return
# Parse engine crashes # Updated timeloss/crash counters
if 'disconnects' in line or 'connection stalls' in line: timelosses += 'on time' in line
crashes += 1 crashes += 'disconnects' in line
crashes += 'connection stalls' in line
# Parse losses on time # Report any engine errors to the server
if 'on time' in line: for error in errors:
timelosses += 1 if error in line:
reportEngineError(arguments, data, line)
# Parse updates to scores # Parse updates to scores
if line.startswith('Score of'): if line.startswith('Score of'):
+3 -2
View File
@@ -53,10 +53,11 @@ urlpatterns = [
django.urls.path(r'clientGetFiles/', OpenBench.views.clientGetFiles), django.urls.path(r'clientGetFiles/', OpenBench.views.clientGetFiles),
django.urls.path(r'clientGetBuildInfo/', OpenBench.views.clientGetBuildInfo), django.urls.path(r'clientGetBuildInfo/', OpenBench.views.clientGetBuildInfo),
django.urls.path(r'clientGetWorkload/', OpenBench.views.clientGetWorkload), django.urls.path(r'clientGetWorkload/', OpenBench.views.clientGetWorkload),
django.urls.path(r'clientWrongBench/', OpenBench.views.clientWrongBench),
django.urls.path(r'clientSubmitNPS/', OpenBench.views.clientSubmitNPS),
django.urls.path(r'clientSubmitError/', OpenBench.views.clientSubmitError),
# Links for the Client to work with the Server (DEAD) # Links for the Client to work with the Server (DEAD)
django.urls.path(r'wrongBench/', OpenBench.views.wrongBench),
django.urls.path(r'submitNPS/', OpenBench.views.submitNPS),
django.urls.path(r'submitResults/', OpenBench.views.submitResults), django.urls.path(r'submitResults/', OpenBench.views.submitResults),
# Redirect anything else to the Index # Redirect anything else to the Index
+60 -23
View File
@@ -452,6 +452,16 @@ def clientGetBuildInfo(request):
@not_minified_response @not_minified_response
def clientGetWorkload(request): def clientGetWorkload(request):
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# #
# POST : Return a Dictionary of data in order to complete a workload. If #
# there are no tests for the User, 'None' will be returned. If we #
# cannot authenticate the User, 'Bad Credentials' is returned. If #
# the posted Machine does not belong the the User, 'Bad Machine' #
# is returned. #
# #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Verify the User's credentials # Verify the User's credentials
user = django.contrib.auth.authenticate( user = django.contrib.auth.authenticate(
username=request.POST['username'], username=request.POST['username'],
@@ -461,56 +471,83 @@ def clientGetWorkload(request):
# getWorkload() will verify the integrity of the request # getWorkload() will verify the integrity of the request
return HttpResponse(OpenBench.utils.getWorkload(user, request)) return HttpResponse(OpenBench.utils.getWorkload(user, request))
@csrf_exempt @csrf_exempt
@not_minified_response @not_minified_response
def wrongBench(request): def clientWrongBench(request):
# Verify that we got a valid login # Verify the User's credentials
user = django.contrib.auth.authenticate( user = django.contrib.auth.authenticate(
username=request.POST['username'], username=request.POST['username'],
password=request.POST['password']) password=request.POST['password'])
if user == None: return HttpResponse('Bad Credentials') if user == None: return HttpResponse('Bad Credentials')
try: # Verify the Machine belongs to the User
# Find the engine with the bad bench machine = Machine.objects.get(id=int(request.POST['machineid']))
engineid = int(request.POST['engineid']) if machine.owner != user.username: return HttpResponse('Bad Machine')
engine = Engine.objects.get(id=engineid)
# Find and stop the test with the bad bench # Find and stop the test with the bad bench
testid = int(request.POST['testid']) test = Test.objects.get(id=int(request.POST['testid']))
test = Test.objects.get(id=testid) test.finished = True; test.save()
test.finished = True
test.save()
# Log the bad bench so we know why the test was stopped # Collect information on the Error
wrong = request.POST['wrong']
correct = request.POST['correct']
name = request.POST['engine']
# Format a nice Error message
message = 'Got {0} Expected {1} for {2}'
message = message.format(wrong, correct, name)
# Log the error into the Events table
LogEvent.objects.create( LogEvent.objects.create(
data='Invalid Bench', test = test,
author=request.POST['username'], data = message,
test=test) author = user.username)
except: pass
return HttpResponse('None') return HttpResponse('None')
@csrf_exempt @csrf_exempt
@not_minified_response @not_minified_response
def submitNPS(request): def clientSubmitNPS(request):
# Verify that we got a valid login # Verify the User's credentials
user = django.contrib.auth.authenticate( user = django.contrib.auth.authenticate(
username=request.POST['username'], username=request.POST['username'],
password=request.POST['password']) password=request.POST['password'])
if user == None: return HttpResponse('Bad Credentials') if user == None: return HttpResponse('Bad Credentials')
# Try to update the NPS for the machine # Verify the Machine belongs to the User
try:
machine = Machine.objects.get(id=int(request.POST['machineid'])) machine = Machine.objects.get(id=int(request.POST['machineid']))
machine.mnps = float(request.POST['nps']) / 1e6 if machine.owner != user.username: return HttpResponse('Bad Machine')
machine.save()
except: return HttpResponse('Bad Machine ID') # Update the NPS and return 'None' to signal no errors
machine.mnps = float(request.POST['nps']) / 1e6; machine.save()
return HttpResponse('None')
@csrf_exempt
@not_minified_response
def clientSubmitError(request):
# Verify the User's credentials
user = django.contrib.auth.authenticate(
username=request.POST['username'],
password=request.POST['password'])
if user == None: return HttpResponse('Bad Credentials')
# Verify the Machine belongs to the User
machine = Machine.objects.get(id=int(request.POST['machineid']))
if machine.owner != user.username: return HttpResponse('Bad Machine')
# Log the Error into the Events table
LogEvent.objects.create(
author = user.username,
data = request.POST['error'],
test = Test.objects.get(id=int(request.POST['testid'])))
return HttpResponse('None') return HttpResponse('None')
@csrf_exempt @csrf_exempt
@not_minified_response @not_minified_response
def submitResults(request): def submitResults(request):