Update the views for Index, Greens, Search, and User

This commit is contained in:
AndyGrant committed 2020-02-28 01:35:47 -05:00
1 parent e6348916e2
commit 684fd636ed
7 files changed
+159 -103

No files matched your search

+2 -2
View File
@@ -34,8 +34,8 @@ urlpatterns = [
django.urls.path(r'greens/', 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'viewUser/<str:username>/', OpenBench.views.viewUser),
django.urls.path(r'viewUser/<str:username>/<int:page>/', OpenBench.views.viewUser),
django.urls.path(r'user/<str:username>/', OpenBench.views.user),
django.urls.path(r'user/<str:username>/<int:page>/', OpenBench.views.user),
# Links for viewing general information tables
django.urls.path(r'users/', OpenBench.views.users),
+66 -1
View File
@@ -18,15 +18,80 @@
# #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
import math, requests, random
import math, requests, random, datetime
import OpenBench.models
from django.utils import timezone
from django.db.models import F
from django.contrib.auth import authenticate
from django.utils.timezone import utc
from OpenBench.config import *
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):
# Tests within the given page
+84 -93
View File
@@ -181,136 +181,127 @@ def profile(request):
# 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)
pending = pending.exclude(deleted=True)
pending = pending.order_by('-creation')
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# #
# GET : Return all pending, active, and completed tests. Limit the #
# display of tests by the requested page number. Also display the #
# 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
active = Test.objects.filter(approved=True)
active = active.exclude(finished=True)
active = active.exclude(deleted=True)
active = active.order_by('-priority', '-currentllr')
pending = OpenBench.utils.getPendingTests()
active = OpenBench.utils.getActiveTests()
completed = OpenBench.utils.getCompletedTests()
# Get the completed tests (sliced later)
completed = Test.objects.filter(finished=True)
completed = completed.exclude(deleted=True)
completed = completed.order_by('-updated')
completed, paging = OpenBench.utils.getPagedContent(
completed, page, 25, 'index'.format())
# 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 = {
'error' : error,
'pending' : pending,
'active' : active,
'completed' : completed[start:end],
'status' : workerData,
'greens' : greens,
'paging' : paging,
'error' : error, 'pending' : pending,
'active' : active, 'completed' : completed,
'paging' : paging, 'status' : OpenBench.utils.getMachineStatus(),
}
return render(request, 'index.html', data)
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):
# 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()
# Only show tests for selected engine (default is all engines)
if 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'] != '':
tests = tests.filter(author=request.POST['author'])
# Don't show tests that have passed
if request.POST['showgreens'] == 'False':
tests = tests.exclude(passed=True)
# Don't show tests that have failed yellow
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':
tests = tests.exclude(failed=True,wins__lt=F('losses'))
if request.POST['showreds'] == 'False':
tests = tests.exclude(failed=True, wins__lt=F('losses'))
# Don't show tests that are unfinished
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':
tests = tests.exclude(deleted=True)
# If there are no keywords, we are done searching
keywords = request.POST['keywords'].split()
if keywords == []:
return render(request, 'search.html', {'tests' : tests.order_by('-updated')})
keywords = ['(?i)' + f.upper() for f in request.POST['keywords'].split()]
tests = tests.filter(dev__name__regex=r'{0}'.format('|'.join(keywords)))
return render(request, 'search.html', {'tests' : tests.order_by('-updated')})
# Only grab tests which contain at least one keyword
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 user(request, username, page=1):
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
return index(request, page, username=username)
pending = OpenBench.utils.getPendingTests().filter(author=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):
+1 -1
View File
@@ -1,6 +1,6 @@
{% load mytags %}
<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><a href="/viewTest/{{test.id}}">{{test.dev.name}}</a></td>
<td class="textcenter"><a href="{{test|gitDiffLink}}">diff</a></td>
+1 -1
View File
@@ -5,7 +5,7 @@
<table class="datatable">
<!-- 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) -->
{% if pending %}
+4 -4
View File
@@ -14,23 +14,23 @@
<select name="engine">
<option selected value="">ALL</option>
{% for name, data in config.engines.items %}
<option value="{{name}}">{{data.name}}</option>
<option value="{{name}}">{{name}}</option>
{% endfor %}
</select><br>
<label> Show Passed </label>
<label> Show Greens </label>
<select name="showgreens">
<option selected value="True">True</option>
<option value="False">False</option>
</select><br>
<label> Show Failed </label>
<label> Show Yellows </label>
<select name="showyellows">
<option selected value="True">True</option>
<option value="False">False</option>
</select><br>
<label> Show Neutral </label>
<label> Show Reds </label>
<select name="showreds">
<option selected value="True">True</option>
<option value="False">False</option>
+1 -1
View File
@@ -17,7 +17,7 @@
{% for profile in profiles %}
{% if profile.enabled %}
<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.tests|insertCommas}}</td>
<td>{{profile.engine}}</td>