Add UX layer: time control buckets, event/PGN parser, template filters, styles and scripts
This commit is contained in:
1 parent
f80349de11
commit
2b06146e7c
5 files changed
+1742
No files matched your search
@@ -0,0 +1,237 @@
|
||||
/* Event viewer: move navigation for PGNs, filtering for plain logs, and the
|
||||
copy / download buttons.
|
||||
|
||||
Hook for the board analyser: whenever the selected move changes, a
|
||||
CustomEvent named "ob:ply" is dispatched on document, with
|
||||
|
||||
event.detail = { ply: <index>, move: <move>, moves: <all moves> }
|
||||
|
||||
and window.OpenBenchViewer exposes { moves, select(ply), current() }. */
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
function $(id) { return document.getElementById(id); }
|
||||
|
||||
function readJSON(id, fallback) {
|
||||
var element = $(id);
|
||||
if (!element) return fallback;
|
||||
try { return JSON.parse(element.textContent); } catch (error) { return fallback; }
|
||||
}
|
||||
|
||||
var raw = readJSON('ev-raw', '');
|
||||
var moves = readJSON('ev-moves', []);
|
||||
var toastTimer = null;
|
||||
|
||||
function toast(message) {
|
||||
|
||||
var element = $('toast');
|
||||
if (!element) return;
|
||||
|
||||
element.textContent = message;
|
||||
element.classList.add('show');
|
||||
|
||||
window.clearTimeout(toastTimer);
|
||||
toastTimer = window.setTimeout(function () { element.classList.remove('show'); }, 1800);
|
||||
}
|
||||
|
||||
function copyText(text) {
|
||||
|
||||
if (navigator.clipboard && window.isSecureContext) return navigator.clipboard.writeText(text);
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
|
||||
var area = document.createElement('textarea');
|
||||
area.value = text;
|
||||
area.style.position = 'fixed';
|
||||
area.style.opacity = '0';
|
||||
document.body.appendChild(area);
|
||||
area.select();
|
||||
|
||||
try { document.execCommand('copy') ? resolve() : reject(); }
|
||||
catch (error) { reject(error); }
|
||||
finally { document.body.removeChild(area); }
|
||||
});
|
||||
}
|
||||
|
||||
function download(name, text) {
|
||||
|
||||
var url = URL.createObjectURL(new Blob([text], { type: 'text/plain;charset=utf-8' }));
|
||||
var link = document.createElement('a');
|
||||
|
||||
link.href = url;
|
||||
link.download = name;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
|
||||
window.setTimeout(function () { URL.revokeObjectURL(url); }, 1000);
|
||||
}
|
||||
|
||||
function bindActions() {
|
||||
|
||||
var copy = $('ev-copy'), save = $('ev-download');
|
||||
|
||||
if (copy) copy.addEventListener('click', function () {
|
||||
copyText(raw).then(function () { toast('Copied to clipboard'); }, function () { toast('Copy failed'); });
|
||||
});
|
||||
|
||||
if (save) save.addEventListener('click', function () {
|
||||
download(save.getAttribute('data-filename') || 'event.log', raw);
|
||||
});
|
||||
}
|
||||
|
||||
function setText(id, text) {
|
||||
var element = $(id);
|
||||
if (element) element.textContent = text;
|
||||
}
|
||||
|
||||
function initMoves() {
|
||||
|
||||
var list = $('ev-movelist');
|
||||
if (!list || !moves.length) return;
|
||||
|
||||
var buttons = {};
|
||||
var current = -1;
|
||||
|
||||
Array.prototype.forEach.call(list.querySelectorAll('.ev-move[data-ply]'), function (button) {
|
||||
buttons[button.getAttribute('data-ply')] = button;
|
||||
button.addEventListener('click', function () { select(parseInt(button.getAttribute('data-ply'), 10), false); });
|
||||
});
|
||||
|
||||
function select(ply, scroll) {
|
||||
|
||||
ply = Math.max(0, Math.min(moves.length - 1, ply));
|
||||
|
||||
var move = moves[ply];
|
||||
|
||||
if (buttons[current]) {
|
||||
buttons[current].classList.remove('is-active');
|
||||
buttons[current].removeAttribute('aria-selected');
|
||||
}
|
||||
|
||||
current = ply;
|
||||
|
||||
var button = buttons[ply];
|
||||
if (button) {
|
||||
button.classList.add('is-active');
|
||||
button.setAttribute('aria-selected', 'true');
|
||||
if (scroll !== false) {
|
||||
list.scrollTop = Math.max(0, button.offsetTop - list.clientHeight / 2 + button.offsetHeight / 2);
|
||||
}
|
||||
}
|
||||
|
||||
setText('sel-counter', 'Ply ' + (ply + 1) + ' / ' + moves.length);
|
||||
setText('sel-label', move.num + (move.color === 'w' ? '.' : '\u2026'));
|
||||
setText('sel-san', move.san);
|
||||
setText('sel-eval', move.eval || '\u2013');
|
||||
setText('sel-depth', move.depth || '\u2013');
|
||||
setText('sel-time', move.time || '\u2013');
|
||||
|
||||
var evalElement = $('sel-eval');
|
||||
if (evalElement) evalElement.className = 'mono ' + (move.tone || '');
|
||||
|
||||
var note = $('sel-note');
|
||||
if (note) {
|
||||
note.textContent = move.note || '';
|
||||
note.hidden = !move.note;
|
||||
}
|
||||
|
||||
['ev-first', 'ev-prev'].forEach(function (id) { if ($(id)) $(id).disabled = ply === 0; });
|
||||
['ev-next', 'ev-last'].forEach(function (id) { if ($(id)) $(id).disabled = ply === moves.length - 1; });
|
||||
|
||||
document.dispatchEvent(new CustomEvent('ob:ply', { detail: { ply: ply, move: move, moves: moves } }));
|
||||
}
|
||||
|
||||
function bind(id, handler) {
|
||||
if ($(id)) $(id).addEventListener('click', handler);
|
||||
}
|
||||
|
||||
bind('ev-first', function () { select(0); });
|
||||
bind('ev-prev', function () { select(current - 1); });
|
||||
bind('ev-next', function () { select(current + 1); });
|
||||
bind('ev-last', function () { select(moves.length - 1); });
|
||||
|
||||
document.addEventListener('keydown', function (event) {
|
||||
|
||||
if (event.altKey || event.ctrlKey || event.metaKey) return;
|
||||
if (/^(INPUT|TEXTAREA|SELECT)$/.test((event.target && event.target.tagName) || '')) return;
|
||||
|
||||
var handled = true;
|
||||
|
||||
switch (event.key) {
|
||||
case 'ArrowLeft': select(current - 1); break;
|
||||
case 'ArrowRight': select(current + 1); break;
|
||||
case 'Home': select(0); break;
|
||||
case 'End': select(moves.length - 1); break;
|
||||
default: handled = false;
|
||||
}
|
||||
|
||||
if (handled) event.preventDefault();
|
||||
});
|
||||
|
||||
window.OpenBenchViewer = {
|
||||
moves : moves,
|
||||
select : select,
|
||||
current : function () { return current; }
|
||||
};
|
||||
|
||||
// Start on the last move, which is usually the one that ended the game
|
||||
select(moves.length - 1);
|
||||
}
|
||||
|
||||
function initLog() {
|
||||
|
||||
var body = $('log-body');
|
||||
if (!body) return;
|
||||
|
||||
var filter = $('log-filter'), wrap = $('log-wrap'), issues = $('log-issues');
|
||||
var empty = $('log-empty');
|
||||
|
||||
var lines = Array.prototype.map.call(body.querySelectorAll('.ev-line'), function (line) {
|
||||
return {
|
||||
element : line,
|
||||
level : line.getAttribute('data-level'),
|
||||
text : line.querySelector('.ev-lt').textContent.toLowerCase()
|
||||
};
|
||||
});
|
||||
|
||||
function apply() {
|
||||
|
||||
var query = filter ? filter.value.trim().toLowerCase() : '';
|
||||
var only = issues ? issues.checked : false;
|
||||
var shown = 0;
|
||||
|
||||
lines.forEach(function (line) {
|
||||
var visible = (!query || line.text.indexOf(query) !== -1) && (!only || line.level !== 'info');
|
||||
line.element.hidden = !visible;
|
||||
if (visible) shown++;
|
||||
});
|
||||
|
||||
if (empty) empty.hidden = shown !== 0;
|
||||
}
|
||||
|
||||
if (filter) filter.addEventListener('input', apply);
|
||||
if (issues) issues.addEventListener('change', apply);
|
||||
|
||||
if (wrap) wrap.addEventListener('change', function () {
|
||||
body.classList.toggle('ev-wrap', wrap.checked);
|
||||
});
|
||||
|
||||
// Jump to the first problem, since that is what people came here for
|
||||
var first = body.querySelector('.ev-line-bad');
|
||||
if (first) body.scrollTop = Math.max(0, first.offsetTop - body.clientHeight / 3);
|
||||
}
|
||||
|
||||
function ready(fn) {
|
||||
if (document.readyState !== 'loading') fn();
|
||||
else document.addEventListener('DOMContentLoaded', fn);
|
||||
}
|
||||
|
||||
ready(function () {
|
||||
bindActions();
|
||||
initMoves();
|
||||
initLog();
|
||||
});
|
||||
|
||||
})();
|
||||
@@ -0,0 +1,903 @@
|
||||
/* ===========================================================================
|
||||
OpenBench - UX layer
|
||||
|
||||
Loaded after style.css and builds on its design tokens ( --color*, --accent,
|
||||
--line, ... ). Everything new lives here, so the base theme stays untouched
|
||||
and this file is easy to review, tweak, or drop.
|
||||
=========================================================================== */
|
||||
|
||||
:root {
|
||||
|
||||
/* Slightly softer corners than the base theme ( 2px ).
|
||||
Set this back to 2px to revert the rounding everywhere. */
|
||||
--radius: 4px;
|
||||
|
||||
--purple: #A78BFA;
|
||||
--purple-soft: rgba(167, 139, 250, 0.14);
|
||||
--shadow-card: inset 0 1px 0 rgba(255, 255, 255, 0.025), 0 1px 3px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
/* ---------- Depth + interaction polish ---------- */
|
||||
|
||||
.card {
|
||||
box-shadow: var(--shadow-card);
|
||||
}
|
||||
|
||||
#content table.hoverable tr:not(.table-header):not(.table-spacer):not(.table-spacer-small):hover > td:first-child {
|
||||
box-shadow: inset 2px 0 0 var(--accent);
|
||||
}
|
||||
|
||||
#content tr[data-href] {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
#content th.numeric {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
#content th.sorted {
|
||||
color: var(--color-font1);
|
||||
}
|
||||
|
||||
.muted-small {
|
||||
color: var(--muted);
|
||||
font-size: 12.5px;
|
||||
}
|
||||
|
||||
/* ---------- Sidebar: collapsible sections ---------- */
|
||||
|
||||
#sidebar .nav-title.collapsible {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
border-radius: var(--radius);
|
||||
}
|
||||
|
||||
#sidebar .nav-title.collapsible:hover {
|
||||
color: var(--color-font2);
|
||||
}
|
||||
|
||||
#sidebar .nav-title.collapsible::after {
|
||||
content: '';
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
margin-right: 4px;
|
||||
border-right: 1.5px solid currentColor;
|
||||
border-bottom: 1.5px solid currentColor;
|
||||
transform: rotate(45deg) translate(-1px, -1px);
|
||||
transition: transform 0.15s ease;
|
||||
}
|
||||
|
||||
#sidebar .nav-section.collapsed .nav-title.collapsible::after {
|
||||
transform: rotate(-45deg);
|
||||
}
|
||||
|
||||
#sidebar .nav-section.collapsed ul {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* ---------- Stat cards ---------- */
|
||||
|
||||
.stat-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
|
||||
gap: 12px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.stat-card {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 14px;
|
||||
min-width: 0;
|
||||
padding: 14px 16px;
|
||||
background-color: var(--color2);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: var(--radius);
|
||||
box-shadow: var(--shadow-card);
|
||||
}
|
||||
|
||||
.stat-icon {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
flex: none;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border-radius: var(--radius);
|
||||
background-color: var(--accent-soft);
|
||||
color: var(--accent-hover);
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.stat-green .stat-icon { background-color: rgba(52, 211, 153, 0.13); color: var(--ok); }
|
||||
.stat-yellow .stat-icon { background-color: rgba(245, 185, 65, 0.13); color: var(--warn); }
|
||||
.stat-purple .stat-icon { background-color: var(--purple-soft); color: var(--purple); }
|
||||
|
||||
.stat-value {
|
||||
color: var(--color-font1);
|
||||
font-family: var(--font-mono);
|
||||
font-size: 22px;
|
||||
font-weight: 650;
|
||||
line-height: 1.1;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
margin-top: 2px;
|
||||
color: var(--muted);
|
||||
font-size: 11.5px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.1em;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.stat-sub {
|
||||
margin-top: 2px;
|
||||
color: var(--muted);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
/* ---------- Test status dot + progress ---------- */
|
||||
|
||||
.status-dot {
|
||||
display: inline-block;
|
||||
flex: none;
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
margin-right: 9px;
|
||||
border-radius: 50%;
|
||||
background-color: var(--muted);
|
||||
vertical-align: middle;
|
||||
position: relative;
|
||||
top: -1px;
|
||||
}
|
||||
|
||||
.status-running { background-color: var(--accent); animation: ob-pulse 2s ease-out infinite; }
|
||||
.status-passed { background-color: var(--ok); }
|
||||
.status-failed { background-color: var(--bad); }
|
||||
.status-pending { background-color: var(--warn); }
|
||||
.status-awaiting { background-color: var(--purple);}
|
||||
.status-stopped,
|
||||
.status-deleted { background-color: #566074; }
|
||||
|
||||
@keyframes ob-pulse {
|
||||
0% { box-shadow: 0 0 0 0 rgba(76, 141, 255, 0.55); }
|
||||
70% { box-shadow: 0 0 0 7px rgba(76, 141, 255, 0); }
|
||||
100% { box-shadow: 0 0 0 0 rgba(76, 141, 255, 0); }
|
||||
}
|
||||
|
||||
.ob-progress {
|
||||
min-width: 96px;
|
||||
height: 3px;
|
||||
margin-top: 7px;
|
||||
border-radius: 2px;
|
||||
background-color: var(--line);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.ob-progress > span {
|
||||
display: block;
|
||||
height: 100%;
|
||||
border-radius: inherit;
|
||||
background-color: var(--accent);
|
||||
transition: width 0.4s ease;
|
||||
}
|
||||
|
||||
.ob-progress-pos > span { background-color: var(--ok); }
|
||||
.ob-progress-neg > span { background-color: var(--bad); }
|
||||
|
||||
/* ---------- Empty states ---------- */
|
||||
|
||||
#content .empty-row td {
|
||||
padding: 38px 14px;
|
||||
}
|
||||
|
||||
#content .empty-row i {
|
||||
display: block;
|
||||
margin-bottom: 10px;
|
||||
font-size: 24px;
|
||||
opacity: 0.55;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
padding: 52px 20px;
|
||||
color: var(--muted);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.empty-state i {
|
||||
display: block;
|
||||
margin-bottom: 12px;
|
||||
font-size: 28px;
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.empty-state p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
/* ---------- Segmented control ---------- */
|
||||
|
||||
.seg {
|
||||
display: inline-flex;
|
||||
gap: 2px;
|
||||
padding: 3px;
|
||||
background-color: var(--color2);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: calc(var(--radius) + 2px);
|
||||
}
|
||||
|
||||
#content a.seg-btn:link,
|
||||
#content a.seg-btn:visited {
|
||||
padding: 5px 13px;
|
||||
border-radius: var(--radius);
|
||||
color: var(--color-font2);
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
transition: background-color 0.15s ease, color 0.15s ease;
|
||||
}
|
||||
|
||||
#content a.seg-btn:hover {
|
||||
background-color: var(--surface-hover);
|
||||
color: var(--color-font1);
|
||||
}
|
||||
|
||||
#content a.seg-btn.active {
|
||||
background-color: var(--accent-soft);
|
||||
box-shadow: inset 0 0 0 1px rgba(76, 141, 255, 0.4);
|
||||
color: var(--color-font1);
|
||||
}
|
||||
|
||||
/* ---------- Users: STC / LTC split ---------- */
|
||||
|
||||
.splitbar {
|
||||
display: flex;
|
||||
min-width: 150px;
|
||||
height: 8px;
|
||||
border-radius: 4px;
|
||||
background-color: var(--line);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.splitbar-lg {
|
||||
height: 12px;
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.splitbar > span {
|
||||
display: block;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.splitbar-stc { background-color: var(--accent); }
|
||||
.splitbar-ltc { background-color: var(--purple); }
|
||||
.splitbar-other { background-color: #566074; }
|
||||
|
||||
.legend {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 4px 16px;
|
||||
color: var(--color-font2);
|
||||
font-size: 12.5px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.legend .dot {
|
||||
display: inline-block;
|
||||
width: 9px;
|
||||
height: 9px;
|
||||
margin-right: 7px;
|
||||
border-radius: 2px;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.dot-stc { background-color: var(--accent); }
|
||||
.dot-ltc { background-color: var(--purple); }
|
||||
.dot-other { background-color: #566074; }
|
||||
|
||||
.split-overview {
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.split-overview p {
|
||||
margin: 12px 0 0;
|
||||
}
|
||||
|
||||
#content td.num-stc { color: var(--accent-hover); }
|
||||
#content td.num-ltc { color: var(--purple); }
|
||||
|
||||
#content td.rank {
|
||||
width: 44px;
|
||||
color: var(--muted);
|
||||
font-family: var(--font-mono);
|
||||
}
|
||||
|
||||
/* ---------- Errors table ---------- */
|
||||
|
||||
#content a.ev-open:link,
|
||||
#content a.ev-open:visited {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 7px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
#content a.ev-open i {
|
||||
font-size: 11px;
|
||||
transition: transform 0.15s ease;
|
||||
}
|
||||
|
||||
#content tr:hover a.ev-open i {
|
||||
transform: translateX(3px);
|
||||
}
|
||||
|
||||
.tc-chip {
|
||||
margin-left: 8px;
|
||||
color: var(--muted);
|
||||
font-family: var(--font-mono);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
/* ---------- Event viewer ---------- */
|
||||
|
||||
#content a.crumb:link,
|
||||
#content a.crumb:visited {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-bottom: 8px;
|
||||
color: var(--muted);
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
#content a.crumb:hover {
|
||||
color: var(--color-font1);
|
||||
}
|
||||
|
||||
.ev-meta {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
|
||||
gap: 1px;
|
||||
margin: 0 0 20px;
|
||||
background-color: var(--line);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: var(--radius);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.ev-meta > div {
|
||||
min-width: 0;
|
||||
padding: 11px 14px;
|
||||
background-color: var(--color2);
|
||||
}
|
||||
|
||||
.ev-meta dt {
|
||||
margin-bottom: 4px;
|
||||
color: var(--muted);
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.1em;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.ev-meta dd {
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
color: var(--color-font1);
|
||||
font-size: 14px;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.ev-versus {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
padding: 24px 20px;
|
||||
}
|
||||
|
||||
.ev-player {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.ev-player strong {
|
||||
overflow: hidden;
|
||||
color: var(--color-font1);
|
||||
font-size: 18px;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.ev-player small {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 7px;
|
||||
color: var(--muted);
|
||||
font-size: 11.5px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.1em;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.ev-black {
|
||||
align-items: flex-end;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.ev-black small {
|
||||
flex-direction: row-reverse;
|
||||
}
|
||||
|
||||
.ev-piece {
|
||||
display: inline-block;
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
border: 1px solid var(--line-strong);
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.ev-white .ev-piece { background-color: #F1F4FA; }
|
||||
.ev-black .ev-piece { background-color: #0B0E14; }
|
||||
|
||||
.ev-result {
|
||||
padding: 6px 16px;
|
||||
background-color: var(--color1);
|
||||
border: 1px solid var(--line-strong);
|
||||
border-radius: var(--radius);
|
||||
color: var(--color-font1);
|
||||
font-size: 22px;
|
||||
font-weight: 650;
|
||||
}
|
||||
|
||||
.ev-callout {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 12px;
|
||||
margin: 0 20px 18px;
|
||||
padding: 12px 14px;
|
||||
background-color: var(--color1);
|
||||
border: 1px solid var(--line);
|
||||
border-left: 3px solid currentColor;
|
||||
border-radius: var(--radius);
|
||||
}
|
||||
|
||||
.ev-callout i {
|
||||
margin-top: 3px;
|
||||
}
|
||||
|
||||
.ev-callout-bad { color: var(--bad); }
|
||||
.ev-callout-warn { color: var(--warn); }
|
||||
.ev-callout-info { color: var(--accent); }
|
||||
|
||||
.ev-callout-body {
|
||||
min-width: 0;
|
||||
color: var(--color-font2);
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.ev-callout-body strong {
|
||||
display: block;
|
||||
color: var(--color-font1);
|
||||
}
|
||||
|
||||
.ev-facts {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px 32px;
|
||||
margin: 0;
|
||||
padding: 14px 20px 16px;
|
||||
border-top: 1px solid var(--line);
|
||||
}
|
||||
|
||||
.ev-facts > div {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.ev-facts dt {
|
||||
margin-bottom: 2px;
|
||||
color: var(--muted);
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.1em;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.ev-facts dd {
|
||||
margin: 0;
|
||||
color: var(--color-font1);
|
||||
font-size: 13px;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.ev-headers {
|
||||
border-top: 1px solid var(--line);
|
||||
}
|
||||
|
||||
.ev-headers summary {
|
||||
padding: 11px 20px;
|
||||
color: var(--muted);
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.ev-headers summary:hover {
|
||||
color: var(--color-font1);
|
||||
}
|
||||
|
||||
.ev-headers table {
|
||||
width: 100%;
|
||||
margin: 0 0 8px;
|
||||
}
|
||||
|
||||
.ev-headers td:first-child {
|
||||
width: 180px;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.ev-grid {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) 360px;
|
||||
gap: 20px;
|
||||
align-items: start;
|
||||
}
|
||||
|
||||
.ev-grid .card {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.ev-side {
|
||||
position: sticky;
|
||||
top: calc(var(--topbar-h) + 16px);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.ev-movelist {
|
||||
position: relative;
|
||||
max-height: 580px;
|
||||
padding: 8px;
|
||||
overflow-y: auto;
|
||||
font-family: var(--font-mono);
|
||||
font-size: 13px;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.ev-row {
|
||||
display: grid;
|
||||
grid-template-columns: 46px minmax(0, 1fr) minmax(0, 1fr);
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.ev-num {
|
||||
padding: 7px 8px;
|
||||
color: var(--muted);
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.ev-move {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 10px;
|
||||
padding: 7px 10px;
|
||||
background: transparent;
|
||||
border: 1px solid transparent;
|
||||
border-radius: var(--radius);
|
||||
color: var(--color-font1);
|
||||
font: inherit;
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.12s ease;
|
||||
}
|
||||
|
||||
button.ev-move:hover {
|
||||
background-color: var(--surface-hover);
|
||||
}
|
||||
|
||||
.ev-move.is-active {
|
||||
background-color: var(--accent-soft);
|
||||
border-color: rgba(76, 141, 255, 0.45);
|
||||
}
|
||||
|
||||
.ev-move.is-final {
|
||||
box-shadow: inset 2px 0 0 var(--bad);
|
||||
}
|
||||
|
||||
.ev-move.ev-empty {
|
||||
color: var(--muted);
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.ev-eval {
|
||||
color: var(--muted);
|
||||
font-size: 11.5px;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
.ev-eval.pos, #sel-eval.pos { color: var(--ok); }
|
||||
.ev-eval.neg, #sel-eval.neg { color: var(--bad); }
|
||||
|
||||
.ev-sel {
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.ev-sel-main {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.ev-sel-label {
|
||||
color: var(--muted);
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
.ev-sel-san {
|
||||
color: var(--color-font1);
|
||||
font-size: 28px;
|
||||
font-weight: 650;
|
||||
}
|
||||
|
||||
.ev-sel-stats {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
gap: 8px;
|
||||
margin-top: 14px;
|
||||
}
|
||||
|
||||
.ev-sel-stats > div {
|
||||
padding: 9px 11px;
|
||||
background-color: var(--color1);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: var(--radius);
|
||||
}
|
||||
|
||||
.ev-sel-stats span {
|
||||
display: block;
|
||||
margin-bottom: 2px;
|
||||
color: var(--muted);
|
||||
font-size: 10.5px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.1em;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.ev-sel-stats strong {
|
||||
color: var(--color-font1);
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.ev-sel-note {
|
||||
margin: 12px 0 0;
|
||||
padding: 9px 11px;
|
||||
border-left: 3px solid var(--warn);
|
||||
border-radius: var(--radius);
|
||||
background-color: rgba(245, 185, 65, 0.08);
|
||||
color: var(--color-font2);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.ev-sel-note[hidden] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.ev-nav {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, 1fr);
|
||||
gap: 6px;
|
||||
margin-top: 14px;
|
||||
}
|
||||
|
||||
.ev-nav button:disabled {
|
||||
opacity: 0.4;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.ev-hint {
|
||||
margin: 12px 0 0;
|
||||
color: var(--muted);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.ev-hint kbd {
|
||||
display: inline-block;
|
||||
min-width: 20px;
|
||||
padding: 1px 6px;
|
||||
background-color: var(--color3);
|
||||
border: 1px solid var(--line-strong);
|
||||
border-bottom-width: 2px;
|
||||
border-radius: var(--radius);
|
||||
color: var(--color-font2);
|
||||
font: 11px var(--font-mono);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* Reserved for the board analyser. It listens for the "ob:ply" event that
|
||||
event_viewer.js dispatches whenever the selected move changes. */
|
||||
|
||||
.ev-board {
|
||||
position: relative;
|
||||
aspect-ratio: 1;
|
||||
margin: 16px;
|
||||
border: 1px solid var(--line-strong);
|
||||
border-radius: var(--radius);
|
||||
background: repeating-conic-gradient(#1B2230 0 25%, #131925 0 50%) 0 0 / 25% 25%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.ev-board-msg {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 6px;
|
||||
padding: 24px;
|
||||
background-color: rgba(11, 14, 20, 0.72);
|
||||
color: var(--muted);
|
||||
font-size: 13px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.ev-board-msg i {
|
||||
margin-bottom: 4px;
|
||||
font-size: 30px;
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
.ev-board-msg strong {
|
||||
color: var(--color-font1);
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
/* Plain text logs */
|
||||
|
||||
.ev-tools {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 8px 14px;
|
||||
}
|
||||
|
||||
.ev-input {
|
||||
width: 220px;
|
||||
max-width: 100%;
|
||||
padding: 6px 10px;
|
||||
background-color: var(--color1);
|
||||
border: 1px solid var(--line-strong);
|
||||
border-radius: var(--radius);
|
||||
color: var(--color-font1);
|
||||
font-family: var(--font-sans);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.ev-input::placeholder {
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.ev-toggle {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
color: var(--color-font2);
|
||||
font-size: 12.5px;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.ev-logbody {
|
||||
max-height: 70vh;
|
||||
padding: 8px 0;
|
||||
overflow: auto;
|
||||
background-color: var(--color1);
|
||||
font-family: var(--font-mono);
|
||||
font-size: 12.5px;
|
||||
line-height: 1.55;
|
||||
}
|
||||
|
||||
.ev-line {
|
||||
display: flex;
|
||||
gap: 14px;
|
||||
padding: 0 14px;
|
||||
border-left: 2px solid transparent;
|
||||
}
|
||||
|
||||
.ev-line[hidden] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.ev-line:hover {
|
||||
background-color: var(--surface-hover);
|
||||
}
|
||||
|
||||
.ev-ln {
|
||||
flex: 0 0 48px;
|
||||
color: #4A5469;
|
||||
text-align: right;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.ev-lt {
|
||||
min-height: 1.55em;
|
||||
color: var(--color-font2);
|
||||
white-space: pre;
|
||||
}
|
||||
|
||||
.ev-wrap .ev-lt {
|
||||
min-width: 0;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.ev-line-bad { background-color: rgba(248, 113, 113, 0.08); border-left-color: var(--bad); }
|
||||
.ev-line-warn { background-color: rgba(245, 185, 65, 0.07); border-left-color: var(--warn); }
|
||||
.ev-line-bad .ev-lt { color: #FFB4B4; }
|
||||
.ev-line-warn .ev-lt { color: #FFD479; }
|
||||
|
||||
.ev-log-note {
|
||||
padding: 8px 14px;
|
||||
border-bottom: 1px solid var(--line);
|
||||
color: var(--muted);
|
||||
font-size: 12.5px;
|
||||
}
|
||||
|
||||
/* ---------- Responsive ---------- */
|
||||
|
||||
@media (max-width: 1100px) {
|
||||
|
||||
.ev-grid {
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
}
|
||||
|
||||
.ev-side {
|
||||
position: static;
|
||||
order: -1;
|
||||
}
|
||||
|
||||
.ev-board-card {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 767px) {
|
||||
|
||||
.ev-versus {
|
||||
grid-template-columns: 1fr;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.ev-black {
|
||||
align-items: flex-start;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.ev-black small {
|
||||
flex-direction: row;
|
||||
}
|
||||
|
||||
.ev-result {
|
||||
justify-self: start;
|
||||
}
|
||||
|
||||
.ev-meta dd {
|
||||
white-space: normal;
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
|
||||
.status-running {
|
||||
animation: none;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
/* OpenBench UX layer: small progressive enhancements, no dependencies.
|
||||
Every feature degrades gracefully when this file does not load. */
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
function ready(fn) {
|
||||
if (document.readyState !== 'loading') fn();
|
||||
else document.addEventListener('DOMContentLoaded', fn);
|
||||
}
|
||||
|
||||
function normalise(path) {
|
||||
path = (path || '').replace(/\/+$/, '');
|
||||
return path === '' ? '/' : path.toLowerCase();
|
||||
}
|
||||
|
||||
/* Highlight the sidebar entry for the current page. Pages that live under
|
||||
another section ( an event belongs to Errors or Events ) can say so with
|
||||
a data-nav="/errors" attribute anywhere in their content. */
|
||||
|
||||
function highlightNav() {
|
||||
|
||||
var nav = document.getElementById('sidebar');
|
||||
if (!nav) return;
|
||||
|
||||
var hint = document.querySelector('[data-nav]');
|
||||
var current = normalise(hint ? hint.getAttribute('data-nav') : window.location.pathname);
|
||||
|
||||
if (current === '/' || /^\/index(\/|$)/.test(current)) current = '/index';
|
||||
|
||||
var best = null, bestLength = -1;
|
||||
|
||||
Array.prototype.forEach.call(nav.querySelectorAll('li a'), function (link) {
|
||||
|
||||
if (link.origin !== window.location.origin) return;
|
||||
|
||||
var path = normalise(link.pathname);
|
||||
var hit = current === path || current.indexOf(path + '/') === 0;
|
||||
|
||||
if (hit && path.length > bestLength) { best = link; bestLength = path.length; }
|
||||
});
|
||||
|
||||
if (best) {
|
||||
best.classList.add('active');
|
||||
best.setAttribute('aria-current', 'page');
|
||||
}
|
||||
}
|
||||
|
||||
/* Sidebar sections can be folded, and the choice is remembered. The list of
|
||||
Engines starts folded, since it grows with every engine added. */
|
||||
|
||||
function collapsibleNav() {
|
||||
|
||||
var KEY = 'ob:nav:collapsed';
|
||||
var collapsed = ['Engines'];
|
||||
|
||||
try {
|
||||
var stored = JSON.parse(window.localStorage.getItem(KEY));
|
||||
if (Array.isArray(stored)) collapsed = stored;
|
||||
} catch (error) { /* storage unavailable, use the default */ }
|
||||
|
||||
Array.prototype.forEach.call(document.querySelectorAll('#sidebar .nav-section'), function (section) {
|
||||
|
||||
var title = section.querySelector('.nav-title');
|
||||
if (!title) return;
|
||||
|
||||
var name = title.textContent.trim();
|
||||
|
||||
title.classList.add('collapsible');
|
||||
title.setAttribute('role', 'button');
|
||||
title.setAttribute('tabindex', '0');
|
||||
|
||||
function apply(state) {
|
||||
section.classList.toggle('collapsed', state);
|
||||
title.setAttribute('aria-expanded', String(!state));
|
||||
}
|
||||
|
||||
// Never hide the section that holds the current page
|
||||
apply(collapsed.indexOf(name) !== -1 && !section.querySelector('a.active'));
|
||||
|
||||
function toggle() {
|
||||
|
||||
var state = !section.classList.contains('collapsed');
|
||||
var index = collapsed.indexOf(name);
|
||||
|
||||
apply(state);
|
||||
|
||||
if (state && index === -1) collapsed.push(name);
|
||||
if (!state && index !== -1) collapsed.splice(index, 1);
|
||||
|
||||
try { window.localStorage.setItem(KEY, JSON.stringify(collapsed)); } catch (error) { /* ignore */ }
|
||||
}
|
||||
|
||||
title.addEventListener('click', toggle);
|
||||
title.addEventListener('keydown', function (event) {
|
||||
if (event.key === 'Enter' || event.key === ' ') { event.preventDefault(); toggle(); }
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/* Browser tabs say what the page is, instead of "RektBench" everywhere */
|
||||
|
||||
function setPageTitle() {
|
||||
|
||||
var heading = document.querySelector('.page-title');
|
||||
var brand = document.querySelector('.brand-name');
|
||||
if (!heading) return;
|
||||
|
||||
var name = brand ? brand.textContent.trim() : 'OpenBench';
|
||||
document.title = heading.textContent.trim() + ' \u00B7 ' + name;
|
||||
}
|
||||
|
||||
/* Whole rows of the test lists are clickable. Real links, buttons, and text
|
||||
selection keep working as usual. */
|
||||
|
||||
function clickableRows() {
|
||||
|
||||
var rows = document.querySelectorAll('#content table.test-list tbody tr');
|
||||
|
||||
Array.prototype.forEach.call(rows, function (row) {
|
||||
var link = row.querySelector('.col-test a');
|
||||
if (link && !row.getAttribute('data-href')) row.setAttribute('data-href', link.getAttribute('href'));
|
||||
});
|
||||
|
||||
document.addEventListener('click', function (event) {
|
||||
|
||||
if (event.defaultPrevented || !event.target.closest) return;
|
||||
|
||||
var row = event.target.closest('tr[data-href]');
|
||||
if (!row) return;
|
||||
|
||||
if (event.target.closest('a, button, input, select, textarea, label, summary')) return;
|
||||
if (window.getSelection && String(window.getSelection())) return;
|
||||
|
||||
var href = row.getAttribute('data-href');
|
||||
|
||||
if (event.metaKey || event.ctrlKey) window.open(href, '_blank');
|
||||
else window.location.href = href;
|
||||
});
|
||||
}
|
||||
|
||||
ready(function () {
|
||||
highlightNav();
|
||||
collapsibleNav();
|
||||
setPageTitle();
|
||||
clickableRows();
|
||||
});
|
||||
|
||||
})();
|
||||
@@ -0,0 +1,86 @@
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
# #
|
||||
# Template filters for the UX layer ( status dots, progress bars, ... ). #
|
||||
# Kept apart from mytags.py. Use with {% load uitags %} #
|
||||
# #
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
|
||||
import re
|
||||
|
||||
from django import template
|
||||
|
||||
from OpenBench.uiutils import event_tone
|
||||
|
||||
register = template.Library()
|
||||
|
||||
@register.filter
|
||||
def test_status(test):
|
||||
|
||||
# One of: running, pending, awaiting, passed, failed, stopped, deleted
|
||||
|
||||
if test.deleted:
|
||||
return 'deleted'
|
||||
|
||||
if test.finished:
|
||||
if test.passed: return 'passed'
|
||||
if test.failed: return 'failed'
|
||||
return 'stopped'
|
||||
|
||||
if not test.approved:
|
||||
return 'pending'
|
||||
|
||||
if test.awaiting:
|
||||
return 'awaiting'
|
||||
|
||||
return 'running'
|
||||
|
||||
@register.filter
|
||||
def progress_info(test):
|
||||
|
||||
# Only running tests get a progress bar. Returns None, or a dict holding the
|
||||
# percentage and a tone: pos ( leaning to a pass ), neg ( leaning to a fail ),
|
||||
# or neutral ( for tests without a meaningful direction )
|
||||
|
||||
if test_status(test) != 'running':
|
||||
return None
|
||||
|
||||
try:
|
||||
|
||||
if test.test_mode == 'SPRT':
|
||||
|
||||
current, lower, upper = float(test.currentllr), float(test.lowerllr), float(test.upperllr)
|
||||
|
||||
if current >= 0 and upper > 0:
|
||||
fraction, tone = current / upper, 'pos' if current > 0 else 'neutral'
|
||||
elif current < 0 and lower < 0:
|
||||
fraction, tone = current / lower, 'neg'
|
||||
else:
|
||||
fraction, tone = 0.0, 'neutral'
|
||||
|
||||
return { 'pct' : int(max(0.0, min(1.0, fraction)) * 100), 'tone' : tone }
|
||||
|
||||
if test.max_games:
|
||||
fraction = test.games / float(test.max_games)
|
||||
return { 'pct' : int(max(0.0, min(1.0, fraction)) * 100), 'tone' : 'neutral' }
|
||||
|
||||
except (TypeError, ValueError, ZeroDivisionError):
|
||||
pass
|
||||
|
||||
return None
|
||||
|
||||
@register.filter
|
||||
def fleet_stats(status):
|
||||
|
||||
# Parses the string from utils.getMachineStatus(), which looks like
|
||||
# ": 3 Machines / 48 Threads / 12.5 MNPS "
|
||||
|
||||
match = re.search(r'(\d+)\s+Machines\s*/\s*(\d+)\s+Threads\s*/\s*([\d.]+)\s+MNPS', status or '')
|
||||
|
||||
if not match:
|
||||
return None
|
||||
|
||||
return { 'machines' : int(match.group(1)), 'threads' : int(match.group(2)), 'mnps' : match.group(3) }
|
||||
|
||||
@register.filter(name='event_tone')
|
||||
def event_tone_filter(summary):
|
||||
return event_tone(summary)
|
||||
@@ -0,0 +1,367 @@
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
# #
|
||||
# UI helpers for the OpenBench website. #
|
||||
# #
|
||||
# Kept out of views.py / utils.py so the presentation logic ( time control #
|
||||
# buckets, PGN and log parsing for the event viewer ) is easy to find, #
|
||||
# test, and extend. Nothing in here touches the database schema. #
|
||||
# #
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
|
||||
import re
|
||||
|
||||
from functools import lru_cache
|
||||
|
||||
from django.db.models import Sum
|
||||
|
||||
from OpenBench.models import Profile, Result
|
||||
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
# TIME CONTROLS #
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
|
||||
# Fischer time controls with a base time below this many seconds are STC, and
|
||||
# anything at or above it is LTC. ( 10+0.1 is STC, 60+0.6 is LTC )
|
||||
STC_MAX_BASE_SECONDS = 30
|
||||
|
||||
BUCKETS = ('STC', 'LTC', 'OTHER')
|
||||
|
||||
@lru_cache(maxsize=512)
|
||||
def classify_time_control(time_control):
|
||||
|
||||
# Imported here, since utils.py imports views.py which imports this module
|
||||
from OpenBench.utils import TimeControl
|
||||
|
||||
try:
|
||||
tc = str(time_control or '')
|
||||
|
||||
# Fixed nodes, depth, movetime, and cyclic controls are not STC or LTC
|
||||
if TimeControl.control_type(tc) != TimeControl.FISCHER:
|
||||
return 'OTHER'
|
||||
|
||||
base = TimeControl.control_base(tc)
|
||||
return 'STC' if base < STC_MAX_BASE_SECONDS else 'LTC'
|
||||
|
||||
except Exception:
|
||||
return 'OTHER'
|
||||
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
# USERS PAGE #
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
|
||||
SORT_KEYS = {
|
||||
'total' : lambda row: (-row['total'], -row['tests']),
|
||||
'stc' : lambda row: (-row['stc' ], -row['total']),
|
||||
'ltc' : lambda row: (-row['ltc' ], -row['total']),
|
||||
'tests' : lambda row: (-row['tests'], -row['total']),
|
||||
}
|
||||
|
||||
def _share(part, whole):
|
||||
# Returned as a string, so templates never localise it into "63,20"
|
||||
return '%.2f' % (100.0 * part / whole) if whole else '0.00'
|
||||
|
||||
def users_context(request):
|
||||
|
||||
sort = request.GET.get('sort', 'total')
|
||||
if sort not in SORT_KEYS:
|
||||
sort = 'total'
|
||||
|
||||
# Games are credited to whoever's machines played them, which is not
|
||||
# necessarily the author of the test. Results hold one row per (test, machine)
|
||||
# so grouping by user and time control in the database stays cheap.
|
||||
|
||||
per_user = {}
|
||||
grouped = Result.objects.values('machine__user__username', 'test__dev_time_control')
|
||||
grouped = grouped.annotate(total=Sum('games'))
|
||||
|
||||
for entry in grouped:
|
||||
buckets = per_user.setdefault(entry['machine__user__username'], dict.fromkeys(BUCKETS, 0))
|
||||
buckets[classify_time_control(entry['test__dev_time_control'])] += entry['total'] or 0
|
||||
|
||||
rows = []
|
||||
for profile in Profile.objects.select_related('user'):
|
||||
|
||||
if not (profile.games or profile.tests or profile.approver):
|
||||
continue
|
||||
|
||||
buckets = per_user.get(profile.user.username, dict.fromkeys(BUCKETS, 0))
|
||||
split = sum(buckets.values())
|
||||
|
||||
rows.append({
|
||||
'username' : profile.user.username,
|
||||
'approver' : profile.approver,
|
||||
'engine' : profile.engine,
|
||||
'joined' : profile.user.date_joined,
|
||||
'total' : profile.games,
|
||||
'tests' : profile.tests,
|
||||
'stc' : buckets['STC' ],
|
||||
'ltc' : buckets['LTC' ],
|
||||
'other' : buckets['OTHER'],
|
||||
'stc_share' : _share(buckets['STC' ], split),
|
||||
'ltc_share' : _share(buckets['LTC' ], split),
|
||||
'oth_share' : _share(buckets['OTHER'], split),
|
||||
})
|
||||
|
||||
rows.sort(key=lambda row: SORT_KEYS[sort](row) + (row['username'].lower(),))
|
||||
|
||||
stc = sum(row['stc' ] for row in rows)
|
||||
ltc = sum(row['ltc' ] for row in rows)
|
||||
other = sum(row['other'] for row in rows)
|
||||
whole = stc + ltc + other
|
||||
|
||||
summary = {
|
||||
'users' : len(rows),
|
||||
'total' : sum(row['total'] for row in rows),
|
||||
'stc' : stc,
|
||||
'ltc' : ltc,
|
||||
'other' : other,
|
||||
'stc_share' : _share(stc, whole),
|
||||
'ltc_share' : _share(ltc, whole),
|
||||
'oth_share' : _share(other, whole),
|
||||
}
|
||||
|
||||
return {
|
||||
'rows' : rows,
|
||||
'summary' : summary,
|
||||
'sort' : sort,
|
||||
'show_other' : other > 0,
|
||||
'stc_limit' : STC_MAX_BASE_SECONDS,
|
||||
}
|
||||
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
# EVENT VIEWER #
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
|
||||
def event_tone(summary):
|
||||
|
||||
# Colour used for badges: bad ( red ), warn ( amber ), info ( blue )
|
||||
text = (summary or '').lower()
|
||||
|
||||
bad = ('illegal', 'disconnect', 'crash', 'fail', 'bad bench', 'missing', 'error')
|
||||
if any(word in text for word in bad):
|
||||
return 'bad'
|
||||
|
||||
if any(word in text for word in ('stall', 'timeout', 'timeloss', 'warn')):
|
||||
return 'warn'
|
||||
|
||||
return 'info'
|
||||
|
||||
# When a worker reports an Illegal Move, Disconnect, or Stalled game, the client
|
||||
# uploads the PGN of that game ( see PGNHelper.pretty_format in Client/worker.py ).
|
||||
# Other events ( build failures, bad benches, ... ) carry plain text logs.
|
||||
|
||||
PGN_PROBE_RE = re.compile(r'^\s*\[Event\s+"', re.MULTILINE)
|
||||
HEADER_RE = re.compile(r'^\[(\w+)\s+"(.*)"\]\s*$')
|
||||
TOKEN_RE = re.compile(r'\{[^}]*\}|\([^)]*\)|\$\d+|\d+\.(?:\.\.)?|1-0|0-1|1/2-1/2|\*|[^\s{}()]+')
|
||||
NUMBER_RE = re.compile(r'^\d+\.(?:\.\.)?$')
|
||||
EVAL_RE = re.compile(r'^(?P<score>[+-]?(?:M\d+|\d+(?:\.\d+)?))/(?P<depth>\d+)(?:\s+(?P<time>\d+(?:\.\d+)?)s)?')
|
||||
|
||||
RESULT_TOKENS = ('1-0', '0-1', '1/2-1/2', '*')
|
||||
|
||||
def _eval_tone(score):
|
||||
|
||||
if score.startswith('-'):
|
||||
return 'neg'
|
||||
|
||||
if score.lstrip('+') in ('0', '0.0', '0.00'):
|
||||
return ''
|
||||
|
||||
return 'pos'
|
||||
|
||||
def parse_pgn(text):
|
||||
|
||||
# Split the first game into its headers, and its movetext
|
||||
|
||||
headers, body, reading_headers = [], [], True
|
||||
|
||||
for raw in text.splitlines():
|
||||
line = raw.strip()
|
||||
|
||||
if body and line.startswith('[Event '):
|
||||
break # A second game, which we do not show
|
||||
|
||||
if reading_headers:
|
||||
match = HEADER_RE.match(line)
|
||||
if match:
|
||||
headers.append((match.group(1), match.group(2)))
|
||||
continue
|
||||
if not line:
|
||||
reading_headers = not headers
|
||||
continue
|
||||
reading_headers = False
|
||||
|
||||
if line:
|
||||
body.append(line)
|
||||
|
||||
header_map = dict(headers)
|
||||
|
||||
# Games from a FEN, or from a Black to move book entry, number differently
|
||||
|
||||
start_black, first_number = False, 1
|
||||
fen = header_map.get('FEN', '')
|
||||
|
||||
if fen:
|
||||
fields = fen.split()
|
||||
start_black = len(fields) >= 2 and fields[1] == 'b'
|
||||
if len(fields) >= 6 and fields[5].isdigit():
|
||||
first_number = int(fields[5])
|
||||
|
||||
moves, final_note = [], ''
|
||||
|
||||
for token in TOKEN_RE.findall(' '.join(body)):
|
||||
|
||||
if token.startswith('{'):
|
||||
|
||||
comment = token[1:-1].strip()
|
||||
if not comment or not moves:
|
||||
continue
|
||||
|
||||
match = EVAL_RE.match(comment)
|
||||
|
||||
if match:
|
||||
score = match.group('score')
|
||||
if score[0] not in '+-':
|
||||
score = '+' + score
|
||||
moves[-1]['eval' ] = score
|
||||
moves[-1]['tone' ] = _eval_tone(score)
|
||||
moves[-1]['depth'] = match.group('depth')
|
||||
moves[-1]['time' ] = (match.group('time') or '') and match.group('time') + 's'
|
||||
|
||||
elif comment.lower() == 'book':
|
||||
moves[-1]['eval'] = 'book'
|
||||
|
||||
else:
|
||||
final_note = comment
|
||||
if not moves[-1]['note']:
|
||||
moves[-1]['note'] = comment
|
||||
|
||||
continue
|
||||
|
||||
# Variations, NAGs, move numbers, and results are not moves
|
||||
if token.startswith(('(', '$')) or token in RESULT_TOKENS or NUMBER_RE.match(token):
|
||||
continue
|
||||
|
||||
index = len(moves) + (1 if start_black else 0)
|
||||
|
||||
moves.append({
|
||||
'ply' : len(moves),
|
||||
'num' : first_number + index // 2,
|
||||
'color' : 'w' if index % 2 == 0 else 'b',
|
||||
'san' : token,
|
||||
'eval' : '',
|
||||
'tone' : '',
|
||||
'depth' : '',
|
||||
'time' : '',
|
||||
'note' : '',
|
||||
'final' : False,
|
||||
})
|
||||
|
||||
if moves:
|
||||
moves[-1]['final'] = True
|
||||
|
||||
# One row per full move, for the move list
|
||||
|
||||
rows = []
|
||||
for move in moves:
|
||||
if not rows or rows[-1]['num'] != move['num']:
|
||||
rows.append({ 'num' : move['num'], 'w' : None, 'b' : None })
|
||||
rows[-1][move['color']] = move
|
||||
|
||||
return {
|
||||
'white' : header_map.get('White', '?'),
|
||||
'black' : header_map.get('Black', '?'),
|
||||
'result' : header_map.get('Result', '*'),
|
||||
'termination' : header_map.get('Termination', ''),
|
||||
'time_control' : header_map.get('TimeControl', ''),
|
||||
'date' : header_map.get('Date', ''),
|
||||
'duration' : header_map.get('GameDuration', ''),
|
||||
'fen' : fen,
|
||||
'headers' : headers,
|
||||
'rows' : rows,
|
||||
'moves' : moves,
|
||||
'ply_count' : len(moves),
|
||||
'final_note' : final_note,
|
||||
}
|
||||
|
||||
# Plain text logs ( compiler output, bench failures, ... )
|
||||
|
||||
MAX_LOG_LINES = 5000
|
||||
|
||||
CLEAN_RE = re.compile(r'\b0\s+(errors?|warnings?)\b', re.IGNORECASE)
|
||||
ERROR_RE = re.compile(
|
||||
r'\b(errors?|fatal|failed|failure|undefined reference|segmentation fault|traceback|exception|illegal move)\b',
|
||||
re.IGNORECASE)
|
||||
WARN_RE = re.compile(r'\b(warnings?|deprecated|stalled|timed? ?out|disconnect\w*)\b', re.IGNORECASE)
|
||||
|
||||
def classify_log_line(text):
|
||||
|
||||
if CLEAN_RE.search(text):
|
||||
return 'info'
|
||||
|
||||
if ERROR_RE.search(text):
|
||||
return 'bad'
|
||||
|
||||
if WARN_RE.search(text):
|
||||
return 'warn'
|
||||
|
||||
return 'info'
|
||||
|
||||
def parse_log(content):
|
||||
|
||||
lines = content.splitlines()
|
||||
total = len(lines)
|
||||
skipped = max(0, total - MAX_LOG_LINES) # Errors are usually at the end
|
||||
lines = lines[skipped:]
|
||||
|
||||
parsed, errors, warnings = [], 0, 0
|
||||
|
||||
for number, text in enumerate(lines, start=skipped + 1):
|
||||
level = classify_log_line(text)
|
||||
errors += level == 'bad'
|
||||
warnings += level == 'warn'
|
||||
parsed.append({ 'n' : number, 'text' : text, 'level' : level })
|
||||
|
||||
return {
|
||||
'lines' : parsed,
|
||||
'total' : total,
|
||||
'errors' : errors,
|
||||
'warnings' : warnings,
|
||||
'skipped' : skipped,
|
||||
}
|
||||
|
||||
def event_context(event, content):
|
||||
|
||||
kind = 'empty'
|
||||
if content and content.strip():
|
||||
kind = 'pgn' if PGN_PROBE_RE.search(content) else 'log'
|
||||
|
||||
context = {
|
||||
'event' : event,
|
||||
'content' : content,
|
||||
'kind' : kind,
|
||||
'tone' : event_tone(event.summary),
|
||||
'back_url' : '/errors/' if event.machine_id else '/events/',
|
||||
'back_label' : 'Errors' if event.machine_id else 'Events',
|
||||
'game' : None,
|
||||
'moves_json' : [],
|
||||
'log' : None,
|
||||
'download_name' : 'event%d.%s' % (event.id, 'pgn' if kind == 'pgn' else 'log'),
|
||||
}
|
||||
|
||||
try:
|
||||
if kind == 'pgn':
|
||||
context['game'] = parse_pgn(content)
|
||||
context['moves_json'] = context['game']['moves']
|
||||
|
||||
elif kind == 'log':
|
||||
context['log'] = parse_log(content)
|
||||
|
||||
except Exception:
|
||||
|
||||
# A strange log should never break the page. Fall back to plain text
|
||||
context['kind'] = 'log'
|
||||
context['game'] = None
|
||||
context['moves_json'] = []
|
||||
context['log'] = parse_log(content)
|
||||
|
||||
return context
|
||||
Reference in new issue
Block a user