Spaces:
Running

direction-qa / stats.js
boreum0302's picture
Add Object Size Change evaluation and review; remove category grouping
048a777 verified
Raw History Blame Contribute Delete
4.5 kB
(()=>{
const el=id=>document.getElementById(id),safe=s=>String(s).replace(/[&<>"']/g,c=>({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'}[c]));
const token=s=>safe(s).replace(/\{[^}]+\}/g,m=>`<span class="template-token">${m}</span>`);
const fmt=n=>n.toLocaleString(),palette=['#55d8af','#6eaff0','#b995ee','#efb365','#ee8296','#79cbd2','#a4c985','#c9a994'];
let stats;
function openTab(which){const on=which==='stats';el('statsView').hidden=!on;el('copyTop').hidden=on;el('collectionView').hidden=on;el('statsTab').setAttribute('aria-selected',String(on));el('videosTab').setAttribute('aria-selected',String(!on));if(on&&typeof stop==='function')stop();}
el('statsTab').onclick=()=>openTab('stats');el('videosTab').onclick=()=>openTab('videos');
function sourceTag(s){return `<span class="source-pill ${s==='Syn4D'?'syn':''}">${safe(s)}</span>`;}
function render(){if(!stats)return;const type=el('statsType').value,source=el('statsSource').value;const rows=stats.rows.filter(r=>(!type||r.type===type)&&(!source||r.source===source));
el('statsScope').textContent=`선택 범위 ${fmt(rows.reduce((n,r)=>n+r.questions,0))} QA`;
const ts=stats.templates.filter(t=>!type||t.type===type);el('templateRows').innerHTML=ts.map((t,ti)=>{
const chips=t.options.map(o=>`<span class="option-chip">${token(o)}</span>`).join('');const pool=t.options.length>8?`<details class="option-details"><summary>전체 보기 후보 ${t.options.length}개 펼치기</summary><div class="option-pool">${chips}</div></details>`:`<div class="option-pool">${chips}</div>`;
return `<tr><td class="type-cell">${safe(t.type)}</td><td class="template-text">${token(t.question)}</td><td>${pool}<div class="stats-note">문항당 ${t.choices.join(' / ')}개 보기</div></td></tr>`}).join('');
const typeCell=(r,i)=>rows.findIndex(x=>x.type===r.type)===i?`<td class="type-cell merged-type" rowspan="${rows.filter(x=>x.type===r.type).length}">${safe(r.type)}</td>`:'';
const max=Math.max(1,...rows.map(r=>r.questions));el('countRows').innerHTML=rows.map((r,i)=>`<tr>${typeCell(r,i)}<td class="source-cell">${sourceTag(r.source)}</td><td class="num-cell">${fmt(r.videos)}</td><td class="count-cell num-cell"><div class="count-line"><div class="count-track"><div class="count-fill" style="width:${100*r.questions/max}%"></div></div>${fmt(r.questions)}</div></td></tr>`).join('');
el('gtRows').innerHTML=rows.map((r,rowIndex)=>{const bar=r.gt.map((g,i)=>`<span class="distribution-segment" style="width:${g.percent}%;background:${palette[i%palette.length]}" title="${safe(g.label)}: ${g.count}"></span>`).join('');const labels=r.gt.map((g,i)=>`<span class="gt-item"><span class="gt-dot" style="background:${palette[i%palette.length]}"></span>${token(g.label)} <span class="gt-value">${g.count}</span><span class="gt-pct">(${g.percent.toFixed(1)}%)</span></span>`).join('');return `<tr>${typeCell(r,rowIndex)}<td class="source-cell">${sourceTag(r.source)}</td><td class="num-cell">${r.questions}</td><td class="distribution">${r.questions?`<div class="distribution-bar">${bar}</div><div class="distribution-legend">${labels}</div>`:'<span class="empty-cell">확정 문항 없음</span>'}</td></tr>`}).join('');
}
fetch('collection_stats.json').then(r=>{if(!r.ok)throw Error('통계 로드 실패');return r.json()}).then(d=>{stats=d;const titles={questions:'검수 QA',videos:'고유 영상',types:'QA 유형',sources:'Video sources'};el('statsMetrics').innerHTML=Object.entries(titles).map(([key,label])=>`<div class="metric"><div class="metric-label">${label}</div><div class="metric-number">${fmt(d.summary[key])}</div></div>`).join('');
el('sourceSummaryRows').innerHTML=d.source_summary.map(r=>`<tr><th scope="row">${sourceTag(r.source)}</th><td class="num-cell">${fmt(r.scenes)}</td><td class="num-cell">${fmt(r.questions)}</td></tr>`).join('');el('sourceSummaryScenes').textContent=fmt(d.summary.scenes);el('sourceSummaryQuestions').textContent=fmt(d.summary.questions);el('sceneDefinition').textContent=d.scene_definition;
for(const type of d.types){const o=document.createElement('option');o.value=o.textContent=type;el('statsType').append(o)}for(const source of d.sources){const o=document.createElement('option');o.value=o.textContent=source;el('statsSource').append(o)}el('videoDefinition').textContent=d.video_definition;el('gtDefinition').textContent=d.gt_definition;render();}).catch(e=>{el('statsScope').textContent=e.message});
el('statsType').onchange=render;el('statsSource').onchange=render;
})();