Implement Searching again
This commit is contained in:
1 parent
3beb04aacb
commit
ef3104cd68
3 files changed
+274
-91
No files matched your search
+81
-34
@@ -43,6 +43,83 @@ from OpenBench.stats import SPRT
|
||||
from OpenBench.views import redirect
|
||||
|
||||
|
||||
class TimeControl(object):
|
||||
|
||||
FIXED_NODES = 'FIXED-NODES' # N= or nodes=
|
||||
FIXED_DEPTH = 'FIXED-DEPTH' # D= or depth=
|
||||
FIXED_TIME = 'FIXED-TIME' # MT= or movetime=
|
||||
CYCLIC = 'CYCLIC' # X/Y or X/Y+Z
|
||||
FISCHER = 'FISCHER' # Y or Y+Z
|
||||
|
||||
@staticmethod
|
||||
def parse(time_str):
|
||||
|
||||
# Display Nodes as N=, Depth as D=, MoveTime as MT=
|
||||
conversion = {
|
||||
'N' : 'N', 'nodes' : 'N',
|
||||
'D' : 'D', 'depth' : 'D',
|
||||
'MT' : 'MT', 'movetime' : 'MT',
|
||||
}
|
||||
|
||||
# Searching for "nodes=", "depth=", and "movetime=" time controls
|
||||
pattern = '(?P<mode>((N)|(D)|(MT)|(nodes)|(depth)|(movetime)))=(?P<value>(\d+))'
|
||||
if results := re.search(pattern, time_str.upper()):
|
||||
mode, value = results.group('mode', 'value')
|
||||
return '%s=%s' % (conversion[mode], value)
|
||||
|
||||
# Searching for "X/Y+Z" time controls, where "X/" is optional
|
||||
pattern = '(?P<moves>(\d+/)?)(?P<base>\d*(\.\d+)?)(?P<inc>\+(\d+\.)?\d+)?'
|
||||
if results := re.search(pattern, time_str):
|
||||
moves, base, inc = results.group('moves', 'base', 'inc')
|
||||
|
||||
# Strip the trailing and leading symbols
|
||||
moves = None if moves == '' else moves.rstrip('/')
|
||||
inc = 0.0 if inc is None else inc.lstrip('+')
|
||||
|
||||
# Format the time control for cutechess cleanly
|
||||
if moves is None: return '%.1f+%.2f' % (float(base), float(inc))
|
||||
return '%d/%.1f+%.2f' % (int(moves), float(base), float(inc))
|
||||
|
||||
print ('FAIL')
|
||||
import sys
|
||||
sys.stdout.flush()
|
||||
|
||||
raise Exception('Unable to parse Time Control (%s)' % (time_str))
|
||||
|
||||
@staticmethod
|
||||
def control_type(time_str):
|
||||
|
||||
# Return one of the types defined at the top of TimeControl
|
||||
|
||||
if time_str.startswith('N='):
|
||||
return TimeControl.FIXED_NODES
|
||||
|
||||
if time_str.startswith('D='):
|
||||
return TimeControl.FIXED_DEPTH
|
||||
|
||||
if time_str.startswith('MT='):
|
||||
return TimeControl.FIXED_TIME
|
||||
|
||||
if '/' in time_str:
|
||||
return TimeControl.CYCLIC
|
||||
|
||||
return TimeControl.FISCHER
|
||||
|
||||
@staticmethod
|
||||
def control_base(time_str):
|
||||
|
||||
# Fixed-nodes, Fixed-depth, Fixed-time
|
||||
if '=' in time_str:
|
||||
return int(time_str.split('=')[1])
|
||||
|
||||
# Cyclic
|
||||
if '/' in time_str:
|
||||
return float(time_str.split('/')[0])
|
||||
|
||||
# Fischer or Sudden Death otherwise
|
||||
return float(time_str.split('+')[0])
|
||||
|
||||
|
||||
def path_join(*args):
|
||||
return "/".join([f.lstrip("/").rstrip("/") for f in args]).rstrip('/')
|
||||
|
||||
@@ -57,36 +134,6 @@ def extract_option(options, option):
|
||||
match = re.search('(?<={0}=)[^ ]*'.format(option), options)
|
||||
if match: return match.group()
|
||||
|
||||
def parse_time_control(time_control):
|
||||
|
||||
# Display Nodes as N=, Depth as D=, MoveTime as MT=
|
||||
conversion = {
|
||||
'N' : 'N', 'nodes' : 'N',
|
||||
'D' : 'D', 'depth' : 'D',
|
||||
'MT' : 'MT', 'movetime' : 'MT',
|
||||
}
|
||||
|
||||
# Searching for "nodes=", "depth=", and "movetime=" Time Controls
|
||||
pattern = '(?P<mode>((N)|(D)|(MT)|(nodes)|(depth)|(movetime)))=(?P<value>(\d+))'
|
||||
if results := re.search(pattern, time_control.upper()):
|
||||
mode, value = results.group('mode', 'value')
|
||||
return '%s=%s' % (conversion[mode], value)
|
||||
|
||||
# Searching for "X/Y+Z" time controls
|
||||
pattern = '(?P<moves>(\d+/)?)(?P<base>\d*(\.\d+)?)(?P<inc>\+(\d+\.)?\d+)?'
|
||||
if results := re.search(pattern, time_control):
|
||||
moves, base, inc = results.group('moves', 'base', 'inc')
|
||||
|
||||
# Strip the trailing and leading symbols
|
||||
moves = None if moves == '' else moves.rstrip('/')
|
||||
inc = 0.0 if inc is None else inc.lstrip('+')
|
||||
|
||||
# Format the time control for cutechess
|
||||
if moves is None: return '%.1f+%.2f' % (float(base), float(inc))
|
||||
return '%d/%.1f+%.2f' % (int(moves), float(base), float(inc))
|
||||
|
||||
raise Exception('Unable to parse Time Control (%s)' % (time_control))
|
||||
|
||||
|
||||
def get_pending_tests():
|
||||
t = Test.objects.filter(approved=False)
|
||||
@@ -328,8 +375,8 @@ def verify_test_creation(request):
|
||||
except: errors.append('{0} was not found in the configuration'.format(field_name))
|
||||
|
||||
def verify_time_control(field, field_name):
|
||||
try: parse_time_control(request.POST[field])
|
||||
except: errors.append('{0} is not a parsable'.format(field_name))
|
||||
try: TimeControl.parse(request.POST[field])
|
||||
except: errors.append('{0} is not parsable'.format(field_name))
|
||||
|
||||
def verify_win_adj(field):
|
||||
try:
|
||||
@@ -451,14 +498,14 @@ def create_new_test(request):
|
||||
test.dev_engine = request.POST['dev_engine']
|
||||
test.dev_options = request.POST['dev_options']
|
||||
test.dev_network = request.POST['dev_network']
|
||||
test.dev_time_control = parse_time_control(request.POST['dev_time_control'])
|
||||
test.dev_time_control = TimeControl.parse(request.POST['dev_time_control'])
|
||||
|
||||
test.base = getEngine(*baseinfo)
|
||||
test.base_repo = request.POST['base_repo']
|
||||
test.base_engine = request.POST['base_engine']
|
||||
test.base_options = request.POST['base_options']
|
||||
test.base_network = request.POST['base_network']
|
||||
test.base_time_control = parse_time_control(request.POST['base_time_control'])
|
||||
test.base_time_control = TimeControl.parse(request.POST['base_time_control'])
|
||||
|
||||
test.report_rate = int(request.POST['report_rate'])
|
||||
test.workload_size = int(request.POST['workload_size'])
|
||||
|
||||
+89
-18
@@ -33,7 +33,7 @@ from OpenBench.models import *
|
||||
from django.contrib.auth.models import User
|
||||
from OpenSite.settings import MEDIA_ROOT
|
||||
|
||||
from django.db.models import F
|
||||
from django.db.models import F, Q
|
||||
from django.http import HttpResponse, JsonResponse
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.core.files.storage import FileSystemStorage
|
||||
@@ -46,7 +46,7 @@ from django.core.files.base import ContentFile
|
||||
class UnableToAuthenticate(Exception):
|
||||
pass
|
||||
|
||||
def render(request, template, content={}, always_allow=False):
|
||||
def render(request, template, content={}, always_allow=False, error=None, status=None):
|
||||
|
||||
data = content.copy()
|
||||
data.update({ 'config' : OPENBENCH_CONFIG })
|
||||
@@ -66,6 +66,12 @@ def render(request, template, content={}, always_allow=False):
|
||||
elif request.user.is_authenticated and not profile.first():
|
||||
request.session['error_message'] = data['config']['error']['fakeuser']
|
||||
|
||||
if error:
|
||||
request.session['error_message'] = error
|
||||
|
||||
if status:
|
||||
request.session['status_message'] = status
|
||||
|
||||
response = django.shortcuts.render(request, 'OpenBench/{0}'.format(template), data)
|
||||
|
||||
for key in ['status_message', 'error_message']:
|
||||
@@ -276,36 +282,101 @@ def search(request):
|
||||
return render(request, 'search.html', {})
|
||||
|
||||
tests = Test.objects.all()
|
||||
keywords = request.POST['keywords'].upper().split()
|
||||
if not keywords: keywords = [""]
|
||||
|
||||
if request.POST['engine'] != '':
|
||||
tests = tests.filter(engine=request.POST['engine'])
|
||||
# Optional Selection box filters
|
||||
|
||||
if request.POST['author'] != '':
|
||||
if request.POST['author']:
|
||||
tests = tests.filter(author=request.POST['author'])
|
||||
|
||||
if request.POST['showgreens'] == 'False':
|
||||
tests = tests.exclude(passed=True)
|
||||
if request.POST['engine']:
|
||||
tests = tests.filter(Q(base_engine=request.POST['engine']) | Q(dev_engine=request.POST['engine']))
|
||||
|
||||
if request.POST['showyellows'] == 'False':
|
||||
if request.POST['opening-book']:
|
||||
tests = tests.filter(book_name=request.POST['opening-book'])
|
||||
|
||||
if request.POST['test-mode']:
|
||||
tests = tests.filter(test_mode=request.POST['test-mode'])
|
||||
|
||||
if request.POST['syzygy-wdl']:
|
||||
tests = tests.filter(syzygy_wdl=request.POST['syzygy-wdl'])
|
||||
|
||||
# Checkboxes for Test statuses
|
||||
|
||||
if 'show-greens' not in request.POST:
|
||||
tests = tests.annotate(x=F('elolower') + F('eloupper')).exclude(x__gte=0, passed=True)
|
||||
|
||||
if 'show-yellows' not in request.POST:
|
||||
tests = tests.exclude(failed=True, wins__gte=F('losses'))
|
||||
|
||||
if request.POST['showreds'] == 'False':
|
||||
if 'show-reds' not in request.POST:
|
||||
tests = tests.exclude(failed=True, wins__lt=F('losses'))
|
||||
|
||||
if request.POST['showunfinished'] == 'False':
|
||||
if 'show-blues' not in request.POST:
|
||||
tests = tests.annotate(x=F('elolower') + F('eloupper')).exclude(x__lt=0, passed=True)
|
||||
|
||||
if 'show-stopped' not in request.POST:
|
||||
tests = tests.exclude(passed=False, failed=False)
|
||||
|
||||
if request.POST['showdeleted'] == 'False':
|
||||
if 'show-deleted' not in request.POST:
|
||||
tests = tests.exclude(deleted=True)
|
||||
|
||||
filtered = [
|
||||
test for test in tests.order_by('-updated') if
|
||||
any(keyword in test.dev.name.upper() for keyword in keywords)
|
||||
]
|
||||
# Remaining filtering is hard to do with standard Django queries
|
||||
|
||||
return render(request, 'search.html', {'tests' : filtered})
|
||||
filtered = []
|
||||
keywords = request.POST['keywords'].upper().split()
|
||||
|
||||
tc_type = request.POST['tc-type']
|
||||
tc_value = request.POST['tc-value-input']
|
||||
tc_select = request.POST['tc-value-select']
|
||||
|
||||
# Attempt to parse the time control
|
||||
|
||||
try:
|
||||
if tc_value:
|
||||
tc_value = OpenBench.utils.TimeControl.parse(tc_value)
|
||||
except:
|
||||
return redirect(request, '/search/', error='Invalid Time Control')
|
||||
|
||||
# Filter out tests
|
||||
|
||||
for test in tests:
|
||||
|
||||
# None of the keywords appear in the dev branch name
|
||||
if keywords and not any(x in test.dev.name.upper() for x in keywords):
|
||||
continue
|
||||
|
||||
# Determine the max number of threads that either engine used
|
||||
dev_threads = OpenBench.utils.extract_option(test.dev_options, 'Threads')
|
||||
base_threads = OpenBench.utils.extract_option(test.base_options, 'Threads')
|
||||
max_threads = max(int(dev_threads), int(base_threads))
|
||||
|
||||
# Extract requsted configuration
|
||||
select_value = request.POST['threads-select']
|
||||
input_value = int(request.POST['threads-input'])
|
||||
|
||||
# Requested Threads value did not match observed value
|
||||
if select_value == '=' and max_threads != input_value: continue
|
||||
if select_value == '>=' and max_threads < input_value: continue
|
||||
if select_value == '<=' and max_threads > input_value: continue
|
||||
|
||||
# Filter our undesired time control types
|
||||
if tc_type and tc_type != OpenBench.utils.TimeControl.control_type(test.dev_time_control):
|
||||
continue
|
||||
|
||||
# Filter tests of the same time control type, but outside our range
|
||||
if tc_value:
|
||||
|
||||
search_base = OpenBench.utils.TimeControl.control_base(tc_value)
|
||||
test_base = OpenBench.utils.TimeControl.control_base(test.dev_time_control)
|
||||
|
||||
if tc_select == '=' and search_base != test_base: continue
|
||||
if tc_select == '>=' and search_base > test_base: continue
|
||||
if tc_select == '<=' and search_base < test_base: continue
|
||||
|
||||
filtered.append(test)
|
||||
|
||||
error = 'No matching tests found' if not len(filtered) else None
|
||||
return render(request, 'search.html', { 'tests' : filtered }, error=error)
|
||||
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
# GENERAL DATA TABLE VIEWS #
|
||||
|
||||
+104
-39
@@ -2,84 +2,150 @@
|
||||
|
||||
{% block scripts %}
|
||||
|
||||
function set_default_engine() {
|
||||
{% if profile.engine %}
|
||||
document.getElementById("engine").value = "{{profile.engine}}";
|
||||
{% endif %}
|
||||
}
|
||||
<script>
|
||||
|
||||
document.addEventListener(
|
||||
'DOMContentLoaded', function () {
|
||||
set_default_engine();
|
||||
}, false
|
||||
);
|
||||
function changed_timecontrol() {
|
||||
var tc_type = document.getElementById("tc-type").value;
|
||||
|
||||
var dict = {
|
||||
"" : "Anything",
|
||||
"FIXED-DEPTH" : "All, or e.g D=10",
|
||||
"FIXED-NODES" : "All, or e.g N=40000",
|
||||
"FIXED-TIME" : "All, or e.g MT=1000",
|
||||
"FISCHER" : "All, or e.g 15.0+0.15",
|
||||
"CYCLIC" : "All, or e.g 40/10.0+0.0",
|
||||
}
|
||||
|
||||
document.getElementById("tc-value-input").placeholder = dict[tc_type];
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
changed_timecontrol();
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
{% if not tests %}
|
||||
|
||||
<form method="POST" action="/search/">
|
||||
{% csrf_token %}
|
||||
|
||||
<div class="form">
|
||||
<div class="col">
|
||||
<div class="row">
|
||||
<label>Keywords</label> <input name="keywords"><br>
|
||||
<label>Keywords</label>
|
||||
<input name="keywords" placeholder="Seperated By Spaces"><br>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label>Author</label> <input name="author"><br>
|
||||
<label>Author</label>
|
||||
<input name="author" placeholder="All Authors By Default"><br>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label>Engine</label>
|
||||
<select id="engine" name="engine">
|
||||
<option selected value="">ALL</option>
|
||||
<option value="" selected>All Engines</option>
|
||||
{% for name, data in config.engines.items %}
|
||||
<option value="{{name}}">{{name}}</option>
|
||||
{% endfor %}
|
||||
</select><br>
|
||||
</div>
|
||||
<br>
|
||||
<div class="row">
|
||||
<label>Show Greens</label>
|
||||
<select name="showgreens">
|
||||
<option selected value="True">True</option>
|
||||
<option value="False">False</option>
|
||||
<label>Opening Book</label>
|
||||
<select id="opening-book" name="opening-book">
|
||||
<option value="" selected>All Books</option>
|
||||
{% for name, data in config.books.items %}
|
||||
<option value="{{name}}">{{name}}</option>
|
||||
{% endfor %}
|
||||
</select><br>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label>Show Yellows</label>
|
||||
<select name="showyellows">
|
||||
<option selected value="True">True</option>
|
||||
<option value="False">False</option>
|
||||
<label>Test Mode</label>
|
||||
<select id="test-mode" name="test-mode">
|
||||
<option value="" selected>All Test Types</option>
|
||||
<option value="SPRT">SPRT</option>
|
||||
<option value="FIXED">FIXED</option>
|
||||
</select><br>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label>Show Reds</label>
|
||||
<select name="showreds">
|
||||
<option selected value="True">True</option>
|
||||
<option value="False">False</option>
|
||||
<label>Syzygy WDL</label>
|
||||
<select id="syzygy-wdl" name="syzygy-wdl">
|
||||
<option value="" selected>All Syzygy Configurations</option>
|
||||
<option value="DISABLED"> Disabled </option>
|
||||
<option value="OPTIONAL"> Optional </option>
|
||||
<option value="6-MAN"> 6-Man </option>
|
||||
<option value="5-MAN"> 5-Man </option>
|
||||
<option value="4-MAN"> 4-Man </option>
|
||||
<option value="3-MAN"> 3-Man </option>
|
||||
</select><br>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label>Show Stopped</label>
|
||||
<select name="showunfinished">
|
||||
<option value="True">True</option>
|
||||
<option selected value="False">False</option>
|
||||
<label>Time Type</label>
|
||||
<select id="tc-type" name="tc-type" onchange="changed_timecontrol()">
|
||||
<option value="" selected>All Time Controls</option>
|
||||
<option value="FIXED-DEPTH">Fixed Depth</option>
|
||||
<option value="FIXED-NODES">Fixed Nodes</option>
|
||||
<option value="FIXED-TIME">Fixed Time</option>
|
||||
<option value="FISCHER">Fischer</option>
|
||||
<option value="CYCLIC">Cyclic</option>
|
||||
</select><br>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label>Show Deleted</label>
|
||||
<select name="showdeleted">
|
||||
<option value="True">True</option>
|
||||
<option selected value="False">False</option>
|
||||
</select><br>
|
||||
<label>Time Value</label>
|
||||
<select id="tc-value-select" name="tc-value-select" style="margin-right: 8px; flex-grow: 0">
|
||||
<option value="=" selected>==</option>
|
||||
<option value=">=">>=</option>
|
||||
<option value="<="><=</option>
|
||||
</select>
|
||||
<input id="tc-value-input" name="tc-value-input"><br>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label>Threads</label>
|
||||
<select id="threads-select" name="threads-select" style="margin-right: 8px; flex-grow: 0">
|
||||
<option value="=">==</option>
|
||||
<option value=">=" selected>>=</option>
|
||||
<option value="<="><=</option>
|
||||
</select>
|
||||
<input id="threads-input" name="threads-input" value="1"><br>
|
||||
</div>
|
||||
<br>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<div class="row">
|
||||
<label>Greens</label>
|
||||
<input checked type="checkbox" id="show-greens" name="show-greens" value="">
|
||||
</div>
|
||||
<div class="row">
|
||||
<label>Blues</label>
|
||||
<input checked type="checkbox" id="show-blues" name="show-blues" value="">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col">
|
||||
<div class="row">
|
||||
<label>Yellows</label>
|
||||
<input checked type="checkbox" id="show-yellows" name="show-yellows" value="">
|
||||
</div>
|
||||
<div class="row">
|
||||
<label>Stopped</label>
|
||||
<input checked type="checkbox" id="show-stopped" name="show-stopped" value="">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col">
|
||||
<div class="row">
|
||||
<label>Reds</label>
|
||||
<input checked type="checkbox" id="show-reds" name="show-reds" value="">
|
||||
</div>
|
||||
<div class="row">
|
||||
<label>Deleted</label>
|
||||
<input type="checkbox" id="show-deleted" name="show-deleted" value="">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<input type="submit" class="anchorbutton btn-blue w-100" name="submit" value="Search Tests">
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
{% endif %}
|
||||
|
||||
<table class="test-list stripes hoverable">
|
||||
@@ -87,5 +153,4 @@
|
||||
{% include "OpenBench/Blocks/testsummary.html" %}
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
||||
{% endblock %}
|
||||
Reference in new issue
Block a user