/* Buildless UI. Email delivery is opt-in through submission-config.js. */ (() => { "use strict"; const $ = (selector, root = document) => root.querySelector(selector); const $$ = (selector, root = document) => [...root.querySelectorAll(selector)]; const escapeHTML = value => String(value).replace(/[&<>"']/g, character => ({"&":"&", "<":"<", ">":">", '"':""", "'":"'"}[character])); const leaderboard = window.TERN_LEADERBOARD; const logo = ''; const brand = `${logo}TERN`; const links = [{id:"overview",name:"About",href:"#overview"},{id:"leaderboard",name:"Leaderboard",href:"#leaderboard"},{id:"dataset",name:"Dataset",href:"#dataset"},{id:"examples",name:"Examples",href:"#examples"}]; const header = $("[data-site-header]"); header.className = "site-header"; header.innerHTML = `
${brand}
`; const menuButton = $(".mobile-menu-button"); function closeMenu() { $(".site-nav").classList.remove("is-open"); menuButton.setAttribute("aria-expanded", "false"); menuButton.setAttribute("aria-label", "Open navigation"); menuButton.textContent = "☰"; } menuButton.addEventListener("click", () => { const open = menuButton.getAttribute("aria-expanded") !== "true"; $(".site-nav").classList.toggle("is-open", open); menuButton.setAttribute("aria-expanded", String(open)); menuButton.setAttribute("aria-label", open ? "Close navigation" : "Open navigation"); menuButton.textContent = open ? "×" : "☰"; }); document.addEventListener("keydown", event => { if (event.key === "Escape" && menuButton.getAttribute("aria-expanded") === "true") { closeMenu(); menuButton.focus(); } }); document.addEventListener("click", event => { if (!header.contains(event.target)) closeMenu(); }); matchMedia("(max-width: 640px)").addEventListener("change", closeMenu); $$(".site-nav a").forEach(link => link.addEventListener("click", closeMenu)); const navSections = $$("[data-nav-section]"); const navLinks = $$(".site-nav a"); function updateActiveNav() { const active = [...navSections].reverse().find(section => section.getBoundingClientRect().top <= 160) || navSections[0]; navLinks.forEach(link => { const selected = link.hash === `#${active.id}`; link.classList.toggle("is-active",selected); if (selected) link.setAttribute("aria-current","location"); else link.removeAttribute("aria-current"); }); } let scrollPending = false; window.addEventListener("scroll",() => { if (scrollPending) return; scrollPending = true; requestAnimationFrame(() => { updateActiveNav(); scrollPending = false; }); },{passive:true}); function revealHashTarget() { let id; try { id = decodeURIComponent(location.hash.slice(1)); } catch (_) { return; } const target = document.getElementById(id); if (!target) return; let parent = target.parentElement; let expanded = false; while (parent) { if (parent.tagName === "DETAILS" && !parent.open) { parent.open = true; expanded = true; } parent = parent.parentElement; } if (expanded) requestAnimationFrame(() => target.scrollIntoView()); updateActiveNav(); } window.addEventListener("hashchange",revealHashTarget); revealHashTarget(); updateActiveNav(); const footer = $("[data-site-footer]"); footer.className = "site-footer"; footer.innerHTML = ``; let toastTimer; function toast(message) { const element = $(".toast"); element.textContent = message; element.hidden = false; clearTimeout(toastTimer); toastTimer = setTimeout(() => { element.hidden = true; }, 3500); } const sampleInput = { id: "test_001", question: "What was the average power of device_01 between 08:00 and 12:00 UTC on January 1, 2026?", database: "root.energy", schema: {root: "root.energy", devices: {device_01: {power: "FLOAT"}}}, timezone: "UTC" }; const predictionExample = [{id:"test_001",predicted_sql:"SELECT AVG(power) FROM root.energy.device_01 WHERE time >= '2026-01-01T08:00:00Z' AND time < '2026-01-01T12:00:00Z'"}]; const copyText = { "sample-input": JSON.stringify(sampleInput, null, 2), predictions: JSON.stringify(predictionExample, null, 2), citation: "% TERN benchmark citation placeholder.\n% Replace with the official BibTeX entry when the paper is released." }; if ($("[data-sample-input]")) $("[data-sample-input]").textContent = copyText["sample-input"]; if ($("[data-prediction-example]")) $("[data-prediction-example]").textContent = copyText.predictions; async function copyToClipboard(value) { if (navigator.clipboard && window.isSecureContext) { try { await navigator.clipboard.writeText(value); return; } catch (_) { /* File URL / permission fallback. */ } } const field = document.createElement("textarea"); field.value = value; field.style.cssText = "position:fixed;left:-9999px;top:0;"; document.body.append(field); field.select(); const copied = document.execCommand("copy"); field.remove(); if (!copied) throw new Error("Clipboard is unavailable in this browser."); } $$("[data-copy], [data-copy-source]").forEach(button => button.addEventListener("click", async () => { try { const source = button.dataset.copySource; await copyToClipboard(source ? document.getElementById(source).textContent : copyText[button.dataset.copy]); toast(button.dataset.copy === "citation" ? "Citation placeholder copied. Official citation coming at release." : "Copied to clipboard."); } catch (_) { toast("Clipboard access is unavailable. You can select and copy the text directly."); } })); const scoreKeys = ["overall", "foundation", "standard", "analytical"]; const scoreLabels = {overall:"Overall EX", foundation:"Foundation EX", standard:"Standard EX", analytical:"Analytical EX"}; const methodLabel = entry => `${entry.name}${entry.setting ? ` (${entry.setting})` : ""}`; const rankHTML = rank => `${String(rank).padStart(2,"0")}`; const settingHTML = setting => setting ? `${escapeHTML(setting)}` : ""; const paperHTML = (paper, fullTitle = false) => paper ? `${fullTitle ? escapeHTML(paper.title) : `[${escapeHTML(paper.label)}]`}` : ""; if ($("[data-full-leaderboard]")) { let sortKey = "overall"; let ascending = false; const tabs = $$("[data-tier]"); const bestScores = Object.fromEntries(scoreKeys.map(key => [key, Math.max(...leaderboard.entries.map(entry => entry[key]))])); const renderBoard = () => { const search = $("#method-search").value.trim().toLowerCase(); const sorted = [...leaderboard.entries].sort((a,b) => (ascending ? 1 : -1) * (a[sortKey] - b[sortKey]) || a.id.localeCompare(b.id)); const ranks = new Map(sorted.map((entry,index) => [entry.id,index + 1])); const filtered = sorted.filter(entry => { const paper = leaderboard.papers[entry.paper]; const searchable = `${methodLabel(entry)} ${entry.category !== "nl2sql" ? "Baseline" : ""} ${paper?.label || ""} ${paper?.title || ""}`.toLowerCase(); return !search || searchable.includes(search); }); $("[data-full-leaderboard]").innerHTML = filtered.map(entry => { const paper = leaderboard.papers[entry.paper]; const metadata = entry.category !== "nl2sql" ? 'Baseline' : paperHTML(paper); return `${rankHTML(ranks.get(entry.id))}${settingHTML(entry.setting)}${metadata ? `${metadata}` : ""}${scoreKeys.map(key => `${entry[key].toFixed(2)}`).join("")}`; }).join(""); $("[data-empty-state]").hidden = filtered.length > 0; $("[data-result-count]").textContent = `Showing ${filtered.length} of ${leaderboard.entries.length} methods`; $$("[data-sort-header]").forEach(th => { const selected = th.dataset.sortHeader === sortKey; if (selected) th.setAttribute("aria-sort",ascending ? "ascending" : "descending"); else th.removeAttribute("aria-sort"); $("span",th).textContent = selected ? (ascending ? "↑" : "↓") : "↕"; }); }; function selectTier(tab) { tabs.forEach(button => { const active = button === tab; button.classList.toggle("is-active",active); button.setAttribute("aria-selected",String(active)); button.tabIndex = active ? 0 : -1; }); $("#board-panel").setAttribute("aria-labelledby",tab.id); sortKey = tab.dataset.tier; ascending = false; renderBoard(); } tabs.forEach((tab,index) => { tab.addEventListener("click",() => selectTier(tab)); tab.addEventListener("keydown",event => { let nextIndex; if (event.key === "ArrowRight") nextIndex = (index + 1) % tabs.length; if (event.key === "ArrowLeft") nextIndex = (index + tabs.length - 1) % tabs.length; if (event.key === "Home") nextIndex = 0; if (event.key === "End") nextIndex = tabs.length - 1; if (nextIndex !== undefined) { event.preventDefault(); selectTier(tabs[nextIndex]); tabs[nextIndex].focus(); } }); }); $$("[data-sort]").forEach(button => button.addEventListener("click",() => { const key = button.dataset.sort; const nextAscending = sortKey === key ? !ascending : false; selectTier(tabs.find(tab => tab.dataset.tier === key)); ascending = nextAscending; renderBoard(); })); $("#method-search").addEventListener("input",renderBoard); $("[data-reset-filters]").addEventListener("click",() => { $("#method-search").value = ""; renderBoard(); }); $("[data-full-leaderboard]").addEventListener("click",event => { const button = event.target.closest("[data-method]"); if (!button) return; const entry = leaderboard.entries.find(item => item.id === button.dataset.method); const paper = leaderboard.papers[entry.paper]; $("[data-method-details]").innerHTML = `
TERN BENCHMARK RESULT

${escapeHTML(methodLabel(entry))}

${scoreKeys.map(key => `
${scoreLabels[key]}${entry[key].toFixed(2)}
`).join("")}
Category
${escapeHTML(leaderboard.categories[entry.category])}
${entry.setting ? `
Setting
${entry.setting === "SFT" ? "Supervised fine-tuning (SFT)" : "In-context learning (ICL)"}
` : ""}${paper ? `
Paper
${paperHTML(paper,true)}
` : ""}
`; $("[data-close-dialog]").addEventListener("click",() => $("#method-dialog").close()); $("#method-dialog").showModal(); }); $("#method-dialog").addEventListener("click",event => { if (event.target === event.currentTarget) { const rect = event.currentTarget.getBoundingClientRect(); if (event.clientX < rect.left || event.clientX > rect.right || event.clientY < rect.top || event.clientY > rect.bottom) event.currentTarget.close(); } }); renderBoard(); } if ($("#submission-form")) { const form = $("#submission-form"); const result = $("#validation-result"); const message = $("#file-message"); const fileInput = $("#prediction-file"); const emailDelivery = window.TERN_EMAIL_SUBMISSION; const sendButton = $("#send-submission"); let selectedDocument = null; let selectedFilename = ""; let selectedFile = null; let fileSequence = 0; let downloadableSummary = null; const fileLimit = emailDelivery.MAX_FILE_BYTES; const hideResult = () => { result.hidden = true; downloadableSummary = null; }; form.addEventListener("input",event => { hideResult(); event.target.removeAttribute("aria-invalid"); }); form.addEventListener("change",hideResult); function refreshDeliveryStatus() { const availability = emailDelivery.getAvailability(); sendButton.disabled = !availability.ready; $("#email-submission-notice").textContent = availability.message; $("[data-email-submission-status]").textContent = availability.ready ? "Email submissions" : "Email submissions coming soon"; return availability; } refreshDeliveryStatus(); function fileMessage(text, error = false) { message.textContent = text; message.classList.toggle("is-error",error); message.hidden = false; } function validateShape(data) { const errors = []; if (!Array.isArray(data) || !data.length) return ["The prediction file must be a non-empty JSON array of objects with id and predicted_sql."]; const ids = new Set(); data.forEach((entry,index) => { const prefix = `Prediction ${index + 1}`; if (!entry || typeof entry !== "object" || Array.isArray(entry)) { errors.push(`${prefix}: expected an object.`); return; } const validId = (typeof entry.id === "string" && entry.id.trim() && entry.id.length <= 200) || (Number.isSafeInteger(entry.id) && entry.id > 0); if (!validId) errors.push(`${prefix}: id must be a positive safe integer or a non-empty string of at most 200 characters.`); else if (ids.has(String(entry.id))) errors.push(`${prefix}: duplicate id "${entry.id}".`); else ids.add(String(entry.id)); if (typeof entry.predicted_sql !== "string" || !entry.predicted_sql.trim()) errors.push(`${prefix}: predicted_sql must be a non-empty string.`); else if (entry.predicted_sql.length > 100000) errors.push(`${prefix}: SQL exceeds the 100,000-character preview limit.`); for (const key of Object.keys(entry)) if (!["id","predicted_sql"].includes(key)) errors.push(`${prefix}: unknown field "${key}".`); }); return errors; } async function readFile(file) { const sequence = ++fileSequence; hideResult(); selectedDocument = null; selectedFilename = ""; selectedFile = null; if (!file) return; $("[data-file-label]").textContent = file.name; if (file.size > fileLimit) { fileMessage("This file exceeds the 10 MB preview limit.",true); return; } if (!/\.json$/i.test(file.name)) { fileMessage("Choose a .json prediction file.",true); return; } try { const text = await file.text(); if (sequence !== fileSequence) return; const data = JSON.parse(text.replace(/^\uFEFF/,"")); selectedDocument = data; selectedFilename = file.name; selectedFile = file; const count = Array.isArray(data) ? data.length : 0; fileMessage(`${file.name} loaded · ${count} prediction${count === 1 ? "" : "s"} · ${(file.size / 1024).toFixed(1)} KB. Ready for local validation.`); } catch (_) { if (sequence === fileSequence) fileMessage("This file could not be read as JSON. Check its syntax and try again.",true); } } fileInput.addEventListener("change",() => readFile(fileInput.files[0])); const dropzone = $("#prediction-dropzone"); ["dragenter","dragover"].forEach(type => dropzone.addEventListener(type,event => { event.preventDefault(); dropzone.classList.add("is-dragging"); })); ["dragleave","drop"].forEach(type => dropzone.addEventListener(type,event => { event.preventDefault(); dropzone.classList.remove("is-dragging"); })); dropzone.addEventListener("drop",event => { if (event.dataTransfer.files.length !== 1) { fileSequence++; selectedDocument = null; selectedFilename = ""; selectedFile = null; fileInput.value = ""; hideResult(); $("[data-file-label]").textContent = "Drop your predictions.json here"; fileMessage("Choose one JSON prediction file at a time.",true); return; } fileInput.value = ""; readFile(event.dataTransfer.files[0]); }); function validateSubmission() { const errors = []; let firstInvalid = null; ["method-name","team-name"].forEach(id => { const field = $(`#${id}`); const valid = Boolean(field.value.trim()); field.setAttribute("aria-invalid",String(!valid)); if (!valid) { errors.push(`${({"method-name":"Method name","team-name":"Team / Organization"})[id]} is required.`); firstInvalid ||= field; } }); const contactField = $("#contact-email"); const contactValid = Boolean(contactField.value.trim()) && contactField.validity.valid; contactField.setAttribute("aria-invalid", String(!contactValid)); if (!contactValid) { errors.push("A valid contact email is required for submission feedback."); firstInvalid ||= contactField; } const urlField = $("#resource-url"); const url = urlField.value.trim(); if (url) { let valid = false; try { valid = ["http:","https:"].includes(new URL(url).protocol); } catch (_) { /* Invalid URL. */ } urlField.setAttribute("aria-invalid",String(!valid)); if (!valid) { errors.push("Paper / Code URL must be a valid http:// or https:// address."); firstInvalid ||= urlField; } } if (!$("#submission-agreement").checked) errors.push("Confirm the prediction declaration before validation."); if (!selectedDocument) errors.push("Add a valid JSON prediction file."); else errors.push(...validateShape(selectedDocument)); result.hidden = false; result.classList.toggle("is-error",errors.length > 0); if (errors.length) { downloadableSummary = null; result.innerHTML = `

Please review your submission

${errors.length > 10 ? `

And ${errors.length - 10} more issue(s). Fix the file and validate again.

` : ""}

No file has been uploaded.

`; if (firstInvalid) firstInvalid.focus(); else result.scrollIntoView({behavior:"smooth",block:"nearest"}); return null; } const values = new FormData(form); downloadableSummary ||= { submission_id: emailDelivery.createSubmissionId(), submitted_at_utc: new Date().toISOString(), submission_type: "leaderboard_review", method: values.get("method").trim(), team: values.get("team").trim(), model: values.get("model").trim() || null, contact_email: contactField.value.trim(), setting: values.get("setting") || null, resource_url: url || null, filename: selectedFilename, prediction_count: selectedDocument.length, local_format_check: "passed", official_evaluation: "not_performed" }; result.innerHTML = `
LOCAL CHECK COMPLETE

Your file structure looks good.

${selectedDocument.length} prediction${selectedDocument.length === 1 ? "" : "s"}Unique IDsRequired fields

${escapeHTML(downloadableSummary.method)} · ${escapeHTML(downloadableSummary.team)}

SQL syntax, semantics, and question coverage have not been verified. No file has been sent and no EX score was created.

`; $("[data-download-summary]").addEventListener("click",() => downloadJSON(downloadableSummary,"tern-submission-summary.json")); result.scrollIntoView({behavior:"smooth",block:"nearest"}); return downloadableSummary; } $("#validate-submission").addEventListener("click",validateSubmission); form.addEventListener("submit",event => { event.preventDefault(); const metadata = validateSubmission(); if (!metadata) return; try { const availability = refreshDeliveryStatus(); if (!availability.ready) throw new Error(availability.message); emailDelivery.send(metadata, selectedFile); result.innerHTML = `
EMAIL SUBMISSION

Finish submission on the email service page.

Submission ID: ${escapeHTML(metadata.submission_id)}

Complete any confirmation on the page opened by the email service. This page does not confirm email delivery. The organizers will review your submission before leaderboard inclusion; no online EX score was generated.

`; $("[data-reopen-delivery]").addEventListener("click",() => form.requestSubmit(sendButton)); } catch (error) { result.classList.add("is-error"); result.innerHTML = `

Submission has not been confirmed

${escapeHTML(error.message || "Please try again.")}

Your file remains available for local validation.

`; } result.scrollIntoView({behavior:"smooth",block:"nearest"}); }); } function downloadJSON(data, filename) { const url = URL.createObjectURL(new Blob([JSON.stringify(data,null,2) + "\n"],{type:"application/json"})); const anchor = document.createElement("a"); anchor.href = url; anchor.download = filename; document.body.append(anchor); anchor.click(); anchor.remove(); setTimeout(() => URL.revokeObjectURL(url),1000); } })();