(()=>{ const el=id=>document.getElementById(id),safe=s=>String(s).replace(/[&<>"']/g,c=>({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c])); const token=s=>safe(s).replace(/\{[^}]+\}/g,m=>`${m}`); 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 `${safe(s)}`;} 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=>`${token(o)}`).join('');const pool=t.options.length>8?`
전체 보기 후보 ${t.options.length}개 펼치기
${chips}
`:`
${chips}
`; return `${safe(t.type)}${token(t.question)}${pool}
문항당 ${t.choices.join(' / ')}개 보기
`}).join(''); const typeCell=(r,i)=>rows.findIndex(x=>x.type===r.type)===i?`${safe(r.type)}`:''; const max=Math.max(1,...rows.map(r=>r.questions));el('countRows').innerHTML=rows.map((r,i)=>`${typeCell(r,i)}${sourceTag(r.source)}${fmt(r.videos)}
${fmt(r.questions)}
`).join(''); el('gtRows').innerHTML=rows.map((r,rowIndex)=>{const bar=r.gt.map((g,i)=>``).join('');const labels=r.gt.map((g,i)=>`${token(g.label)} ${g.count}(${g.percent.toFixed(1)}%)`).join('');return `${typeCell(r,rowIndex)}${sourceTag(r.source)}${r.questions}${r.questions?`
${bar}
${labels}
`:'확정 문항 없음'}`}).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])=>`
${label}
${fmt(d.summary[key])}
`).join(''); el('sourceSummaryRows').innerHTML=d.source_summary.map(r=>`${sourceTag(r.source)}${fmt(r.scenes)}${fmt(r.questions)}`).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; })();