From bd98e33fcdc96f1dc3268c64a64b0d47b8440ca2 Mon Sep 17 00:00:00 2001 From: AndyGrant Date: Mon, 25 Jun 2018 21:12:25 -0400 Subject: [PATCH] Add worker information to main page --- OpenBench/views.py | 18 ++++++++++++++++-- Templates/OpenBench/index.html | 6 +++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/OpenBench/views.py b/OpenBench/views.py index 0c95ace..427628a 100644 --- a/OpenBench/views.py +++ b/OpenBench/views.py @@ -126,6 +126,19 @@ def index(request, page=0, pageLength=50, username=None, error=''): 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.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 just to view one user if username != None: pending = pending.filter(author=username) @@ -145,10 +158,11 @@ def index(request, page=0, pageLength=50, username=None, error=''): # Build context dictionary for index template data = { + 'error' : error, 'pending' : pending, 'active' : active, 'completed' : completed[start:end], - 'error' : error, + 'status' : workerData, 'paging' : paging, } @@ -168,7 +182,7 @@ def viewUser(request, username, page=0): def machines(request): # Build context dictionary for machine template with machines updated recently - target = datetime.datetime.utcnow().replace(tzinfo=utc) - datetime.timedelta(minutes=20) + target = datetime.datetime.utcnow().replace(tzinfo=utc) - datetime.timedelta(minutes=10) data = {'machines' : Machine.objects.filter(updated__gte=target)} return render(request, 'machines.html', data) diff --git a/Templates/OpenBench/index.html b/Templates/OpenBench/index.html index 871a32d..627cfda 100644 --- a/Templates/OpenBench/index.html +++ b/Templates/OpenBench/index.html @@ -3,7 +3,7 @@ {% block content %} {% if paging.page == 0 %} - + {% if pending %} @@ -26,7 +26,7 @@ {% endfor %} - + {% if active %} @@ -50,7 +50,7 @@ {% endfor %} {% endif %} - + {% if completed %}

Pending

Pending

Engine{{test|shortStatBlock|linebreaksbr}}

Active

Active - {{status}}

Engine

Finished

Finished

Engine