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
+124 -105

No files matched your search

+64 -53
View File
@@ -222,12 +222,12 @@ def singleCoreBench(name, outqueue):
dir = os.path.join('Engines', getNameAsExe(name))
# 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')
# Parse and dump results into queue
bench = int(data[0].split(':')[1])
nps = int(data[1].split(':')[1])
bench = int(data[-2].split(':')[1])
nps = int(data[-1].split(':')[1])
outqueue.put((bench, nps))
def getBenchSignature(engine):
@@ -275,28 +275,32 @@ def reportWrongBench(data, engine):
def reportNPS(data, nps):
# Server wants verification for reporting nps counts
postdata = {
'nps' : nps,
'username' : USERNAME,
'password' : PASSWORD,
'machineid' : data['machine']['id']}
return requests.post('{0}/submitNPS/'.format(SERVER), data=postdata).text
try:
postdata = {
'nps' : nps,
'username' : USERNAME,
'password' : PASSWORD,
'machineid' : data['machine']['id']}
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):
# Server wants verification for reporting nps counts
postdata = {
'wins' : wins,
'losses' : losses,
'draws' : draws,
'crashes' : crashes,
'timeloss' : timeloss,
'username' : USERNAME,
'password' : PASSWORD,
'machineid' : data['machine']['id'],
'resultid' : data['result']['id'],
'testid' : data['test']['id']}
return requests.post('{0}/submitResults/'.format(SERVER), data=postdata).text
try:
postdata = {
'wins' : wins,
'losses' : losses,
'draws' : draws,
'crashes' : crashes,
'timeloss' : timeloss,
'username' : USERNAME,
'password' : PASSWORD,
'machineid' : data['machine']['id'],
'resultid' : data['result']['id'],
'testid' : data['test']['id']}
return requests.post('{0}/submitResults/'.format(SERVER), data=postdata).text
except: print ('<Warning> Unable to reach server')
def completeWorkload(data):
@@ -359,6 +363,14 @@ def completeWorkload(data):
killProcess(process)
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
if (sum(score) - sum(sent)) % 25 == 0 and score != sent:
wins = score[0] - sent[0]
@@ -392,44 +404,43 @@ if __name__ == '__main__':
while True:
# Request the information for the next workload
request = requests.post('{0}/getWorkload/'.format(SERVER), data=postdata)
try:
# Request the information for the next workload
request = requests.post('{0}/getWorkload/'.format(SERVER), data=postdata)
# Response is a dictionary of information, 'None', or an erro
data = request.content.decode('utf-8')
# Response is a dictionary of information, 'None', or an erro
data = request.content.decode('utf-8')
# Server has nothing to run, ask again later
if data == 'None':
print ('<Warning> Server has no workloads for us')
time.sleep(60)
continue
# Server has nothing to run, ask again later
if data == 'None':
print ('<Warning> Server has no workloads for us')
time.sleep(60)
continue
# Server was unable to authenticate us
if data == 'Bad Credentials':
print ('<ERROR> Invalid Login Credentials')
sys.exit()
# Server was unable to authenticate us
if data == 'Bad Credentials':
print ('<ERROR> Invalid Login Credentials')
sys.exit()
# Server might reject our Machine ID
if data == 'Bad Machine':
print ('<ERROR> Bad Machine. Delete machine.txt')
sys.exit()
# Server might reject our Machine ID
if data == 'Bad Machine':
print ('<ERROR> Bad Machine. Delete machine.txt')
sys.exit()
# Convert response into a data dictionary
data = ast.literal_eval(data)
# Convert response into a data dictionary
data = ast.literal_eval(data)
# Update and save our assigned machine ID
postdata['machineid'] = data['machine']['id']
with open('machine.txt', 'w') as fout:
fout.write(str(postdata['machineid']))
# Update and save our assigned machine ID
postdata['machineid'] = data['machine']['id']
with open('machine.txt', 'w') as fout:
fout.write(str(postdata['machineid']))
# Update machine id in case ours was bad
postdata['machineid'] = data['machine']['id']
# Update machine id in case ours was bad
postdata['machineid'] = data['machine']['id']
# Try to complete the workload, rest for a few
# seconds in the event of an error, giving the
# server time to correct the mistake ...
completeWorkload(data)
# Begin working on the games to be played
completeWorkload(data)
#except Exception as error:
# print ('<WARNING> {0}'.format(error))
time.sleep(15)
except Exception as error:
print ('<ERROR> {0}'.format(str(error)))
time.sleep(10)
+41 -31
View File
@@ -1,5 +1,6 @@
import math, requests, random
from django.db.models import F
from django.contrib.auth import authenticate
from OpenBench.config import *
@@ -204,47 +205,56 @@ def update(request):
draws = int(request.POST['draws'])
crashes = int(request.POST['crashes'])
timeloss = int(request.POST['timeloss'])
games = wins + losses + draws
# Get each model to be updated
profile = Profile.objects.get(user=user)
machine = Machine.objects.get(id=int(request.POST['machineid']))
result = Result.objects.get(id=int(request.POST['resultid']))
test = Test.objects.get(id=int(request.POST['testid']))
# Parse the various IDs sent back
machineid = int(request.POST['machineid'])
resultid = int(request.POST['resultid'])
testid = int(request.POST['testid'])
# 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:
raise Exception()
# Update Profile
profile.games += wins + losses + draws
profile.save()
# New stats for the test
elo = ELO(test)
sprt = SPRT(test)
passed = sprt > test.upperllr
failed = sprt < test.lowerllr
finished = passed or failed
# Update Machine
machine.save()
# Update total # of games played for the User
Profile.objects.filter(user=user).update(games=F('games') + games)
# Update Result
result.games += wins + losses + draws
result.wins += wins
result.losses += losses
result.draws += draws
result.crashes += crashes
result.timeloss += timeloss
result.save()
# Just force an update to Machine.update
Machine.objects.filter(id=machineid).update()
# Update Test
test.games += wins + losses + draws
test.wins += wins
test.losses += losses
test.draws += draws
test.currentllr = SPRT(test)
test.elo = ELO(test)
test.passed = test.currentllr > test.upperllr
test.failed = test.currentllr < test.lowerllr
test.finished = test.passed or test.failed
test.save()
# Update for the new results
Result.objects.filter(id=resultid).update(
games=F('games') + games,
wins=F('wins') + wins,
losses=F('losses') + losses,
draws=F('draws') + draws,
crashes=F('crashes') + crashes,
timeloss=F('timeloss') + timeloss,
)
# Signal back to kill the test
if test.finished: raise Exception()
# Finally, update test data and flags
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):
w = test.wins
+18 -20
View File
@@ -159,8 +159,8 @@ def viewUser(request, username):
def machines(request):
# Build context dictionary for machine template with machines updated within 5 mins
target = datetime.datetime.utcnow().replace(tzinfo=utc) - datetime.timedelta(minutes=5)
# Build context dictionary for machine template with machines updated recently
target = datetime.datetime.utcnow().replace(tzinfo=utc) - datetime.timedelta(minutes=20)
data = {'machines' : Machine.objects.filter(updated__gte=target)}
return render(request, 'machines.html', data)
@@ -228,7 +228,7 @@ def editTest(request, id):
# Log changes to the test settings
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)
return HttpResponseRedirect('/index/')
@@ -306,10 +306,9 @@ def stopTest(request, id):
test.save()
# Log the test stopping
event = LogEvent()
event.data = 'Stopped test {0} ({1})'.format(str(test), test.id)
event.author = request.user.username
event.save()
LogEvent.objects.create(
data='Stopped test {0} ({1})'.format(str(test), test.id),
author=request.user.username)
return HttpResponseRedirect('/index/')
@@ -333,10 +332,9 @@ def deleteTest(request, id):
test.save()
# Log the test deltion
event = LogEvent()
event.data = 'Deleted test {0} ({1})'.format(str(test), test.id)
event.author = request.user.username
event.save()
LogEvent.objects.create(
data='Deleted test {0} ({1})'.format(str(test), test.id),
author=request.user.username)
return HttpResponseRedirect('/index/')
@@ -354,10 +352,10 @@ def getFiles(request):
@csrf_exempt
def getWorkload(request):
# Attempt to login in user
try: loginUser(request, authenticate(
# Verify credentials
try: authenticate(
username=request.POST['username'],
password=request.POST['password']))
password=request.POST['password'])
except: return HttpResponse('Bad Credentials')
# Create or fetch the Machine
@@ -382,10 +380,10 @@ def getWorkload(request):
@csrf_exempt
def wrongBench(request):
# Attempt to login in user
try: loginUser(request, authenticate(
# Verify credentials
try: authenticate(
username=request.POST['username'],
password=request.POST['password']))
password=request.POST['password'])
except: return HttpResponse('Bad Credentials')
try:
@@ -411,10 +409,10 @@ def wrongBench(request):
@csrf_exempt
def submitNPS(request):
# Attempt to login in user
try: loginUser(request, authenticate(
# Verify credentials
try: authenticate(
username=request.POST['username'],
password=request.POST['password']))
password=request.POST['password'])
except: return HttpResponse('Bad Credentials')
# Try to update the NPS for the machine
+1 -1
View File
@@ -127,7 +127,7 @@
<td>{{result.losses}}</td>
<td>{{result.draws}}</td>
<td>{{result.crashes}}</td>
<td>{{result.time}}</td>
<td>{{result.timeloss}}</td>
</tr>
{% endfor %}
</table>
BIN
View File
Binary file not shown.