diff --git a/Client/OpenBench.py b/Client/OpenBench.py index 0bf932a..03f74f9 100644 --- a/Client/OpenBench.py +++ b/Client/OpenBench.py @@ -168,22 +168,23 @@ def getCutechessCommand(data, scalefactor): # Find Threads for the Dev Engine tokens = data['test']['dev']['options'].split(' ') - devthreads = tokens[0].split('=')[1] + devthreads = int(tokens[0].split('=')[1]) # Find Threads for the Base Engine tokens = data['test']['base']['options'].split(' ') - basethreads = tokens[0].split('=')[1] + basethreads = int(tokens[0].split('=')[1]) # Finally, output the time control for the user - print ('ORIGINAL :\n', data['test']['timecontrol']), - print ('SCALED :\n', timecontrol) + print ('ORIGINAL :', data['test']['timecontrol']) + print ('SCALED :', timecontrol) + print ('') generalFlags = ( '-repeat' ' -srand ' + str(int(time.time())) + ' -resign movecount=3 score=400' ' -draw movenumber=40 movecount=8 score=10' - ' -concurrency ' + str(floor(THREADS / max(devthreads, basethreads))) + + ' -concurrency ' + str(math.floor(THREADS / max(devthreads, basethreads))) + ' -games 1000' ' -recover' ' -wait 10' @@ -229,7 +230,7 @@ def singleCoreBench(name, outqueue): def getBenchSignature(engine): - print ('Running Benchmark for {0} on {1} cores'.format(engine['name'], THREADS)) + print ('\nRunning Benchmark for {0} on {1} cores'.format(engine['name'], THREADS)) # Allow each process to send back completition times outqueue = multiprocessing.Queue() @@ -261,7 +262,7 @@ def getBenchSignature(engine): def reportWrongBench(data, engine): - # Server wants verification for reporting + # Server wants verification for reporting wrong benchs postdata = { 'username' : USERNAME, 'password' : PASSWORD, @@ -269,6 +270,16 @@ def reportWrongBench(data, engine): 'testid' : data['test']['id']} requests.post('{0}/wrongBench/'.format(SERVER), data=postdata) +def reportNPS(data, nps): + + # Server wants verification for reporting nps counts + postdata = { + 'nps' : nps, + 'username' : USERNAME, + 'password' : PASSWORD, + 'machineid' : data['machine']['id']} + requests.post('{0}/submitNPS/'.format(SERVER), data=postdata) + def reportResults(data, wins, losses, draws, crashes, timeloss): pass @@ -297,6 +308,7 @@ def completeWorkload(data): # Compute and report CPU scaling factor avgnps = (devnps + basenps) / 2.0 + reportNPS(data, avgnps) scalefactor = 2650000 / avgnps print ('FACTOR : {0}'.format(round(1 / scalefactor, 2))) @@ -398,7 +410,8 @@ if __name__ == '__main__': # Try to complete the workload, rest for a few # seconds in the event of an error, giving the # server time to correct the mistake ... - try: completeWorkload(data) - except Exception as error: - print (' {0}'.format(error)) + completeWorkload(data) + + #except Exception as error: + # print (' {0}'.format(error)) time.sleep(15) \ No newline at end of file diff --git a/OpenBench/urls.py b/OpenBench/urls.py index c35d295..3f26127 100644 --- a/OpenBench/urls.py +++ b/OpenBench/urls.py @@ -28,5 +28,6 @@ urlpatterns = [ path(r'getFiles/', OpenBench.views.getFiles), path(r'getWorkload/', OpenBench.views.getWorkload), path(r'wrongBench/', OpenBench.views.wrongBench), + path(r'submitNPS/', OpenBench.views.submitNPS), path(r'submitResults/', OpenBench.views.submitResults), ] diff --git a/OpenBench/utils.py b/OpenBench/utils.py index 0f5eb03..3f1871b 100644 --- a/OpenBench/utils.py +++ b/OpenBench/utils.py @@ -81,7 +81,7 @@ def getMachine(machineid, username, osname, threads): # Client has no saved machine ID, make a new machine if machineid == 'None': - return Machine.objects.create(owner=username, osname=osname, threads=threads) + return Machine.objects.create(owner=username, osname=osname, threads=int(threads)) # Fetch and verify the claimed machine ID machine = Machine.objects.get(id=machineid) @@ -89,7 +89,7 @@ def getMachine(machineid, username, osname, threads): assert machine.osname == osname # Update to reflect new worload - machine.threads = threads + machine.threads = int(threads) machine.mnps = 0.00 machine.save() return machine @@ -102,7 +102,7 @@ def getWorkload(machine): tests = list(tests.filter(approved=True)) # No tests, error out and let views handle it - if len(tests) == 0: raise Exception('ANone') + if len(tests) == 0: raise Exception('None') options = [] # Highest priority with acceptable threads @@ -111,11 +111,11 @@ def getWorkload(machine): # Find Threads for the Dev Engine tokens = test.devoptions.split(' ') - devthreads = tokens[0].split('=')[1] + devthreads = int(tokens[0].split('=')[1]) # Find Threads for the Base Engine tokens = test.baseoptions.split(' ') - basethreads = tokens[0].split('=')[1] + basethreads = int(tokens[0].split('=')[1]) # Minimum threads to support Dev & Base threadcnt = max(devthreads, basethreads) diff --git a/OpenBench/views.py b/OpenBench/views.py index 959f7d6..084ddef 100644 --- a/OpenBench/views.py +++ b/OpenBench/views.py @@ -113,7 +113,7 @@ def index(request, page=0, username=None, error=''): # Get tests pending approval pending = Test.objects.filter(approved=False) - pending = pending.exclude(finished=False) + pending = pending.exclude(finished=True) pending = pending.exclude(deleted=True) pending = pending.order_by('-creation') @@ -383,21 +383,41 @@ def wrongBench(request): password=request.POST['password'])) except: return HttpResponse('Bad Credentials') - # Find the engine with the bad bench - engineid = int(request.POST['engineid']) - engine = Engine.objects.get(id=engineid) + try: + # Find the engine with the bad bench + engineid = int(request.POST['engineid']) + engine = Engine.objects.get(id=engineid) - # Find and stop the test with the bad bench - testid = int(request.POST['testid']) - test = Test.objects.get(id=testid) - test.finished = True - test.save() + # Find and stop the test with the bad bench + testid = int(request.POST['testid']) + test = Test.objects.get(id=testid) + test.finished = True + test.save() - # Log the bad bench so we know why the test was stopped - LogEvent.objects.create( - data='Invalid bench for {0} with {1}'.format(str(test), str(engine)), - author=request.POST['username'] - ) + # Log the bad bench so we know why the test was stopped + LogEvent.objects.create( + data='Invalid bench for {0} with {1}'.format(str(test), str(engine)), + author=request.POST['username'] + ) + except: pass + + return HttpResponse('None') + +@csrf_exempt +def submitNPS(request): + + # Attempt to login in user + try: loginUser(request, authenticate( + username=request.POST['username'], + password=request.POST['password'])) + except: return HttpResponse('Bad Credentials') + + # Try to update the NPS for the machine + try: + machine = Machine.objects.get(id=int(request.POST['machineid'])) + machine.mnps = float(request.POST['nps']) / 1e6 + machine.save() + except: return HttpResponse('Bad Machine ID') return HttpResponse('None') diff --git a/db.sqlite3 b/db.sqlite3 index a3c10fe..340cd4d 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ