제작된 퀴즈 6단계: 플레이 통계 상세(문제마다 힌트 시간/투표, 정답이 아닌 입력 수·사람 수, 다시듣기, 제작된 퀴즈·곡; DB에 없는 퀴즈 곡도 기록 — song_plays.song_id nullable로 다시 만듦). 관리자 통계 곡별·퀴즈별(퀴즈 → 곡별 어려운 순) 탭. 난이도 제안이 힌트도 보고, 검토 대기 → 난이도 조정에 근거(출제·정답·힌트·오답·다시듣기)와 함께 승인/반영 안 함(5번 더 나온 뒤 다시). 메뉴 개수에 포함

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-22 13:15:08 +09:00
parent b999310eb9
commit a0907b551b
12 changed files with 424 additions and 25 deletions

View File

@@ -247,16 +247,159 @@ interface StatRow {
avg_ms: number | null;
last_at: number;
suggest: number | null;
hints: number;
wrong: number;
replays: number;
}
export function StatsPage() {
const [tab, setTab] = useState<'songs' | 'quizzes'>('songs');
return (
<>
<h1>통계</h1>
<div className="seg" role="tablist" style={{ maxWidth: 360 }}>
<button type="button" role="tab" aria-selected={tab === 'songs'} className={tab === 'songs' ? 'on' : ''} onClick={() => setTab('songs')}>
곡별
</button>
<button type="button" role="tab" aria-selected={tab === 'quizzes'} className={tab === 'quizzes' ? 'on' : ''} onClick={() => setTab('quizzes')}>
퀴즈별
</button>
</div>
{tab === 'songs' ? <SongStats /> : <QuizStats />}
</>
);
}
interface QuizStatRow {
id: number;
name: string;
visibility: string;
owner: string | null;
songs: number;
plays: number;
games: number;
questions: number;
correct: number;
avg_ms: number | null;
hints: number;
wrong: number;
replays: number;
last_at: number | null;
}
interface QuizItemStat {
id: number;
pos: number;
title: string;
artist: string;
song_id: number | null;
plays: number;
correct: number;
avg_ms: number | null;
hints: number;
wrong: number;
replays: number;
}
const sec = (ms: number | null) => (ms !== null ? `${(ms / 1000).toFixed(1)}초` : '-');
const VIS: Record<string, string> = { private: '비공개', partial: '일부공개', public: '전체공개' };
/** 통계 → 퀴즈별: each 제작된 퀴즈, then its songs (hardest first). */
function QuizStats() {
const { data } = useLoad<{ quizzes: QuizStatRow[] }>('/api/admin/stats/quizzes');
const [open, setOpen] = useState<number | null>(null);
const { data: items } = useLoad<{ items: QuizItemStat[] }>(open ? `/api/admin/stats/quizzes/${open}` : '/api/admin/stats/quizzes/0');
const q = data?.quizzes.find((x) => x.id === open);
return (
<>
<p className="muted small">제작된 퀴즈로 한 게임만 세요. 정답률은 문제 중 정답자가 나온 비율, 오답은 정답이 아닌 채팅 입력이에요.</p>
<div className="table-wrap">
<table className="data-table">
<thead>
<tr>
<th>퀴즈</th>
<th>곡</th>
<th>게임</th>
<th>문제</th>
<th>정답률</th>
<th>평균 정답 시간</th>
<th>힌트</th>
<th>오답</th>
<th>다시듣기</th>
<th>마지막</th>
</tr>
</thead>
<tbody>
{data?.quizzes.map((r) => (
<tr key={r.id} className={open === r.id ? 'sel' : ''} onClick={() => setOpen(open === r.id ? null : r.id)} style={{ cursor: 'pointer' }}>
<td>
<b>{r.name}</b>
<div className="muted small">
{VIS[r.visibility]} · {r.owner ?? '?'}
</div>
</td>
<td className="mono">{r.songs}</td>
<td className="mono">{r.games}</td>
<td className="mono">{r.questions}</td>
<td className="mono">{pct(r.correct, r.questions)}</td>
<td className="mono">{sec(r.avg_ms)}</td>
<td className="mono">{pct(r.hints, r.questions)}</td>
<td className="mono">{r.questions ? (r.wrong / r.questions).toFixed(1) : '-'}</td>
<td className="mono">{r.replays}</td>
<td className="small">{fmt(r.last_at)}</td>
</tr>
))}
</tbody>
</table>
</div>
{data?.quizzes.length === 0 && <p className="muted">아직 제작된 퀴즈가 없어요.</p>}
{q && items && (
<>
<h2>{q.name} · 곡별 (어려운 곡부터)</h2>
<div className="table-wrap">
<table className="data-table">
<thead>
<tr>
<th>번호</th>
<th>노래</th>
<th>출제</th>
<th>정답률</th>
<th>평균 정답 시간</th>
<th>힌트</th>
<th>오답(문제당)</th>
<th>다시듣기</th>
</tr>
</thead>
<tbody>
{items.items.map((r) => (
<tr key={r.id}>
<td className="mono">{r.pos + 1}</td>
<td>
<b>{r.title}</b> - {r.artist}
{!r.song_id && <span className="badge" style={{ marginLeft: 6 }}>DB에 없음</span>}
</td>
<td className="mono">{r.plays}</td>
<td className="mono">{pct(r.correct, r.plays)}</td>
<td className="mono">{sec(r.avg_ms)}</td>
<td className="mono">{pct(r.hints, r.plays)}</td>
<td className="mono">{r.plays ? (r.wrong / r.plays).toFixed(1) : '-'}</td>
<td className="mono">{r.replays}</td>
</tr>
))}
</tbody>
</table>
</div>
</>
)}
</>
);
}
function SongStats() {
const [sort, setSort] = useState('plays');
const [page, setPage] = useState(0);
const { data, reload } = useLoad<{ total: number; rows: StatRow[]; pageSize: number; today: { plays: number; games: number }; suggestions: number }>(`/api/admin/stats?sort=${sort}&page=${page}`);
const pages = data ? Math.max(1, Math.ceil(data.total / data.pageSize)) : 1;
return (
<>
<h1>통계</h1>
{data && (
<div className="stat-row">
<div className="stat">
@@ -273,7 +416,7 @@ export function StatsPage() {
</div>
</div>
)}
<p className="muted small">5번 이상 나온 곡만 제안해요. 80% 넘게 8초 안에 맞히면 한 단계 쉽게, 30% 아래로 맞히면 한 단계 어렵게.</p>
<p className="muted small">5번 이상 나온 곡만 제안해요. 80% 넘게 8초 안에 힌트 없이(힌트 30% 미만) 맞히면 한 단계 쉽게, 30% 아래로 맞히거나 절반 이하로 맞히면서 힌트가 60% 넘게 나오면 한 단계 어렵게. 제안은 검토 대기 → 난이도 조정에도 근거와 함께 나와요.</p>
<div className="row">
<label className="field-inline">
정렬
@@ -294,6 +437,9 @@ export function StatsPage() {
<th>출제</th>
<th>정답률</th>
<th>평균 정답 시간</th>
<th>힌트</th>
<th>오답(문제당)</th>
<th>다시듣기</th>
<th>마지막</th>
<th>제안</th>
</tr>
@@ -308,6 +454,9 @@ export function StatsPage() {
<td className="mono">{r.plays}</td>
<td className="mono">{pct(r.correct, r.plays)}</td>
<td className="mono">{r.avg_ms !== null ? `${(r.avg_ms / 1000).toFixed(1)}초` : '-'}</td>
<td className="mono">{pct(r.hints, r.plays)}</td>
<td className="mono">{r.plays ? (r.wrong / r.plays).toFixed(1) : '-'}</td>
<td className="mono">{r.replays}</td>
<td className="small">{fmt(r.last_at)}</td>
<td>
{r.suggest !== null && (

View File

@@ -40,11 +40,13 @@ const FIELD: Record<Field, string> = { title: '제목', artist: '가수', video:
const when = (ms: number | null) => (ms ? new Date(ms).toLocaleString('ko-KR', { dateStyle: 'short', timeStyle: 'short' }) : '-');
export function ReviewsPage() {
const [tab, setTab] = useState<'pending' | 'done'>('pending');
const [tab, setTab] = useState<'pending' | 'levels' | 'done'>('pending');
const counts = useReviewCount((s) => s);
const [list, setList] = useState<Review[] | null>(null);
const [genres, setGenres] = useState<Genre[]>([]);
const refreshCount = useReviewCount((s) => s.refresh);
const load = useCallback(() => {
if (tab === 'levels') return refreshCount();
apiCall<{ reviews: Review[] }>('GET', `/api/admin/reviews${tab === 'done' ? '?status=done' : ''}`)
.then((r) => setList(r.reviews))
.catch((e: Error) => toast(e.message, 'error'));
@@ -58,14 +60,21 @@ export function ReviewsPage() {
<>
<h1>검토 대기</h1>
<p className="muted">전체공개 퀴즈의 곡 중 서버 노래 DB에 없거나 DB와 다른 곡이에요. 고른 값이 서버 DB에 들어가고, 이 퀴즈의 복수정답도 DB 별칭에 들어가요. 한 번 정한 값은 다시 묻지 않아요.</p>
<div className="seg" role="tablist" style={{ maxWidth: 360 }}>
<div className="seg" role="tablist" style={{ maxWidth: 540 }}>
<button type="button" role="tab" aria-selected={tab === 'pending'} className={tab === 'pending' ? 'on' : ''} onClick={() => setTab('pending')}>
퀴즈 곡 검토
퀴즈 곡 {counts.songs ? `(${counts.songs})` : ''}
</button>
<button type="button" role="tab" aria-selected={tab === 'levels'} className={tab === 'levels' ? 'on' : ''} onClick={() => setTab('levels')}>
난이도 조정 {counts.levels ? `(${counts.levels})` : ''}
</button>
<button type="button" role="tab" aria-selected={tab === 'done'} className={tab === 'done' ? 'on' : ''} onClick={() => setTab('done')}>
처리한 것
</button>
</div>
{tab === 'levels' ? (
<LevelReviews onChange={refreshCount} />
) : (
<>
{list?.length === 0 && <p className="muted">{tab === 'pending' ? '검토할 곡이 없어요.' : '아직 처리한 것이 없어요.'}</p>}
<div className="stack" style={{ gap: 12 }}>
{list?.map((r) =>
@@ -84,6 +93,68 @@ export function ReviewsPage() {
),
)}
</div>
</>
)}
</>
);
}
interface LevelRow {
id: number;
title: string;
artist: string;
level: number | null;
suggest: number;
plays: number;
evidence: string[];
}
/** 난이도 조정: suggestions from play statistics, with the numbers behind them. */
function LevelReviews({ onChange }: { onChange: () => void }) {
const [rows, setRows] = useState<LevelRow[] | null>(null);
const load = useCallback(() => {
apiCall<{ rows: LevelRow[] }>('GET', '/api/admin/level-reviews')
.then((r) => setRows(r.rows))
.catch((e: Error) => toast(e.message, 'error'));
onChange();
}, [onChange]);
useEffect(load, [load]);
const act = (p: Promise<unknown>, msg: string) =>
void p.then(
() => (toast(msg), load()),
(e: Error) => toast(e.message, 'error'),
);
return (
<>
<p className="muted small">게임 기록(5번 이상 나온 곡)으로 계산한 제안이에요. "반영 안 함"을 누르면 5번 더 나온 뒤에 다시 계산해요.</p>
{rows?.length === 0 && <p className="muted">지금은 난이도 조정 제안이 없어요.</p>}
<div className="stack" style={{ gap: 12 }}>
{rows?.map((r) => (
<div key={r.id} className="card stack" style={{ gap: 8 }}>
<div className="row">
<b className="grow">
{r.title} <span className="muted">- {r.artist}</span>
</b>
<span className={`badge ${r.suggest > (r.level ?? 0) ? 'warn' : 'ok'}`}>
★{r.level} → ★{r.suggest} ({r.suggest > (r.level ?? 0) ? '더 어렵게' : '더 쉽게'})
</span>
</div>
<ul className="small" style={{ margin: 0, paddingLeft: 18 }}>
{r.evidence.map((e) => (
<li key={e}>{e}</li>
))}
</ul>
<div className="row">
<button type="button" className="btn btn-primary btn-sm" onClick={() => act(apiCall('POST', '/api/admin/stats/apply', { songId: r.id, level: r.suggest }), `★${r.suggest}로 바꿨어요.`)}>
★{r.suggest}로 바꾸기
</button>
<button type="button" className="btn btn-sm" onClick={() => act(apiCall('POST', `/api/admin/level-reviews/${r.id}/dismiss`), '이번 제안은 반영하지 않았어요.')}>
반영 안 함
</button>
</div>
</div>
))}
</div>
</>
);
}

View File

@@ -2,11 +2,13 @@
import { create } from 'zustand';
import { apiCall } from '../../net/api';
export const useReviewCount = create<{ n: number; refresh: () => void }>((set) => ({
export const useReviewCount = create<{ n: number; songs: number; levels: number; refresh: () => void }>((set) => ({
n: 0,
songs: 0,
levels: 0,
refresh: () => {
apiCall<{ pending: number }>('GET', '/api/admin/reviews/count')
.then((r) => set({ n: r.pending }))
apiCall<{ pending: number; songs: number; levels: number }>('GET', '/api/admin/reviews/count')
.then((r) => set({ n: r.pending, songs: r.songs, levels: r.levels }))
.catch(() => {});
},
}));