Add Create Test
This commit is contained in:
1 parent
8af4b023c4
commit
e8025ecb98
10 files changed
+228
-65
No files matched your search
+16
-17
@@ -1,21 +1,20 @@
|
||||
FRAMEWORK_REPO_URL = "http://github.com/AndyGrant/OpenBench/"
|
||||
FRAMEWORK_REPO_URL = 'http://github.com/AndyGrant/OpenBench/'
|
||||
|
||||
FRAMEWORK_DEFAULTS = {
|
||||
"config" : {
|
||||
|
||||
"source" : "http://github.com/AndyGrant/EtherealDev/",
|
||||
"homepage" : "http://github.com/AndyGrant/Ethereal",
|
||||
"framework" : "http://github.com/AndyGrant/OpenBench/",
|
||||
|
||||
"protocol" : "uci",
|
||||
"engine" : "Ethereal",
|
||||
|
||||
"alpha" : .10,
|
||||
"beta" : .10,
|
||||
"elower" : 0,
|
||||
"eupper" : 5,
|
||||
"hashsize" : 8,
|
||||
"threads" : 1,
|
||||
"timecontrol" : "5.0+0.05"
|
||||
'config' : {
|
||||
'source' : 'http://github.com/AndyGrant/EtherealDev/',
|
||||
'homepage' : 'http://github.com/AndyGrant/Ethereal',
|
||||
'framework' : 'http://github.com/AndyGrant/OpenBench/',
|
||||
'engine' : 'Ethereal',
|
||||
'timecontrol' : '5.0+0.05',
|
||||
'hash' : 8,
|
||||
'threads' : 1,
|
||||
'protocol' : 'uci',
|
||||
'elolower' : 0.0,
|
||||
'eloupper' : 5.0,
|
||||
'alpha' : 0.10,
|
||||
'beta' : 0.10,
|
||||
'threads' : 1,
|
||||
'bookname' : '2moves_v1.pgn',
|
||||
}
|
||||
}
|
||||
+7
-11
@@ -14,11 +14,11 @@ class LogEvent(Model):
|
||||
|
||||
class Engine(Model):
|
||||
|
||||
name = CharField(max_length=128)
|
||||
source = CharField(max_length=1024)
|
||||
proto = CharField(max_length=16)
|
||||
sha = CharField(max_length=64)
|
||||
bench = IntegerField(default=0)
|
||||
name = CharField(max_length=128)
|
||||
source = CharField(max_length=1024)
|
||||
protocol = CharField(max_length=16)
|
||||
sha = CharField(max_length=64)
|
||||
bench = IntegerField(default=0)
|
||||
|
||||
def __str__(self):
|
||||
return '{0} ({1})'.format(self.name, self.bench)
|
||||
@@ -37,7 +37,6 @@ class Machine(Model):
|
||||
|
||||
owner = CharField(max_length=64)
|
||||
osname = CharField(max_length=128)
|
||||
|
||||
cores = IntegerField(default=0)
|
||||
mnps = FloatField(default=0.00)
|
||||
lastseen = DateTimeField(auto_now=True)
|
||||
@@ -49,7 +48,6 @@ class Results(Model):
|
||||
|
||||
test = ForeignKey('Test', PROTECT, related_name='test')
|
||||
machine = ForeignKey('Machine', PROTECT, related_name='machine')
|
||||
|
||||
games = IntegerField(default=0)
|
||||
wins = IntegerField(default=0)
|
||||
losses = IntegerField(default=0)
|
||||
@@ -71,16 +69,14 @@ class Test(Model):
|
||||
|
||||
bookname = CharField(max_length=32)
|
||||
timecontrol = CharField(max_length=16)
|
||||
hashsize = IntegerField(default=1)
|
||||
threads = IntegerField(default=1)
|
||||
|
||||
priority = IntegerField(default=0)
|
||||
throughput = IntegerField(default=0)
|
||||
|
||||
alpha = FloatField(default=0.0)
|
||||
beta = FloatField(default=0.0)
|
||||
elolower = FloatField(default=0.0)
|
||||
eloupper = FloatField(default=0.0)
|
||||
alpha = FloatField(default=0.0)
|
||||
beta = FloatField(default=0.0)
|
||||
|
||||
lowerllr = FloatField(default=0.0)
|
||||
currentllr = FloatField(default=0.0)
|
||||
|
||||
@@ -17,7 +17,7 @@ body {
|
||||
width: auto;
|
||||
}
|
||||
|
||||
#errormessagebar {
|
||||
#error {
|
||||
background-color: RED;
|
||||
padding: 8px;
|
||||
text-align: center;
|
||||
@@ -130,7 +130,7 @@ input[type=submit]:hover {
|
||||
|
||||
label, option {
|
||||
display: inline-block;
|
||||
width: 140px;
|
||||
width: 180px;
|
||||
font-weight:bold;
|
||||
vertical-align: middle;
|
||||
}
|
||||
@@ -40,7 +40,7 @@ def gitDiffLink(test):
|
||||
|
||||
repo = "/".join(dev.split("/")[:-2])
|
||||
|
||||
return "{0}/compare/{1}...{2}".format(repo, basesha[:8], testsha[:8])
|
||||
return "{0}/compare/{1}...{2}".format(repo, basesha[:8], devsha[:8])
|
||||
|
||||
register = template.Library()
|
||||
register.filter("oneDigitPrecision", oneDigitPrecision)
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
from OpenBench.models import Engine, Test
|
||||
|
||||
import math, requests
|
||||
|
||||
def getSourceLocation(branch, repo):
|
||||
|
||||
try:
|
||||
target = repo.replace('github.com', 'api.github.com/repos')
|
||||
target = target + 'branches/' + branch
|
||||
data = requests.get(target).json()
|
||||
source = repo + 'archive/' + data['commit']['commit']['tree']['sha'] + '.zip'
|
||||
sha = data['commit']['sha']
|
||||
return (sha, source)
|
||||
|
||||
except:
|
||||
raise Exception('Unable to find branch ({0})'.format(branch))
|
||||
|
||||
def newEngine(name, source, protocol, sha, bench):
|
||||
|
||||
# Engine may already exist, which is okay
|
||||
try: return Engine.objects.get(sha=sha)
|
||||
except: pass
|
||||
|
||||
# Build new Engine
|
||||
engine = Engine()
|
||||
engine.name = name
|
||||
engine.source = source
|
||||
engine.protocol = protocol
|
||||
engine.sha = sha
|
||||
engine.bench = bench
|
||||
engine.save()
|
||||
return engine
|
||||
|
||||
def newTest(request):
|
||||
|
||||
test = Test() # New Test, saved only after parsing
|
||||
|
||||
# Extract Development Fields
|
||||
devname = request.POST['devbranch']
|
||||
devbench = int(request.POST['devbench'])
|
||||
devprotocol = request.POST['devprotocol']
|
||||
|
||||
# Extract Base Fields
|
||||
basename = request.POST['basebranch']
|
||||
basebench = int(request.POST['basebench'])
|
||||
baseprotocol = request.POST['baseprotocol']
|
||||
|
||||
# Extract test configuration
|
||||
test.devoptions = request.POST['devoptions']
|
||||
test.baseoptions = request.POST['baseoptions']
|
||||
test.bookname = request.POST['bookname']
|
||||
test.timecontrol = request.POST['timecontrol']
|
||||
test.priority = int(request.POST['priority'])
|
||||
test.throughput = int(request.POST['throughput'])
|
||||
test.elolower = float(request.POST['elolower'])
|
||||
test.eloupper = float(request.POST['eloupper'])
|
||||
test.alpha = float(request.POST['alpha'])
|
||||
test.beta = float(request.POST['beta'])
|
||||
|
||||
# Compute LLR cutoffs
|
||||
test.lowerllr = math.log(test.beta / (1.0 - test.alpha))
|
||||
test.upperllr = math.log((1.0 - test.beta) / test.alpha)
|
||||
|
||||
# Build or fetch the Development version
|
||||
devsha, devsource = getSourceLocation(devname, request.POST['source'])
|
||||
test.dev = newEngine(devname, devsource, devprotocol, devsha, devbench)
|
||||
|
||||
# Build or fetch the Base version
|
||||
basesha, basesource = getSourceLocation(basename, request.POST['source'])
|
||||
test.base = newEngine(basename, basesource, baseprotocol, basesha, basebench)
|
||||
|
||||
# Nothing seems to have gone wrong
|
||||
test.save()
|
||||
return test
|
||||
+58
-33
@@ -1,17 +1,18 @@
|
||||
from django.shortcuts import render as djangoRender
|
||||
|
||||
from django.http import HttpResponse, HttpResponseRedirect
|
||||
|
||||
from django.contrib.auth import authenticate
|
||||
from django.contrib.auth import login as loginUser
|
||||
from django.contrib.auth import logout as logoutUser
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib.admin.views.decorators import staff_member_required
|
||||
|
||||
from OpenBench.config import *
|
||||
|
||||
from OpenBench.models import LogEvent, Engine, Profile
|
||||
from OpenBench.models import Machine, Results, Test
|
||||
|
||||
import OpenBench.utils
|
||||
|
||||
# Wrap django.shortcuts.render to add framework settings
|
||||
def render(request, template, data):
|
||||
data.update(FRAMEWORK_DEFAULTS)
|
||||
@@ -23,28 +24,34 @@ def register(request):
|
||||
if request.method == 'GET':
|
||||
return render(request, 'register.html', {})
|
||||
|
||||
# Attempt to create and login the new user
|
||||
user = User.objects.create_user(
|
||||
request.POST['username'],
|
||||
request.POST['email'],
|
||||
request.POST['password']
|
||||
)
|
||||
try:
|
||||
# Attempt to create and login the new user
|
||||
user = User.objects.create_user(
|
||||
request.POST['username'],
|
||||
request.POST['email'],
|
||||
request.POST['password']
|
||||
)
|
||||
|
||||
# Login the user and return to index
|
||||
user.save()
|
||||
loginUser(request, user)
|
||||
# Login the user and return to index
|
||||
user.save()
|
||||
loginUser(request, user)
|
||||
|
||||
# Wrap the User in a Profile
|
||||
profile = Profile()
|
||||
profile.user = user
|
||||
profile.save()
|
||||
# Wrap the User in a Profile
|
||||
profile = Profile()
|
||||
profile.user = user
|
||||
profile.save()
|
||||
|
||||
# Log the registration
|
||||
event = LogEvent()
|
||||
event.data = 'Created user {0}'.format(request.POST['username'])
|
||||
event.save()
|
||||
# Log the registration
|
||||
event = LogEvent()
|
||||
event.data = 'Created user {0}'.format(request.POST['username'])
|
||||
event.save()
|
||||
|
||||
return HttpResponseRedirect('/index/')
|
||||
# Kick back to index
|
||||
return HttpResponseRedirect('/index/')
|
||||
|
||||
# Bad data, kick back to index with error
|
||||
except Exception as error:
|
||||
return index(request, error=str(error))
|
||||
|
||||
def login(request):
|
||||
|
||||
@@ -52,10 +59,15 @@ def login(request):
|
||||
if request.method == 'GET':
|
||||
return render(request, 'login.html', {})
|
||||
|
||||
# Attempt to login the user, and return to index
|
||||
user = authenticate(username=request.POST['username'], password=request.POST['password'])
|
||||
loginUser(request, user)
|
||||
return HttpResponseRedirect('/index/')
|
||||
try:
|
||||
# Attempt to login the user, and return to index
|
||||
user = authenticate(username=request.POST['username'], password=request.POST['password'])
|
||||
loginUser(request, user)
|
||||
return HttpResponseRedirect('/index/')
|
||||
|
||||
# Bad data, kick back to index with error
|
||||
except Exception as error:
|
||||
return index(request, error=str(error))
|
||||
|
||||
def logout(request):
|
||||
|
||||
@@ -63,7 +75,7 @@ def logout(request):
|
||||
logoutUser(request)
|
||||
return HttpResponseRedirect('/index/')
|
||||
|
||||
def index(request, page=0):
|
||||
def index(request, page=0, error=''):
|
||||
|
||||
# Get tests pending approval
|
||||
pending = Test.objects.filter(approved=False)
|
||||
@@ -82,20 +94,19 @@ def index(request, page=0):
|
||||
completed = completed.exclude(deleted=True)
|
||||
completed = completed.order_by('completion')
|
||||
|
||||
# Get machines currently active workloads
|
||||
# machines = Machine.objects.get()
|
||||
# machines = Machines played within last <minutes>
|
||||
# Save my @nitrocan @defenchess
|
||||
|
||||
# Compile context dictionary
|
||||
data = {
|
||||
'pending' : pending,
|
||||
'active' : active,
|
||||
'completed' : completed,
|
||||
'error' : error,
|
||||
}
|
||||
|
||||
return render(request, 'index.html', data)
|
||||
|
||||
def users(request):
|
||||
|
||||
# Build context dictionary for template
|
||||
profiles = Profile.objects.all()
|
||||
data = {'profiles' : Profile.objects.all()}
|
||||
return render(request, 'users.html', data)
|
||||
@@ -111,18 +122,32 @@ def eventLog(request):
|
||||
data['events'].append({
|
||||
'data' : event.data,
|
||||
'creation' : event.creation})
|
||||
|
||||
return render(request, 'eventLog.html', data)
|
||||
|
||||
@login_required
|
||||
def newTest(request):
|
||||
pass
|
||||
|
||||
# User trying to view the new test page
|
||||
if request.method == 'GET':
|
||||
return render(request, 'newTest.html', {"user" : request.user})
|
||||
|
||||
try:
|
||||
# Create test and verify fields
|
||||
OpenBench.utils.newTest(request)
|
||||
return HttpResponseRedirect('/index/')
|
||||
|
||||
# Bad data, kick back to index with error
|
||||
except Exception as error:
|
||||
return index(request, error=str(error))
|
||||
|
||||
@staff_member_required
|
||||
def editTest(request, id):
|
||||
pass
|
||||
|
||||
def viewTest(request, id):
|
||||
pass
|
||||
|
||||
@staff_member_required
|
||||
def approveTest(request, id):
|
||||
pass
|
||||
|
||||
|
||||
Reference in new issue
Block a user