elementref's picture
Add static lookup app and dataset CSV files
0ef3796 verified
Raw History Blame Contribute Delete
8.14 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Hydraulic Filter Element Explorer</title>
<style>
:root {
--bg: #f6f7f9;
--card: #fff;
--text: #1c1f26;
--muted: #5b6370;
--line: #e3e6eb;
--accent: #1f4b8a;
}
* { box-sizing: border-box; }
body {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
background: var(--bg);
color: var(--text);
line-height: 1.5;
}
main { max-width: 1100px; margin: 0 auto; padding: 2rem 1.25rem 4rem; }
h1 { font-size: 1.75rem; font-weight: 700; margin: 0 0 0.75rem; }
p.lead, p.meta, #status { color: var(--muted); }
p.meta { font-size: 0.95rem; }
a { color: var(--accent); }
form { display: flex; gap: 0.5rem; margin: 1.25rem 0 0.75rem; flex-wrap: wrap; }
input[type="search"] {
flex: 1 1 280px;
font: inherit;
padding: 0.65rem 0.8rem;
border: 1px solid var(--line);
border-radius: 6px;
background: var(--card);
}
button {
font: inherit;
padding: 0.65rem 1.1rem;
border: 0;
border-radius: 6px;
background: var(--accent);
color: #fff;
cursor: pointer;
}
button:disabled { opacity: 0.6; cursor: not-allowed; }
section { margin-top: 1.5rem; }
h2 { font-size: 1.15rem; margin: 0 0 0.6rem; }
.table-wrap { overflow: auto; background: var(--card); border: 1px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; font-family: system-ui, sans-serif; font-size: 0.85rem; }
th, td { text-align: left; padding: 0.45rem 0.6rem; border-bottom: 1px solid var(--line); vertical-align: top; white-space: nowrap; }
th { background: #eef2f7; position: sticky; top: 0; }
td.wrap { white-space: normal; min-width: 12rem; }
</style>
</head>
<body>
<main>
<h1>Hydraulic Filter Element Explorer</h1>
<p class="lead">Look up part numbers in the open ElementRef hydraulic filter element dataset (CC BY 4.0): catalog specifications plus graded cross-references (<code>full</code>, <code>partial</code>, or <code>verify</code>).</p>
<p class="meta">Canonical citation: <a href="https://doi.org/10.5281/zenodo.23132845">https://doi.org/10.5281/zenodo.23132845</a>
· <a href="https://huggingface.co/datasets/elementref/hydraulic-filter-elements">Dataset on Hugging Face</a>
· <a href="https://elementref.com/open-data/">Open data page</a></p>
<form id="search-form">
<input id="query" type="search" placeholder="For example: 0060 R 003 BN4HC or HC2208FCP4H" aria-label="Part number or brand" />
<button id="search-btn" type="submit" disabled>Search</button>
</form>
<p id="status">Loading dataset files…</p>
<section>
<h2>Matching SKUs</h2>
<div class="table-wrap"><table id="sku-table"><thead></thead><tbody></tbody></table></div>
</section>
<section>
<h2>Graded cross-references</h2>
<div class="table-wrap"><table id="xref-table"><thead></thead><tbody></tbody></table></div>
</section>
</main>
<script>
const SKU_COLUMNS = ["model","brand","series","category","filter_type","media","micron","micron_basis","beta","od_mm","id_mm","length_mm","end_cap","collapse_bar","bypass_bar","seal_material","confidence"];
const XREF_COLUMNS = ["model_a","model_b","match_level","conflict","sources"];
const statusEl = document.getElementById("status");
const buttonEl = document.getElementById("search-btn");
let skus = [];
let xrefs = [];
function parseCsv(text) {
const rows = [];
let row = [];
let cell = "";
let inQuotes = false;
for (let i = 0; i < text.length; i++) {
const c = text[i];
if (inQuotes) {
if (c === '"') {
if (text[i + 1] === '"') { cell += '"'; i++; }
else inQuotes = false;
} else cell += c;
} else if (c === '"') inQuotes = true;
else if (c === ",") { row.push(cell); cell = ""; }
else if (c === "\n") { row.push(cell); rows.push(row); row = []; cell = ""; }
else if (c !== "\r") cell += c;
}
if (cell.length || row.length) { row.push(cell); rows.push(row); }
if (!rows.length) return [];
const headers = rows[0];
return rows.slice(1).filter(r => r.some(v => v)).map(r => {
const obj = {};
headers.forEach((h, idx) => { obj[h] = r[idx] || ""; });
return obj;
});
}
function renderTable(table, columns, records, wrapCols) {
const thead = table.querySelector("thead");
const tbody = table.querySelector("tbody");
thead.innerHTML = "<tr>" + columns.map(c => "<th>" + c + "</th>").join("") + "</tr>";
tbody.innerHTML = "";
const frag = document.createDocumentFragment();
for (const rec of records) {
const tr = document.createElement("tr");
for (const c of columns) {
const td = document.createElement("td");
if (wrapCols && wrapCols.has(c)) td.className = "wrap";
td.textContent = rec[c] || "";
tr.appendChild(td);
}
frag.appendChild(tr);
}
tbody.appendChild(frag);
}
function compact(s) { return (s || "").toLowerCase().replace(/[^a-z0-9]+/g, ""); }
function search(query) {
const q = (query || "").trim();
if (!q) {
renderTable(document.getElementById("sku-table"), SKU_COLUMNS, []);
renderTable(document.getElementById("xref-table"), XREF_COLUMNS, []);
statusEl.textContent = "Enter a part number or brand to search.";
return;
}
const needle = q.toLowerCase();
const packed = compact(q);
const skuHits = skus.filter(r => (r._q && r._q.includes(needle)) || (packed && r._n === packed));
const xrefHits = xrefs.filter(r => (r._a && r._a.includes(needle)) || (r._b && r._b.includes(needle)) || (packed && (r._an === packed || r._bn === packed)));
renderTable(document.getElementById("sku-table"), SKU_COLUMNS, skuHits.slice(0, 50), new Set(["media","beta"]));
renderTable(document.getElementById("xref-table"), XREF_COLUMNS, xrefHits.slice(0, 100));
statusEl.textContent = "Found " + skuHits.length.toLocaleString() + " matching SKU(s) (showing up to 50) and " + xrefHits.length.toLocaleString() + " cross-reference pair(s) (showing up to 100).";
}
async function loadCsv(path) {
const res = await fetch(path);
if (!res.ok) throw new Error("Could not load " + path + " (" + res.status + ")");
return parseCsv(await res.text());
}
async function init() {
try {
statusEl.textContent = "Loading SKU catalog…";
skus = await loadCsv("./skus-all.csv");
skus.forEach(r => {
r._q = ((r.model || "") + " " + (r.normalized || "") + " " + (r.brand || "")).toLowerCase();
r._n = compact(r.normalized || r.model);
});
statusEl.textContent = "Loading cross-references…";
const parts = await Promise.all([
loadCsv("./cross-references-1.csv"),
loadCsv("./cross-references-2.csv"),
loadCsv("./cross-references-3.csv")
]);
xrefs = parts.flat();
xrefs.forEach(r => {
r._a = (r.model_a || "").toLowerCase();
r._b = (r.model_b || "").toLowerCase();
r._an = compact(r.model_a);
r._bn = compact(r.model_b);
});
buttonEl.disabled = false;
statusEl.textContent = "Dataset files loaded. Search a part number to begin.";
} catch (err) {
statusEl.textContent = "Could not load the dataset files: " + err.message;
}
}
document.getElementById("search-form").addEventListener("submit", (e) => {
e.preventDefault();
search(document.getElementById("query").value);
});
renderTable(document.getElementById("sku-table"), SKU_COLUMNS, []);
renderTable(document.getElementById("xref-table"), XREF_COLUMNS, []);
init();
</script>
</body>
</html>