Working progress
This commit is contained in:
1 parent
0556bf7618
commit
dd0f2ca29f
29 files changed
+377
-169
No files matched your search
@@ -2,7 +2,7 @@ import django.apps
|
||||
import threading, time
|
||||
import OpenBench.utils
|
||||
|
||||
from django.core.management.commands.runserver import BaseRunserverCommand
|
||||
from django.core.management.commands.runserver import Command as BaseRunserverCommand
|
||||
|
||||
class ArtifactWatcher(threading.Thread):
|
||||
|
||||
|
||||
+4
-5
@@ -19,7 +19,7 @@
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
|
||||
from django.db.models import CharField, IntegerField, BooleanField, FloatField
|
||||
from django.db.models import ForeignKey, DateTimeField, OneToOneField
|
||||
from django.db.models import JSONField, ForeignKey, DateTimeField, OneToOneField
|
||||
from django.db.models import CASCADE, PROTECT, Model
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
@@ -50,15 +50,14 @@ class Profile(Model):
|
||||
class Machine(Model):
|
||||
|
||||
user = ForeignKey(User, PROTECT, related_name='owner')
|
||||
osname = CharField(max_length=128)
|
||||
threads = IntegerField(default=0)
|
||||
mnps = FloatField(default=0.00)
|
||||
updated = DateTimeField(auto_now=True)
|
||||
lastaddr = CharField(max_length=64, default='None')
|
||||
secret = CharField(max_length=64, default='None')
|
||||
info = JSONField()
|
||||
workload = ForeignKey('Test', PROTECT, related_name='workload', default=1)
|
||||
|
||||
def __str__(self):
|
||||
return '{0}-{1} ({2})'.format(self.user.username, self.osname, self.id)
|
||||
return '[%d] %s' % (self.id, self.user.username)
|
||||
|
||||
class Result(Model):
|
||||
|
||||
|
||||
@@ -288,4 +288,11 @@ body, html, main{
|
||||
|
||||
|
||||
|
||||
/* ??? */
|
||||
|
||||
td pre {
|
||||
margin: 0px;
|
||||
padding: 0px;
|
||||
}
|
||||
|
||||
|
||||
@@ -168,6 +168,37 @@ def testIdToPrettyName(test_id):
|
||||
def testIdToTimeControl(test_id):
|
||||
return OpenBench.models.Test.objects.get(id=test_id).timecontrol
|
||||
|
||||
def cpuflagsBlock(machine, N=8):
|
||||
|
||||
|
||||
reported = []
|
||||
flags = machine.info['cpu_flags']
|
||||
|
||||
general_flags = ['BMI2', 'POPCNT']
|
||||
broad_avx_flags = ['AVX2', 'AVX', 'SSE4_2', 'SSE4_1', 'SSSE3']
|
||||
|
||||
for flag in general_flags:
|
||||
if flag in flags:
|
||||
reported.append(flag)
|
||||
break
|
||||
|
||||
for flag in broad_avx_flags:
|
||||
if flag in flags:
|
||||
reported.append(flag)
|
||||
break
|
||||
|
||||
for flag in flags:
|
||||
if flag not in general_flags and flag not in broad_avx_flags:
|
||||
reported.append(flag)
|
||||
|
||||
return ' '.join(reported)
|
||||
|
||||
def compilerBlock(machine):
|
||||
string = ''
|
||||
for engine, info in machine.info['compilers'].items():
|
||||
string += '%-16s %-8s (%s)\n' % (engine, info[0], info[1])
|
||||
return string
|
||||
|
||||
register = django.template.Library()
|
||||
register.filter('oneDigitPrecision', oneDigitPrecision)
|
||||
register.filter('twoDigitPrecision', twoDigitPrecision)
|
||||
@@ -183,3 +214,5 @@ register.filter('testIsFRC', testIsFRC)
|
||||
register.filter('resolveNetworkURL', resolveNetworkURL)
|
||||
register.filter('testIdToPrettyName', testIdToPrettyName)
|
||||
register.filter('testIdToTimeControl', testIdToTimeControl)
|
||||
register.filter('cpuflagsBlock', cpuflagsBlock)
|
||||
register.filter('compilerBlock', compilerBlock)
|
||||
+3
-1
@@ -43,6 +43,7 @@ urlpatterns = [
|
||||
django.urls.path(r'events/', OpenBench.views.events),
|
||||
django.urls.path(r'events/<int:page>/', OpenBench.views.events),
|
||||
django.urls.path(r'machines/', OpenBench.views.machines),
|
||||
django.urls.path(r'machines/<int:machineid>/', OpenBench.views.machines),
|
||||
|
||||
# Links for viewing and managing tests (maintain Legacy)
|
||||
django.urls.path(r'test/<int:id>/', OpenBench.views.test),
|
||||
@@ -61,6 +62,7 @@ urlpatterns = [
|
||||
# Links for the Client to work with the Server
|
||||
django.urls.path(r'clientGetFiles/', OpenBench.views.clientGetFiles),
|
||||
django.urls.path(r'clientGetBuildInfo/', OpenBench.views.clientGetBuildInfo),
|
||||
django.urls.path(r'clientWorkerInfo/', OpenBench.views.clientWorkerInfo),
|
||||
django.urls.path(r'clientGetWorkload/', OpenBench.views.clientGetWorkload),
|
||||
django.urls.path(r'clientGetNetwork/<str:sha256>/', OpenBench.views.clientGetNetwork),
|
||||
django.urls.path(r'clientWrongBench/', OpenBench.views.clientWrongBench),
|
||||
@@ -71,6 +73,6 @@ urlpatterns = [
|
||||
# Redirect anything else to the Index
|
||||
django.urls.path(r'', OpenBench.views.index),
|
||||
|
||||
# Link for Ethereal 13.00 PRO Sales
|
||||
# Link for Ethereal Sales
|
||||
django.urls.path(r'Ethereal/', OpenBench.views.buyEthereal),
|
||||
]
|
||||
+23
-2
@@ -116,8 +116,8 @@ def getMachineStatus(username=None):
|
||||
machines = machines.filter(user__username=username)
|
||||
|
||||
return ": {0} Machines / ".format(len(machines)) + \
|
||||
"{0} Threads / ".format(sum([f.threads for f in machines])) + \
|
||||
"{0} MNPS ".format(round(sum([f.threads * f.mnps for f in machines]), 2))
|
||||
"{0} Threads / ".format(sum([f.info['concurrency'] for f in machines])) + \
|
||||
"{0} MNPS ".format(round(sum([f.info['concurrency'] * f.mnps for f in machines]), 2))
|
||||
|
||||
def getPaging(content, page, url, pagelen=25):
|
||||
|
||||
@@ -404,6 +404,27 @@ def createNewTest(request):
|
||||
return test, None
|
||||
|
||||
|
||||
def get_machine(machineid, user, info):
|
||||
|
||||
# Create a new machine if we don't have an id
|
||||
if machineid == 'None':
|
||||
return Machine(user=user, info=info)
|
||||
|
||||
# Fetch the requested machine, which hopefully exists
|
||||
try: machine = Machine.objects.get(id=int(machineid))
|
||||
except: return None
|
||||
|
||||
# Workload requests should always contain a MAC
|
||||
if 'mac_address' not in machine.info:
|
||||
return None
|
||||
|
||||
# Soft-verify by checking if the MAC addresses match
|
||||
if machine.info['mac_address'] != info['mac_address']:
|
||||
return None
|
||||
|
||||
return machine
|
||||
|
||||
|
||||
def getMachine(machineid, user, osname, threads):
|
||||
|
||||
# Create a new Machine if needed
|
||||
|
||||
+39
-17
@@ -18,7 +18,7 @@
|
||||
# #
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
|
||||
import os, hashlib, mimetypes, datetime, json, random
|
||||
import os, hashlib, datetime, json, secrets
|
||||
|
||||
import django.http
|
||||
import django.shortcuts
|
||||
@@ -34,7 +34,7 @@ from OpenSite.settings import MEDIA_ROOT
|
||||
from ipware import get_client_ip
|
||||
from wsgiref.util import FileWrapper
|
||||
from django.db.models import F
|
||||
from django.http import HttpResponse, FileResponse
|
||||
from django.http import HttpResponse, FileResponse, JsonResponse
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.core.files.storage import FileSystemStorage
|
||||
from django.core.files.base import ContentFile
|
||||
@@ -381,7 +381,7 @@ def events(request, page=1):
|
||||
data = {'events' : events[start:end], 'paging' : paging};
|
||||
return render(request, 'events.html', data)
|
||||
|
||||
def machines(request):
|
||||
def machines(request, machineid=None):
|
||||
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
# #
|
||||
@@ -390,8 +390,13 @@ def machines(request):
|
||||
# #
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
|
||||
data = {'machines' : OpenBench.utils.getRecentMachines()}
|
||||
return render(request, 'machines.html', data)
|
||||
if machineid == None:
|
||||
data = {'machines' : OpenBench.utils.getRecentMachines()}
|
||||
return render(request, 'machines.html', data)
|
||||
|
||||
else:
|
||||
data = {'machine' : OpenBench.models.Machine.objects.get(id=machineid)}
|
||||
return render(request, 'machine.html', data)
|
||||
|
||||
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
@@ -624,29 +629,46 @@ def scripts(request):
|
||||
@not_minified_response
|
||||
def clientGetFiles(request):
|
||||
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
# #
|
||||
# GET : Return a URL to the location of Cutechess for Windows and Linux #
|
||||
# #
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
## Location of static compile of Cutechess for Windows and Linux.
|
||||
## OpenBench does not serve these files, but points to a repo ideally.
|
||||
|
||||
return HttpResponse(OpenBench.config.OPENBENCH_CONFIG['corefiles'])
|
||||
|
||||
@not_minified_response
|
||||
def clientGetBuildInfo(request):
|
||||
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
# #
|
||||
# GET : Return a Dictionary of all of the Engines that are present in #
|
||||
# config.py, as well as the required compilation tools for them #
|
||||
# #
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
## Information pulled from the config about how to build each engine.
|
||||
## Toss in a private flag as well to indicate the need for Github Tokens.
|
||||
|
||||
data = {}
|
||||
for engine, config in OpenBench.config.OPENBENCH_CONFIG['engines'].items():
|
||||
data[engine] = config['build']
|
||||
data[engine]['private'] = config['private']
|
||||
return HttpResponse(json.dumps(data))
|
||||
return JsonResponse(data)
|
||||
|
||||
@csrf_exempt
|
||||
@not_minified_response
|
||||
def clientWorkerInfo(request):
|
||||
|
||||
# Verify the User's credentials
|
||||
try: user = authenticate(request, True)
|
||||
except UnableToAuthenticate:
|
||||
return JsonResponse({ 'error' : 'Bad Credentials' })
|
||||
|
||||
# Attempt to fetch the Machine, or create a new one
|
||||
info = json.loads(request.POST['system_info'])
|
||||
machine = OpenBench.utils.get_machine(info['machine_id'], user, info)
|
||||
|
||||
# Indicate invalid request
|
||||
if not machine:
|
||||
return JsonResponse({ 'error' : 'Bad Machine Id' })
|
||||
|
||||
# Save the machine's latest information
|
||||
machine.secret = secrets.token_hex(32)
|
||||
machine.save()
|
||||
|
||||
# Pass back the Machine Id, and Secret Token for this session
|
||||
return JsonResponse({ 'machine_id' : machine.id, 'secret' : machine.secret })
|
||||
|
||||
@csrf_exempt
|
||||
@not_minified_response
|
||||
|
||||
Reference in new issue
Block a user