Update the views for Index, Greens, Search, and User
This commit is contained in:
1 parent
e6348916e2
commit
684fd636ed
7 files changed
+159
-103
No files matched your search
+2
-2
@@ -34,8 +34,8 @@ urlpatterns = [
|
|||||||
django.urls.path(r'greens/', OpenBench.views.greens),
|
django.urls.path(r'greens/', OpenBench.views.greens),
|
||||||
django.urls.path(r'greens/<int:page>/', OpenBench.views.greens),
|
django.urls.path(r'greens/<int:page>/', OpenBench.views.greens),
|
||||||
django.urls.path(r'search/', OpenBench.views.search),
|
django.urls.path(r'search/', OpenBench.views.search),
|
||||||
django.urls.path(r'viewUser/<str:username>/', OpenBench.views.viewUser),
|
django.urls.path(r'user/<str:username>/', OpenBench.views.user),
|
||||||
django.urls.path(r'viewUser/<str:username>/<int:page>/', OpenBench.views.viewUser),
|
django.urls.path(r'user/<str:username>/<int:page>/', OpenBench.views.user),
|
||||||
|
|
||||||
# Links for viewing general information tables
|
# Links for viewing general information tables
|
||||||
django.urls.path(r'users/', OpenBench.views.users),
|
django.urls.path(r'users/', OpenBench.views.users),
|
||||||
|
|||||||
+66
-1
@@ -18,15 +18,80 @@
|
|||||||
# #
|
# #
|
||||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||||
|
|
||||||
import math, requests, random
|
import math, requests, random, datetime
|
||||||
|
|
||||||
|
import OpenBench.models
|
||||||
|
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.db.models import F
|
from django.db.models import F
|
||||||
from django.contrib.auth import authenticate
|
from django.contrib.auth import authenticate
|
||||||
|
from django.utils.timezone import utc
|
||||||
|
|
||||||
from OpenBench.config import *
|
from OpenBench.config import *
|
||||||
from OpenBench.models import Engine, Profile, Machine, Result, Test
|
from OpenBench.models import Engine, Profile, Machine, Result, Test
|
||||||
|
|
||||||
|
|
||||||
|
def getPendingTests():
|
||||||
|
pending = OpenBench.models.Test.objects.filter(approved=False)
|
||||||
|
pending = pending.exclude(finished=True)
|
||||||
|
pending = pending.exclude(deleted=True)
|
||||||
|
return pending.order_by('-creation')
|
||||||
|
|
||||||
|
def getActiveTests():
|
||||||
|
active = OpenBench.models.Test.objects.filter(approved=True)
|
||||||
|
active = active.exclude(finished=True)
|
||||||
|
active = active.exclude(deleted=True)
|
||||||
|
return active.order_by('-priority', '-currentllr')
|
||||||
|
|
||||||
|
def getCompletedTests():
|
||||||
|
completed = OpenBench.models.Test.objects.filter(finished=True)
|
||||||
|
completed = completed.exclude(deleted=True)
|
||||||
|
return completed.order_by('-updated')
|
||||||
|
|
||||||
|
def getMachineStatus(username=None):
|
||||||
|
|
||||||
|
# Filter for machines used in the last 10 minutes
|
||||||
|
target = datetime.datetime.utcnow().replace(tzinfo=utc) \
|
||||||
|
- datetime.timedelta(minutes=10)
|
||||||
|
machines = Machine.objects.filter(updated__gte=target)
|
||||||
|
|
||||||
|
# Filter for user specific views
|
||||||
|
if username != None: machines = machines.filter(owner=username)
|
||||||
|
|
||||||
|
# Extract stat information from workers
|
||||||
|
return "{0} Machines ".format(len(machines)) + \
|
||||||
|
"{0} Threads ".format(sum([f.threads for f in machines])) + \
|
||||||
|
"{0} MNPS ".format(sum([f.threads * f.mnps for f in machines]))
|
||||||
|
|
||||||
|
def getPagedContent(content, page, pagelen, url):
|
||||||
|
|
||||||
|
start = max(0, pagelen * (page - 1))
|
||||||
|
end = min(len(content), pagelen * page)
|
||||||
|
count = 1 + math.ceil(len(content) / pagelen)
|
||||||
|
|
||||||
|
part1 = list(range(1, min(4, count)))
|
||||||
|
part2 = list(range(page - 2, page + 1))
|
||||||
|
part3 = list(range(page + 1, page + 3))
|
||||||
|
part4 = list(range(count - 3, count + 1))
|
||||||
|
|
||||||
|
pages = part1 + part2 + part3 + part4
|
||||||
|
pages = [f for f in pages if f >= 1 and f <= count]
|
||||||
|
pages = list(set(pages))
|
||||||
|
pages.sort()
|
||||||
|
|
||||||
|
final = []
|
||||||
|
for f in range(len(pages) - 1):
|
||||||
|
final.append(pages[f])
|
||||||
|
if pages[f] != pages[f+1] - 1:
|
||||||
|
final.append('...')
|
||||||
|
|
||||||
|
context = {
|
||||||
|
"url" : url, "page" : page, "pages" : final,
|
||||||
|
"prev" : max(1, page - 1), "next" : max(1, min(page + 1, count - 1)),
|
||||||
|
}
|
||||||
|
|
||||||
|
return content[start:end], context
|
||||||
|
|
||||||
def pagingContext(page, pageLength, items, url):
|
def pagingContext(page, pageLength, items, url):
|
||||||
|
|
||||||
# Tests within the given page
|
# Tests within the given page
|
||||||
|
|||||||
+84
-93
@@ -181,136 +181,127 @@ def profile(request):
|
|||||||
# Test List Views #
|
# Test List Views #
|
||||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||||
|
|
||||||
def index(request, page=1, pageLength=24, greens=False, username=None, error=''):
|
def index(request, page=1, error=''):
|
||||||
|
|
||||||
# Get tests pending approval
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||||
pending = Test.objects.filter(approved=False)
|
# #
|
||||||
pending = pending.exclude(finished=True)
|
# GET : Return all pending, active, and completed tests. Limit the #
|
||||||
pending = pending.exclude(deleted=True)
|
# display of tests by the requested page number. Also display the #
|
||||||
pending = pending.order_by('-creation')
|
# status for connected machines. #
|
||||||
|
# #
|
||||||
|
# POST : Return all pending, active, and completed tests. Limit the #
|
||||||
|
# display of tests by the requested page number. Also display the #
|
||||||
|
# status for connected machines. #
|
||||||
|
# #
|
||||||
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||||
|
|
||||||
# Get tests currently running
|
pending = OpenBench.utils.getPendingTests()
|
||||||
active = Test.objects.filter(approved=True)
|
active = OpenBench.utils.getActiveTests()
|
||||||
active = active.exclude(finished=True)
|
completed = OpenBench.utils.getCompletedTests()
|
||||||
active = active.exclude(deleted=True)
|
|
||||||
active = active.order_by('-priority', '-currentllr')
|
|
||||||
|
|
||||||
# Get the completed tests (sliced later)
|
completed, paging = OpenBench.utils.getPagedContent(
|
||||||
completed = Test.objects.filter(finished=True)
|
completed, page, 25, 'index'.format())
|
||||||
completed = completed.exclude(deleted=True)
|
|
||||||
completed = completed.order_by('-updated')
|
|
||||||
|
|
||||||
# Pull data from active machines
|
|
||||||
target = datetime.datetime.utcnow().replace(tzinfo=utc) - datetime.timedelta(minutes=10)
|
|
||||||
machines = Machine.objects.filter(updated__gte=target)
|
|
||||||
if username != None: machines = machines.filter(owner=username)
|
|
||||||
|
|
||||||
# Extract stat information from workers
|
|
||||||
machineCount = len(machines)
|
|
||||||
threadCount = sum(machine.threads for machine in machines)
|
|
||||||
npsTotal = sum(machine.threads * machine.mnps for machine in machines)
|
|
||||||
workerData = "{0} Machines {1} Threads {2} MNPS".format(
|
|
||||||
machineCount, threadCount, round(npsTotal, 2)
|
|
||||||
)
|
|
||||||
|
|
||||||
# Index is wrapped for just viewing passed tests
|
|
||||||
if greens == True:
|
|
||||||
pending = active = []
|
|
||||||
completed = completed.filter(passed=True)
|
|
||||||
source = 'greens'
|
|
||||||
|
|
||||||
# Index is wrapped just to view one user
|
|
||||||
elif username != None:
|
|
||||||
pending = pending.filter(author=username)
|
|
||||||
active = active.filter(author=username)
|
|
||||||
completed = completed.filter(author=username)
|
|
||||||
source = "viewUser/{0}".format(username)
|
|
||||||
|
|
||||||
# Index is normal, not wrapped for any views
|
|
||||||
else:
|
|
||||||
source = "index"
|
|
||||||
|
|
||||||
# Choose tests within the given page, if any
|
|
||||||
items = len(completed)
|
|
||||||
start = (page - 1) * pageLength
|
|
||||||
end = page * pageLength
|
|
||||||
start = max(0, min(start, items))
|
|
||||||
end = max(0, min(end, items))
|
|
||||||
paging = pagingContext(page, pageLength, items, source)
|
|
||||||
|
|
||||||
# Build context dictionary for index template
|
|
||||||
data = {
|
data = {
|
||||||
'error' : error,
|
'error' : error, 'pending' : pending,
|
||||||
'pending' : pending,
|
'active' : active, 'completed' : completed,
|
||||||
'active' : active,
|
'paging' : paging, 'status' : OpenBench.utils.getMachineStatus(),
|
||||||
'completed' : completed[start:end],
|
|
||||||
'status' : workerData,
|
|
||||||
'greens' : greens,
|
|
||||||
'paging' : paging,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return render(request, 'index.html', data)
|
return render(request, 'index.html', data)
|
||||||
|
|
||||||
def greens(request, page=1):
|
def greens(request, page=1):
|
||||||
|
|
||||||
# Index but with only passed tests
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||||
return index(request, page, greens=True)
|
# #
|
||||||
|
# GET : Return all tests both passed and completed. Limit the display #
|
||||||
|
# of tests by the requested page number. #
|
||||||
|
# #
|
||||||
|
# POST : Return all tests both passed and completed. Limit the display #
|
||||||
|
# of tests by the requested page number. #
|
||||||
|
# #
|
||||||
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||||
|
|
||||||
|
completed = OpenBench.utils.getCompletedTests().filter(passed=True)
|
||||||
|
completed, paging = OpenBench.utils.getPagedContent(
|
||||||
|
completed, page, 25, 'greens'.format())
|
||||||
|
|
||||||
|
data = {'completed' : completed, 'paging' : paging}
|
||||||
|
return render(request, 'index.html', data)
|
||||||
|
|
||||||
def search(request):
|
def search(request):
|
||||||
|
|
||||||
# First time viewing the page
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||||
if request.method == 'GET':
|
# #
|
||||||
return render(request, 'search.html', {'tests' : []})
|
# GET : Return the HTML template for searching tests on the framework. #
|
||||||
|
# #
|
||||||
|
# POST : Filter the tests by the provided criteria, and return a display #
|
||||||
|
# with the filtered results. Keywords are case insensitive #
|
||||||
|
# #
|
||||||
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||||
|
|
||||||
|
if request.method == 'GET':
|
||||||
|
return render(request, 'search.html', {})
|
||||||
|
|
||||||
# Base starting point with all tests
|
|
||||||
tests = Test.objects.all()
|
tests = Test.objects.all()
|
||||||
|
|
||||||
# Only show tests for selected engine (default is all engines)
|
|
||||||
if request.POST['engine'] != '':
|
if request.POST['engine'] != '':
|
||||||
tests = tests.filter(engine=request.POST['engine'])
|
tests = tests.filter(engine=request.POST['engine'])
|
||||||
|
|
||||||
# Only show tests from a selected author (default is all authors)
|
|
||||||
if request.POST['author'] != '':
|
if request.POST['author'] != '':
|
||||||
tests = tests.filter(author=request.POST['author'])
|
tests = tests.filter(author=request.POST['author'])
|
||||||
|
|
||||||
# Don't show tests that have passed
|
|
||||||
if request.POST['showgreens'] == 'False':
|
if request.POST['showgreens'] == 'False':
|
||||||
tests = tests.exclude(passed=True)
|
tests = tests.exclude(passed=True)
|
||||||
|
|
||||||
# Don't show tests that have failed yellow
|
|
||||||
if request.POST['showyellows'] == 'False':
|
if request.POST['showyellows'] == 'False':
|
||||||
tests = tests.exclude(failed=True,wins__gte=F('losses'))
|
tests = tests.exclude(failed=True, wins__gte=F('losses'))
|
||||||
|
|
||||||
# Don't show tests that have failed red
|
if request.POST['showreds'] == 'False':
|
||||||
if request.POST['showreds'] == 'False':
|
tests = tests.exclude(failed=True, wins__lt=F('losses'))
|
||||||
tests = tests.exclude(failed=True,wins__lt=F('losses'))
|
|
||||||
|
|
||||||
# Don't show tests that are unfinished
|
|
||||||
if request.POST['showunfinished'] == 'False':
|
if request.POST['showunfinished'] == 'False':
|
||||||
tests = tests.exclude(passed=False,failed=False)
|
tests = tests.exclude(passed=False, failed=False)
|
||||||
|
|
||||||
# Don't show tests that have been deleted
|
|
||||||
if request.POST['showdeleted'] == 'False':
|
if request.POST['showdeleted'] == 'False':
|
||||||
tests = tests.exclude(deleted=True)
|
tests = tests.exclude(deleted=True)
|
||||||
|
|
||||||
# If there are no keywords, we are done searching
|
keywords = ['(?i)' + f.upper() for f in request.POST['keywords'].split()]
|
||||||
keywords = request.POST['keywords'].split()
|
tests = tests.filter(dev__name__regex=r'{0}'.format('|'.join(keywords)))
|
||||||
if keywords == []:
|
return render(request, 'search.html', {'tests' : tests.order_by('-updated')})
|
||||||
return render(request, 'search.html', {'tests' : tests.order_by('-updated')})
|
|
||||||
|
|
||||||
# Only grab tests which contain at least one keyword
|
def user(request, username, page=1):
|
||||||
filtered = []
|
|
||||||
for test in tests.order_by('-updated'):
|
|
||||||
for keyword in keywords:
|
|
||||||
if keyword.upper() in test.dev.name.upper():
|
|
||||||
filtered.append(test)
|
|
||||||
break
|
|
||||||
return render(request, 'search.html', {'tests' : filtered})
|
|
||||||
|
|
||||||
def viewUser(request, username, page=0):
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||||
|
# #
|
||||||
|
# GET : Return all pending, active, and completed tests for the User #
|
||||||
|
# that has been requested. Limit the display of completed tests #
|
||||||
|
# by the requested page number. Also display the User's machines #
|
||||||
|
# #
|
||||||
|
# POST : Return all pending, active, and completed tests for the User #
|
||||||
|
# that has been requested. Limit the display of completed tests #
|
||||||
|
# by the requested page number. Also display the User's machines #
|
||||||
|
# #
|
||||||
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||||
|
|
||||||
# Index but with only username's tests
|
pending = OpenBench.utils.getPendingTests().filter(author=username)
|
||||||
return index(request, page, username=username)
|
active = OpenBench.utils.getActiveTests().filter(author=username)
|
||||||
|
completed = OpenBench.utils.getCompletedTests().filter(author=username)
|
||||||
|
|
||||||
|
completed, paging = OpenBench.utils.getPagedContent(
|
||||||
|
completed, page, 25, 'user/{0}'.format(username))
|
||||||
|
|
||||||
|
data = {
|
||||||
|
'pending' : pending, 'active' : active,
|
||||||
|
'completed' : completed, 'paging' : paging,
|
||||||
|
'status' : OpenBench.utils.getMachineStatus(username),
|
||||||
|
}
|
||||||
|
|
||||||
|
return render(request, 'index.html', data)
|
||||||
|
|
||||||
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||||
|
# #
|
||||||
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||||
|
|
||||||
def users(request):
|
def users(request):
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{% load mytags %}
|
{% load mytags %}
|
||||||
<tr>
|
<tr>
|
||||||
<td><a href="/viewUser/{{test.author}}">{{test.author|slice:":6"}}</a></td>
|
<td><a href="/user/{{test.author}}">{{test.author|slice:":6"}}</a></td>
|
||||||
<td>{{test.engine}}</td>
|
<td>{{test.engine}}</td>
|
||||||
<td><a href="/viewTest/{{test.id}}">{{test.dev.name}}</a></td>
|
<td><a href="/viewTest/{{test.id}}">{{test.dev.name}}</a></td>
|
||||||
<td class="textcenter"><a href="{{test|gitDiffLink}}">diff</a></td>
|
<td class="textcenter"><a href="{{test|gitDiffLink}}">diff</a></td>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<table class="datatable">
|
<table class="datatable">
|
||||||
|
|
||||||
<!-- Only show Pending tests for the front page of the Index -->
|
<!-- Only show Pending tests for the front page of the Index -->
|
||||||
{% if paging.page == 1 and greens == False %}
|
{% if paging.page == 1 %}
|
||||||
|
|
||||||
<!-- Currently Pending tests (Waiting to be approved) -->
|
<!-- Currently Pending tests (Waiting to be approved) -->
|
||||||
{% if pending %}
|
{% if pending %}
|
||||||
|
|||||||
@@ -14,23 +14,23 @@
|
|||||||
<select name="engine">
|
<select name="engine">
|
||||||
<option selected value="">ALL</option>
|
<option selected value="">ALL</option>
|
||||||
{% for name, data in config.engines.items %}
|
{% for name, data in config.engines.items %}
|
||||||
<option value="{{name}}">{{data.name}}</option>
|
<option value="{{name}}">{{name}}</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</select><br>
|
</select><br>
|
||||||
|
|
||||||
<label> Show Passed </label>
|
<label> Show Greens </label>
|
||||||
<select name="showgreens">
|
<select name="showgreens">
|
||||||
<option selected value="True">True</option>
|
<option selected value="True">True</option>
|
||||||
<option value="False">False</option>
|
<option value="False">False</option>
|
||||||
</select><br>
|
</select><br>
|
||||||
|
|
||||||
<label> Show Failed </label>
|
<label> Show Yellows </label>
|
||||||
<select name="showyellows">
|
<select name="showyellows">
|
||||||
<option selected value="True">True</option>
|
<option selected value="True">True</option>
|
||||||
<option value="False">False</option>
|
<option value="False">False</option>
|
||||||
</select><br>
|
</select><br>
|
||||||
|
|
||||||
<label> Show Neutral </label>
|
<label> Show Reds </label>
|
||||||
<select name="showreds">
|
<select name="showreds">
|
||||||
<option selected value="True">True</option>
|
<option selected value="True">True</option>
|
||||||
<option value="False">False</option>
|
<option value="False">False</option>
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
{% for profile in profiles %}
|
{% for profile in profiles %}
|
||||||
{% if profile.enabled %}
|
{% if profile.enabled %}
|
||||||
<tr>
|
<tr>
|
||||||
<td><a href="/viewUser/{{profile.user.username}}">{{profile.user.username}}</a></td>
|
<td><a href="/user/{{profile.user.username}}">{{profile.user.username}}</a></td>
|
||||||
<td style="text-align: right">{{profile.games|insertCommas}}</td>
|
<td style="text-align: right">{{profile.games|insertCommas}}</td>
|
||||||
<td style="text-align: right">{{profile.tests|insertCommas}}</td>
|
<td style="text-align: right">{{profile.tests|insertCommas}}</td>
|
||||||
<td>{{profile.engine}}</td>
|
<td>{{profile.engine}}</td>
|
||||||
|
|||||||
Reference in new issue
Block a user