Cleanup update logic (Django magic), remove |tail, delete db

This commit is contained in:
AndyGrant committed 2018-06-12 20:52:31 -04:00
1 parent 666e7b1a08
commit e814516ee4
5 files changed
+80 -61

No files matched your search

+20 -9
View File
@@ -222,12 +222,12 @@ def singleCoreBench(name, outqueue):
dir = os.path.join('Engines', getNameAsExe(name)) dir = os.path.join('Engines', getNameAsExe(name))
# Last two lines should hold node count and NPS # Last two lines should hold node count and NPS
data = os.popen('{0} bench 13 |tail -2'.format(dir)).read() data = os.popen('{0} bench'.format(dir)).read()
data = data.strip().split('\n') data = data.strip().split('\n')
# Parse and dump results into queue # Parse and dump results into queue
bench = int(data[0].split(':')[1]) bench = int(data[-2].split(':')[1])
nps = int(data[1].split(':')[1]) nps = int(data[-1].split(':')[1])
outqueue.put((bench, nps)) outqueue.put((bench, nps))
def getBenchSignature(engine): def getBenchSignature(engine):
@@ -275,16 +275,19 @@ def reportWrongBench(data, engine):
def reportNPS(data, nps): def reportNPS(data, nps):
# Server wants verification for reporting nps counts # Server wants verification for reporting nps counts
try:
postdata = { postdata = {
'nps' : nps, 'nps' : nps,
'username' : USERNAME, 'username' : USERNAME,
'password' : PASSWORD, 'password' : PASSWORD,
'machineid' : data['machine']['id']} 'machineid' : data['machine']['id']}
return requests.post('{0}/submitNPS/'.format(SERVER), data=postdata).text return requests.post('{0}/submitNPS/'.format(SERVER), data=postdata).text
except: print ('<Warning> Unable to reach server')
def reportResults(data, wins, losses, draws, crashes, timeloss): def reportResults(data, wins, losses, draws, crashes, timeloss):
# Server wants verification for reporting nps counts # Server wants verification for reporting nps counts
try:
postdata = { postdata = {
'wins' : wins, 'wins' : wins,
'losses' : losses, 'losses' : losses,
@@ -297,6 +300,7 @@ def reportResults(data, wins, losses, draws, crashes, timeloss):
'resultid' : data['result']['id'], 'resultid' : data['result']['id'],
'testid' : data['test']['id']} 'testid' : data['test']['id']}
return requests.post('{0}/submitResults/'.format(SERVER), data=postdata).text return requests.post('{0}/submitResults/'.format(SERVER), data=postdata).text
except: print ('<Warning> Unable to reach server')
def completeWorkload(data): def completeWorkload(data):
@@ -359,6 +363,14 @@ def completeWorkload(data):
killProcess(process) killProcess(process)
break break
# Parse engine crashes
if 'disconnects' in line or 'connection stalls' in line:
crashes += 1
# Parse losses on time
if 'on time' in line:
timeloss += 1
# Batch result updates # Batch result updates
if (sum(score) - sum(sent)) % 25 == 0 and score != sent: if (sum(score) - sum(sent)) % 25 == 0 and score != sent:
wins = score[0] - sent[0] wins = score[0] - sent[0]
@@ -392,6 +404,7 @@ if __name__ == '__main__':
while True: while True:
try:
# Request the information for the next workload # Request the information for the next workload
request = requests.post('{0}/getWorkload/'.format(SERVER), data=postdata) request = requests.post('{0}/getWorkload/'.format(SERVER), data=postdata)
@@ -425,11 +438,9 @@ if __name__ == '__main__':
# Update machine id in case ours was bad # Update machine id in case ours was bad
postdata['machineid'] = data['machine']['id'] postdata['machineid'] = data['machine']['id']
# Try to complete the workload, rest for a few # Begin working on the games to be played
# seconds in the event of an error, giving the
# server time to correct the mistake ...
completeWorkload(data) completeWorkload(data)
#except Exception as error: except Exception as error:
# print ('<WARNING> {0}'.format(error)) print ('<ERROR> {0}'.format(str(error)))
time.sleep(15) time.sleep(10)
+41 -31
View File
@@ -1,5 +1,6 @@
import math, requests, random import math, requests, random
from django.db.models import F
from django.contrib.auth import authenticate from django.contrib.auth import authenticate
from OpenBench.config import * from OpenBench.config import *
@@ -204,47 +205,56 @@ def update(request):
draws = int(request.POST['draws']) draws = int(request.POST['draws'])
crashes = int(request.POST['crashes']) crashes = int(request.POST['crashes'])
timeloss = int(request.POST['timeloss']) timeloss = int(request.POST['timeloss'])
games = wins + losses + draws
# Get each model to be updated # Parse the various IDs sent back
profile = Profile.objects.get(user=user) machineid = int(request.POST['machineid'])
machine = Machine.objects.get(id=int(request.POST['machineid'])) resultid = int(request.POST['resultid'])
result = Result.objects.get(id=int(request.POST['resultid'])) testid = int(request.POST['testid'])
test = Test.objects.get(id=int(request.POST['testid']))
# Don't update an finished, deleted, or unappoved test # Don't update an finished, deleted, or unappoved test
test = Test.objects.get(id=testid)
if test.finished or test.deleted or not test.approved: if test.finished or test.deleted or not test.approved:
raise Exception() raise Exception()
# Update Profile # New stats for the test
profile.games += wins + losses + draws elo = ELO(test)
profile.save() sprt = SPRT(test)
passed = sprt > test.upperllr
failed = sprt < test.lowerllr
finished = passed or failed
# Update Machine # Update total # of games played for the User
machine.save() Profile.objects.filter(user=user).update(games=F('games') + games)
# Update Result # Just force an update to Machine.update
result.games += wins + losses + draws Machine.objects.filter(id=machineid).update()
result.wins += wins
result.losses += losses
result.draws += draws
result.crashes += crashes
result.timeloss += timeloss
result.save()
# Update Test # Update for the new results
test.games += wins + losses + draws Result.objects.filter(id=resultid).update(
test.wins += wins games=F('games') + games,
test.losses += losses wins=F('wins') + wins,
test.draws += draws losses=F('losses') + losses,
test.currentllr = SPRT(test) draws=F('draws') + draws,
test.elo = ELO(test) crashes=F('crashes') + crashes,
test.passed = test.currentllr > test.upperllr timeloss=F('timeloss') + timeloss,
test.failed = test.currentllr < test.lowerllr )
test.finished = test.passed or test.failed
test.save()
# Signal back to kill the test # Finally, update test data and flags
if test.finished: raise Exception() Test.objects.filter(id=testid).update(
games=F('games') + games,
wins=F('wins') + wins,
losses=F('losses') + losses,
draws=F('draws') + draws,
currentllr=sprt,
elo=elo,
passed=passed,
failed=failed,
finished=finished
)
# Signal to stop completed tests
if finished: raise Exception()
def ELO(test): def ELO(test):
w = test.wins w = test.wins
+18 -20
View File
@@ -159,8 +159,8 @@ def viewUser(request, username):
def machines(request): def machines(request):
# Build context dictionary for machine template with machines updated within 5 mins # Build context dictionary for machine template with machines updated recently
target = datetime.datetime.utcnow().replace(tzinfo=utc) - datetime.timedelta(minutes=5) target = datetime.datetime.utcnow().replace(tzinfo=utc) - datetime.timedelta(minutes=20)
data = {'machines' : Machine.objects.filter(updated__gte=target)} data = {'machines' : Machine.objects.filter(updated__gte=target)}
return render(request, 'machines.html', data) return render(request, 'machines.html', data)
@@ -228,7 +228,7 @@ def editTest(request, id):
# Log changes to the test settings # Log changes to the test settings
LogEvent.objects.create( LogEvent.objects.create(
data='Edit test {0} ({1}) P={2} TP={3}'.format(str(test), test.id, test.priority, test.throughput), data='Edited test {0} ({1}) P={2} TP={3}'.format(str(test), test.id, test.priority, test.throughput),
author=request.user.username) author=request.user.username)
return HttpResponseRedirect('/index/') return HttpResponseRedirect('/index/')
@@ -306,10 +306,9 @@ def stopTest(request, id):
test.save() test.save()
# Log the test stopping # Log the test stopping
event = LogEvent() LogEvent.objects.create(
event.data = 'Stopped test {0} ({1})'.format(str(test), test.id) data='Stopped test {0} ({1})'.format(str(test), test.id),
event.author = request.user.username author=request.user.username)
event.save()
return HttpResponseRedirect('/index/') return HttpResponseRedirect('/index/')
@@ -333,10 +332,9 @@ def deleteTest(request, id):
test.save() test.save()
# Log the test deltion # Log the test deltion
event = LogEvent() LogEvent.objects.create(
event.data = 'Deleted test {0} ({1})'.format(str(test), test.id) data='Deleted test {0} ({1})'.format(str(test), test.id),
event.author = request.user.username author=request.user.username)
event.save()
return HttpResponseRedirect('/index/') return HttpResponseRedirect('/index/')
@@ -354,10 +352,10 @@ def getFiles(request):
@csrf_exempt @csrf_exempt
def getWorkload(request): def getWorkload(request):
# Attempt to login in user # Verify credentials
try: loginUser(request, authenticate( try: authenticate(
username=request.POST['username'], username=request.POST['username'],
password=request.POST['password'])) password=request.POST['password'])
except: return HttpResponse('Bad Credentials') except: return HttpResponse('Bad Credentials')
# Create or fetch the Machine # Create or fetch the Machine
@@ -382,10 +380,10 @@ def getWorkload(request):
@csrf_exempt @csrf_exempt
def wrongBench(request): def wrongBench(request):
# Attempt to login in user # Verify credentials
try: loginUser(request, authenticate( try: authenticate(
username=request.POST['username'], username=request.POST['username'],
password=request.POST['password'])) password=request.POST['password'])
except: return HttpResponse('Bad Credentials') except: return HttpResponse('Bad Credentials')
try: try:
@@ -411,10 +409,10 @@ def wrongBench(request):
@csrf_exempt @csrf_exempt
def submitNPS(request): def submitNPS(request):
# Attempt to login in user # Verify credentials
try: loginUser(request, authenticate( try: authenticate(
username=request.POST['username'], username=request.POST['username'],
password=request.POST['password'])) password=request.POST['password'])
except: return HttpResponse('Bad Credentials') except: return HttpResponse('Bad Credentials')
# Try to update the NPS for the machine # Try to update the NPS for the machine
+1 -1
View File
@@ -127,7 +127,7 @@
<td>{{result.losses}}</td> <td>{{result.losses}}</td>
<td>{{result.draws}}</td> <td>{{result.draws}}</td>
<td>{{result.crashes}}</td> <td>{{result.crashes}}</td>
<td>{{result.time}}</td> <td>{{result.timeloss}}</td>
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>
BIN
View File
Binary file not shown.