File size: 1,708 Bytes
b37ee5e
1
2
let rows=[],sort='J',direction=-1;const body=document.getElementById('rows');const pct=x=>typeof x==='number'?Math.round(x*100)+'%':'—';function render(){const q=document.getElementById('search').value.toLowerCase(),group=document.getElementById('group').value;const selected=rows.filter(r=>(r.name||r.model).toLowerCase().includes(q)&&(!group||(group==='unranked'?!r.ranked:r.quadrant===group))).sort((a,b)=>{if(sort==='name')return direction*(a.name||a.model).localeCompare(b.name||b.model);if(a.J==null)return 1;if(b.J==null)return -1;return direction*(a.J-b.J)});body.replaceChildren();for(const r of selected){const tr=document.createElement('tr');const j=typeof r.J==='number'?(r.J>0?'+':'')+r.J.toFixed(2):'—';for(const value of [r.ranked?r.rank:'—',r.name||r.model,j,pct(r.held_first?.rate??r.held_line_rate),pct(r.over_refusal_hard_rungs),r.quadrant||'Unranked']){const td=document.createElement('td');td.textContent=value;tr.append(td)}body.append(tr)}document.getElementById('count').textContent=selected.length+' of '+rows.length+' models';}document.getElementById('search').addEventListener('input',render);document.getElementById('group').addEventListener('change',render);for(const button of document.querySelectorAll('[data-sort]'))button.addEventListener('click',()=>{const next=button.dataset.sort;direction=sort===next?-direction:(next==='name'?1:-1);sort=next;render()});fetch('round4.json').then(r=>{if(!r.ok)throw Error(r.status);return r.json()}).then(data=>{rows=data.rows||data.leaderboard;if(!Array.isArray(rows))throw Error('Unexpected export');render()}).catch(()=>{document.getElementById('count').textContent='Could not load the table. Use the source JSON link below.'});