Cleaning + fix some date time django magic
This commit is contained in:
1 parent
36d73bacbe
commit
841d634e08
5 files changed
+56
-75
No files matched your search
+2
-2
@@ -1,9 +1,9 @@
|
||||
from django.contrib import admin
|
||||
from OpenBench.models import LogEvent, Engine, Profile, Machine, Results, Test
|
||||
from OpenBench.models import LogEvent, Engine, Profile, Machine, Result, Test
|
||||
|
||||
admin.site.register(LogEvent)
|
||||
admin.site.register(Engine)
|
||||
admin.site.register(Profile)
|
||||
admin.site.register(Machine)
|
||||
admin.site.register(Results)
|
||||
admin.site.register(Result)
|
||||
admin.site.register(Test)
|
||||
+6
-6
@@ -8,7 +8,7 @@ class LogEvent(Model):
|
||||
|
||||
data = CharField(max_length=256)
|
||||
author = CharField(max_length=64)
|
||||
creation = DateTimeField(auto_now=True)
|
||||
creation = DateTimeField(auto_now_add=True)
|
||||
|
||||
def __str__(self):
|
||||
return "{0} {1} : {2}".format(self.creation, self.author, self.data)
|
||||
@@ -42,12 +42,12 @@ class Machine(Model):
|
||||
osname = CharField(max_length=128)
|
||||
threads = IntegerField(default=0)
|
||||
mnps = FloatField(default=0.00)
|
||||
lastseen = DateTimeField(auto_now=True)
|
||||
updated = DateTimeField(auto_now=True)
|
||||
|
||||
def __str__(self):
|
||||
return '{0}-{1} ({2})'.format(self.owner, self.osname, self.id)
|
||||
|
||||
class Results(Model):
|
||||
class Result(Model):
|
||||
|
||||
test = ForeignKey('Test', PROTECT, related_name='test')
|
||||
machine = ForeignKey('Machine', PROTECT, related_name='machine')
|
||||
@@ -57,7 +57,7 @@ class Results(Model):
|
||||
draws = IntegerField(default=0)
|
||||
crashes = IntegerField(default=0)
|
||||
time = IntegerField(default=0)
|
||||
lastseen = DateTimeField(default=0)
|
||||
updated = DateTimeField(auto_now=True)
|
||||
|
||||
def __str__(self):
|
||||
return '{0} {1}'.format(self.test.dev.name, self.machine.__str__())
|
||||
@@ -100,8 +100,8 @@ class Test(Model):
|
||||
deleted = BooleanField(default=False)
|
||||
approved = BooleanField(default=False)
|
||||
|
||||
creation = DateTimeField(auto_now=True)
|
||||
completion = DateTimeField(auto_now=True)
|
||||
creation = DateTimeField(auto_now_add=True)
|
||||
updated = DateTimeField(auto_now=True)
|
||||
|
||||
def __str__(self):
|
||||
return '{0} vs {1} @ {2}'.format(self.dev.name, self.base.name, self.timecontrol)
|
||||
+30
-35
@@ -15,22 +15,6 @@ def getSourceLocation(branch, repo):
|
||||
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
|
||||
@@ -65,11 +49,11 @@ def newTest(request):
|
||||
|
||||
# Build or fetch the Development version
|
||||
devsha, devsource = getSourceLocation(devname, test.source)
|
||||
test.dev = newEngine(devname, devsource, devprotocol, devsha, devbench)
|
||||
test.dev = getEngine(devname, devsource, devprotocol, devsha, devbench)
|
||||
|
||||
# Build or fetch the Base version
|
||||
basesha, basesource = getSourceLocation(basename, test.source)
|
||||
test.base = newEngine(basename, basesource, baseprotocol, basesha, basebench)
|
||||
test.base = getEngine(basename, basesource, baseprotocol, basesha, basebench)
|
||||
|
||||
# Track # of tests by this user
|
||||
profile = Profile.objects.get(user=request.user)
|
||||
@@ -80,22 +64,29 @@ def newTest(request):
|
||||
test.save()
|
||||
return test
|
||||
|
||||
def getEngine(name, source, protocol, sha, bench):
|
||||
|
||||
# Engine may already exist, which is okay
|
||||
try: return Engine.objects.get(sha=sha)
|
||||
except: pass
|
||||
|
||||
# Build new Engine
|
||||
return Engine.objects.create(
|
||||
name=name, source=source,
|
||||
protocol=protocol, sha=sha, bench=bench)
|
||||
|
||||
def getMachine(machineid, username, osname, threads):
|
||||
|
||||
# Machine does not exist, make a new one
|
||||
# Client has no saved machine ID, make a new machine
|
||||
if machineid == 'None':
|
||||
machine = Machine()
|
||||
machine.owner = username
|
||||
machine.osname = osname
|
||||
machine.threads = threads
|
||||
machine.mnps = 0.00
|
||||
machine.save()
|
||||
return machine
|
||||
return Machine.objects.create(owner=username, osname=osname, threads=threads)
|
||||
|
||||
# Verify the selected machine is the user's
|
||||
# Fetch and verify the claimed machine ID
|
||||
machine = Machine.objects.get(id=machineid)
|
||||
assert machine.owner == username
|
||||
assert machine.osname == osname
|
||||
|
||||
# Update to reflect new worload
|
||||
machine.threads = threads
|
||||
machine.mnps = 0.00
|
||||
machine.save()
|
||||
@@ -124,7 +115,7 @@ def getWorkload(machine):
|
||||
tokens = test.baseoptions.split(' ')
|
||||
basethreads = tokens[0].split('=')[1]
|
||||
|
||||
# Machines need at to support Dev & Base
|
||||
# Minimum threads to support Dev & Base
|
||||
threadcnt = max(devthreads, basethreads)
|
||||
|
||||
# Empty list or higher priority found for workable test
|
||||
@@ -152,24 +143,28 @@ def getWorkload(machine):
|
||||
options = options[1:]
|
||||
|
||||
def getResults(machine, test):
|
||||
pass
|
||||
|
||||
def workloadDictionary(profile, machine, result, test):
|
||||
|
||||
# Can find an existing result by test and machine
|
||||
results = Result.objects.filter(test=test)
|
||||
results = list(Result.objects.filter(machine=machine))
|
||||
|
||||
|
||||
|
||||
def workloadDictionary(machine, result, test):
|
||||
|
||||
# Worker will send back the id of each model for ease of
|
||||
# updating. Worker needs test information, as well as the
|
||||
# specification for both engines. Group the dev and base
|
||||
# options with the coressponding engine, for easy usage
|
||||
return {
|
||||
'profile' : { 'id' : profile.id, },
|
||||
'machine' : { 'id' : machine.id, },
|
||||
'result' : { 'id' : result.id, },
|
||||
'result' : { 'id' : result.id, },
|
||||
'test' : {
|
||||
'id' : test.id,
|
||||
'bookname' : test.bookname,
|
||||
'booksource' : FRAMEWORK_REPO_URL + '/raw/master/Books/'
|
||||
'booksource' : FRAMEWORK_REPO_URL + '/raw/master/Books/',
|
||||
'timecontrol' : test.timecontrol,
|
||||
'dev' : {
|
||||
'dev' : {
|
||||
'name' : test.dev.name,
|
||||
'source' : test.dev.source,
|
||||
'protocol' : test.dev.protocol,
|
||||
|
||||
+18
-32
@@ -10,7 +10,7 @@ from django.views.decorators.csrf import csrf_exempt
|
||||
|
||||
from OpenBench.config import *
|
||||
from OpenBench.models import LogEvent, Engine, Profile
|
||||
from OpenBench.models import Machine, Results, Test
|
||||
from OpenBench.models import Machine, Result, Test
|
||||
|
||||
import OpenBench.utils
|
||||
|
||||
@@ -34,26 +34,20 @@ def register(request):
|
||||
if not request.POST['username'].isalnum():
|
||||
raise Exception('Alpha Numeric Usernames Only')
|
||||
|
||||
# Attempt to create and login the new user
|
||||
user = User.objects.create_user(
|
||||
request.POST['username'],
|
||||
request.POST['email'],
|
||||
request.POST['password1']
|
||||
)
|
||||
# Create new User and Profile
|
||||
Profile.objects.create(
|
||||
user=User.objects.create_user(
|
||||
request.POST['username'],
|
||||
request.POST['email'],
|
||||
request.POST['password1']))
|
||||
|
||||
# Save and log the user in
|
||||
user.save(); loginUser(request, user)
|
||||
|
||||
# Wrap the User in a Profile
|
||||
profile = Profile()
|
||||
profile.user = user
|
||||
profile.save()
|
||||
# Log the User in now
|
||||
loginUser(request, User.objects.get(name=request.POST['username']))
|
||||
|
||||
# Log the registration
|
||||
event = LogEvent()
|
||||
event.data = 'Created an account'
|
||||
event.author = request.POST['username']
|
||||
event.save()
|
||||
LogEvent.objects.create(
|
||||
data='Created an account',
|
||||
author=request.POST['username'])
|
||||
|
||||
# Kick back to index
|
||||
return HttpResponseRedirect('/index/')
|
||||
@@ -185,10 +179,9 @@ def newTest(request):
|
||||
test = OpenBench.utils.newTest(request)
|
||||
|
||||
# Log the test creation
|
||||
event = LogEvent()
|
||||
event.data = 'Created test {0} ({1})'.format(str(test), test.id)
|
||||
event.author = request.user.username
|
||||
event.save()
|
||||
LogEvent.objects.create(
|
||||
data='Created test {0} ({1})'.format(str(test), test.id),
|
||||
author=request.user.username)
|
||||
|
||||
return HttpResponseRedirect('/index/')
|
||||
|
||||
@@ -201,7 +194,7 @@ def viewTest(request, id):
|
||||
try:
|
||||
# Find Test and Results
|
||||
test = Test.objects.get(id=id)
|
||||
results = Results.objects.all().filter(test=test)
|
||||
results = Result.objects.all().filter(test=test)
|
||||
data = {'test' : test, 'results' : results}
|
||||
return render(request, 'viewTest.html', data)
|
||||
|
||||
@@ -377,15 +370,8 @@ def getWorkload(request):
|
||||
try: results = OpenBench.utils.getResults(machine, test)
|
||||
except: return HttpResponse('None')
|
||||
|
||||
# Convert everything for the Client
|
||||
data = {
|
||||
"machine" : machine.dictionary(),
|
||||
"test" : test.dictionary(),
|
||||
"result" : results.dictionary()
|
||||
}
|
||||
|
||||
# Send context as a string0
|
||||
return HttpResponse(str(data))
|
||||
# Send ID's and test information as a string dictionary
|
||||
return HttpResponse(str(workloadDictionary(machine, result, test)))
|
||||
|
||||
@csrf_exempt
|
||||
def submitResults(request):
|
||||
|
||||
BIN
Binary file not shown.
Reference in new issue
Block a user