Compare commits

..

3 Commits

10 changed files with 91 additions and 15 deletions

View File

@@ -40,7 +40,7 @@ const LETTER: Record<string, string> = {
const isLatinText = (t: string) => /[A-Za-z]/.test(t) && !/[\p{Script=Hangul}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Han}]/u.test(t);
const MAX_READINGS = 4;
/** Spacing counts in the default answer check: each spelling also without its spaces (로드 스튜어트 / 로드스튜어트). */
/** Each spelling also without its spaces (로드 스튜어트 / 로드스튜어트), for rooms that turn 띄어쓰기 on in 정답인식. */
const withJoined = (list: string[]) => [...new Set(list.flatMap((r) => (/\s/.test(r) ? [r, r.replace(/\s+/g, '')] : [r])))];
/**

View File

@@ -145,7 +145,7 @@ switch (cmd) {
const oldTables = i >= 0 ? [(await Bun.file(rest[i + 1]!).json()) as LexiconTable] : [];
const r = redoReadings(db, { dryRun: rest.includes('--dry-run'), oldTables });
for (const e of r.examples) console.log(`${e.where}\t${e.name}\t- ${e.drop.join(', ')}\t+ ${e.add.join(', ')}`);
console.log(JSON.stringify({ songs: r.songs, quizItems: r.quizItems, unknownSongs: r.unknownSongs, unknownWords: r.unknownWords.size }));
console.log(JSON.stringify({ songs: r.songs, quizItems: r.quizItems, pendingReviews: r.pendingReviews, unknownSongs: r.unknownSongs, unknownWords: r.unknownWords.size }));
break;
}
case 'lexicon-missing': {

View File

@@ -69,3 +69,29 @@ test('saved quizzes: generated readings replaced, typed answers kept, 이지선
expect(JSON.parse(got(a).a)).toEqual(['정꾹이', '정국']);
expect(got(b)).toEqual({ t: '[]', a: '[]' });
});
test('제목 정리 rows still waiting get the new spellings too: applying one later does not bring the old reading back', async () => {
const { applyTitleReviews } = await import('./songs/title-review');
const db = openDb(tempDbPath());
const [id] = new Catalog(db).upsert({ title: 'Heaven (feat. X)', artists: [{ name: 'Rod Stewart' }], source: 't', ref: '1' });
db.query(
"INSERT INTO title_reviews (song_id, kind, status, old_title, old_artist, new_title, new_artist, title_answers, artist_answers, created_at) VALUES (?, 'title', 'pending', 'Heaven (feat. X)', 'Rod Stewart', 'Heaven', 'Rod Stewart', ?, ?, 0)",
).run(id!, JSON.stringify(['헤벤']), JSON.stringify(['로드 스투어트']));
expect(redoReadings(db).pendingReviews).toBe(1);
expect(applyTitleReviews(db, { ids: [id!] }, 'admin').applied).toBe(1);
expect(aliases(db, id!, 'title')).toEqual(['Heaven (feat. X)', '헤븐']);
expect(aliases(db, id!, 'artist')).toEqual(['로드 스튜어트', '로드스튜어트']);
});
test('saved quizzes: an answer the song DB has from a person (quiz save / admin) stays even when it equals an old generated reading', () => {
const db = openDb(tempDbPath());
db.query("INSERT INTO users (id, kind, nickname, created_at, last_seen_at) VALUES ('u', 'member', 'u', 0, 0)").run();
const quiz = (db.query("INSERT INTO custom_quizzes (owner_id, name, description, visibility, settings_json, kind, created_at, updated_at) VALUES ('u', 'q', '', 'private', '{}', 'normal', 0, 0) RETURNING id").get() as { id: number }).id;
const [song] = new Catalog(db).upsert({ title: 'Heaven', artists: [{ name: '에일리' }], source: 't', ref: '1' });
db.query("INSERT INTO song_aliases (song_id, part, alias, source) VALUES (?, 'title', '헤벤', 'quiz')").run(song!);
const it = (db.query("INSERT INTO custom_quiz_items (quiz_id, pos, song_id, video_id, title, artist, title_answers, artist_answers) VALUES (?, 0, ?, 'aaaaaaaaaaa', 'Heaven', '에일리', ?, '[]') RETURNING id").get(quiz, song!, JSON.stringify(['헤벤'])) as { id: number }).id;
redoReadings(db);
expect(JSON.parse(db.query<{ t: string }, [number]>('SELECT title_answers t FROM custom_quiz_items WHERE id = ?').get(it)!.t)).toEqual(['헤벤', '헤븐']);
// the song's own typed alias is never touched either
expect(aliases(db, song!, 'title')).toEqual(['헤벤', '헤븐']);
});

View File

@@ -91,7 +91,7 @@ describe('rooms over WebSocket', () => {
const { a, cb, code } = await setup();
const r = await nextRoom(cb, (x) => x.players.length === 2);
expect(r.hostId).toBe(a.id);
expect(r.config).toMatchObject({ title: '방장님의 방', level: 3, answer: 'title', strict: { space: true, number: true, symbol: true }, hint: 'none', count: 30 });
expect(r.config).toMatchObject({ title: '방장님의 방', level: 3, answer: 'title', strict: { space: false, number: true, symbol: true }, hint: 'none', count: 30 });
expect((await api(s.base, '/api/rooms')).body.rooms.map((x: any) => x.code)).toEqual([code]);
expect((await api(s.base, `/api/rooms/${code}`)).body).toMatchObject({ code, players: 2, status: 'lobby' });
});

View File

@@ -98,6 +98,8 @@ export function planReadings(
export interface RedoResult {
songs: { changed: number; dropped: number; added: number };
quizItems: { changed: number; dropped: number; added: number };
/** 제목 정리 rows still waiting: their answers are applied later, so they get the same change. */
pendingReviews: number;
unknownSongs: number;
unknownWords: Map<string, number>;
examples: { where: string; name: string; drop: string[]; add: string[] }[];
@@ -108,7 +110,7 @@ export interface RedoResult {
* as it was before (`oldTables`, from git) so the spellings it made go too.
*/
export function redoReadings(db: Database, opts: { dryRun?: boolean; oldTables?: LexiconTable[] } = {}): RedoResult {
const out: RedoResult = { songs: { changed: 0, dropped: 0, added: 0 }, quizItems: { changed: 0, dropped: 0, added: 0 }, unknownSongs: 0, unknownWords: new Map(), examples: [] };
const out: RedoResult = { songs: { changed: 0, dropped: 0, added: 0 }, quizItems: { changed: 0, dropped: 0, added: 0 }, pendingReviews: 0, unknownSongs: 0, unknownWords: new Map(), examples: [] };
const songs = db
.query<{ id: number; title: string; artist: string; old_title: string | null }, []>(
'SELECT s.id, s.title, s.artist, r.old_title FROM songs s LEFT JOIN title_reviews r ON r.song_id = s.id WHERE s.deleted_at IS NULL ORDER BY s.id',
@@ -146,17 +148,46 @@ export function redoReadings(db: Database, opts: { dryRun?: boolean; oldTables?:
for (const a of plan.title.add) add.run(s.id, 'title', a.slice(0, 200));
for (const a of plan.artist.add) add.run(s.id, 'artist', a.slice(0, 200));
}
// 이지선다 quizzes have no answers
const items = db
.query<{ id: number; title: string; artist: string; title_answers: string; artist_answers: string }, []>(
"SELECT i.id, i.title, i.artist, i.title_answers, i.artist_answers FROM custom_quiz_items i JOIN custom_quizzes q ON q.id = i.quiz_id WHERE q.kind <> 'duel'",
// 제목 정리 rows not applied yet: whatever they would add is all generated (made by buildTitleReviews)
const pending = db
.query<{ song_id: number; old_title: string; new_title: string; new_artist: string; title_answers: string; artist_answers: string }, []>(
"SELECT song_id, old_title, new_title, new_artist, title_answers, artist_answers FROM title_reviews WHERE status = 'pending'",
)
.all();
const saveReview = db.query('UPDATE title_reviews SET title_answers = ?, artist_answers = ? WHERE song_id = ?');
for (const r of pending) {
const ta = JSON.parse(r.title_answers) as string[];
const aa = JSON.parse(r.artist_answers) as string[];
const plan = planReadings({ title: r.new_title, artist: r.new_artist, source: r.old_title, titleAnswers: ta, artistAnswers: aa }, opts.oldTables);
if (!plan.title.drop.length && !plan.artist.drop.length && !plan.title.add.length && !plan.artist.add.length) continue;
out.pendingReviews++;
const dT = new Set(plan.title.drop);
const dA = new Set(plan.artist.drop);
if (!opts.dryRun)
saveReview.run(
JSON.stringify([...ta.filter((a) => !dT.has(a)), ...plan.title.add].slice(0, 30)),
JSON.stringify([...aa.filter((a) => !dA.has(a)), ...plan.artist.add].slice(0, 30)),
r.song_id,
);
}
// 이지선다 quizzes have no answers. A quiz answer has no record of who wrote it: a generated one is recognised by being
// what the old reader made from that item's own names; one the song's DB also has from an admin or a quiz save
// (song_aliases source other than 'auto') is someone's typing and stays.
const items = db
.query<{ id: number; song_id: number | null; title: string; artist: string; title_answers: string; artist_answers: string }, []>(
"SELECT i.id, i.song_id, i.title, i.artist, i.title_answers, i.artist_answers FROM custom_quiz_items i JOIN custom_quizzes q ON q.id = i.quiz_id WHERE q.kind <> 'duel'",
)
.all();
const typed = db.query<{ part: string; alias: string }, [number]>("SELECT part, alias FROM song_aliases WHERE song_id = ? AND source <> 'auto'");
const save = db.query('UPDATE custom_quiz_items SET title_answers = ?, artist_answers = ? WHERE id = ?');
for (const it of items) {
const ta = JSON.parse(it.title_answers) as string[];
const aa = JSON.parse(it.artist_answers) as string[];
const plan = planReadings({ title: it.title, artist: it.artist, titleAnswers: ta, artistAnswers: aa }, opts.oldTables);
const own = it.song_id ? typed.all(it.song_id) : [];
const mine = (part: string, a: string) => own.some((x) => x.part === part && low(x.alias) === low(a));
plan.title.drop = plan.title.drop.filter((a) => !mine('title', a));
plan.artist.drop = plan.artist.drop.filter((a) => !mine('artist', a));
if (!plan.title.drop.length && !plan.artist.drop.length && !plan.title.add.length && !plan.artist.add.length) continue;
const dT = new Set(plan.title.drop);
const dA = new Set(plan.artist.drop);

View File

@@ -14,7 +14,7 @@
| 연도 | 범위 슬라이더 + 시작/끝 선택 상자 | 전체(가장 오래된 곡 ~ 올해) |
| 난이도 | 별 10개, 왼쪽부터 채움 — N단계 곡만 | 3 (Q7) |
| 정답방식 | 제목만 / 가수만 / 제목+가수(순서 무관) | 제목만 |
| 정답인식 | 띄어쓰기 · 숫자 · 특수문자 각각 켜기/끄기 | **모두 켬** (Q2) |
| 정답인식 | 띄어쓰기 · 숫자 · 특수문자 각각 켜기/끄기 | **띄어쓰기 끔, 숫자·특수문자 켬** (Q2) |
| 힌트공개 | 없음, 15초, 30초, 45초, 60초, 직접선택 | 없음 |
| └ 힌트인원(이상) (직접선택일 때) | 1명, 2명, 1/3명, 1/2명, 2/3명, 전체 | 1/3명 (Q3) |
| 스킵인원(이상) | 없음, 1명, 2명, 1/3명, 1/2명, 2/3명, 전체 | 1/3명 |
@@ -110,7 +110,7 @@
## 정답방식 · 정답인식
- 정답방식: 제목만 / 가수만 / 제목+가수 — 제목+가수는 **순서 상관없이** 한 줄에 둘 다 (05 문서 판정 규칙)
- 정답인식: 버튼 3개, 누를 때마다 켜짐/꺼짐
- **켜짐 = 그 요소까지 정확히 쳐야 정답**, 꺼짐 = 무시하고 비교 (확정: Q2), 기본은 셋 다 켬
- **켜짐 = 그 요소까지 정확히 쳐야 정답**, 꺼짐 = 무시하고 비교 (확정: Q2), 기본은 띄어쓰기 끔·숫자 켬·특수문자 켬 (2026-11-04)
- 대소문자는 항상 무시
## 힌트공개

View File

@@ -7,7 +7,7 @@
| # | 결정 | 영향 문서 |
|---|---|---|
| Q1 | **B안: 숨긴 유튜브 플레이어(IFrame)** 로 재생. 대신 모두 같은 순간에 듣고, 버퍼링으로 한 명이 못 듣는 일이 없게 한다 | 08 |
| Q2 | 정답인식 켜짐 = 그 요소까지 정확히 쳐야 정답. **기본값: 띄어쓰기·숫자·특수문자 모두 켬** | 04, 05 |
| Q2 | 정답인식 켜짐 = 그 요소까지 정확히 쳐야 정답. **기본값: 띄어쓰기 끔, 숫자·특수문자 켬** (2026-11-04 변경) | 04, 05 |
| Q3 | 힌트공개에 **직접선택** 추가(60초 뒤). 직접선택이면 **힌트인원** 설정이 생기고 투표로 공개 | 04, 05 |
| Q4 | **다시듣기 투표**(모두 같이 다시 듣기), 단축키 **Ctrl+R**, 설정에 **다시듣기인원** | 04, 05, 06 |
| Q5 | 먼저 맞힌 1명만 +1 | 05 |
@@ -59,7 +59,8 @@
## Q2. 정답인식 기본값
- 켜짐 = 그 요소까지 똑같이 쳐야 정답, 꺼짐 = 무시하고 비교
- 새 방 기본값: **띄어쓰기 켬, 숫자 켬, 특수문자 켬**(가장 엄격). 대소문자는 항상 무시
- 새 방·새 퀴즈 기본값: **띄어쓰기 끔, 숫자 켬, 특수문자 켬**. 대소문자는 항상 무시. 방장은 띄어쓰기를 다시 켤 수 있다
- 2026-11-04 사용자 요청으로 바꿈(전에는 셋 다 켬). 이미 만든 퀴즈 2개(테스트용1, 테스트용1 이지선다)의 저장된 설정도 띄어쓰기 끔으로 맞춤
- 엄격 모드라도 관리자 별칭으로 흔한 표기 차이(`광` / `광 (狂)`, 괄호 속 영어 제목 등)는 흡수한다 — 정답 후보 만들기 규칙(05)은 그대로
## Q3. 힌트

View File

@@ -47,13 +47,16 @@
- words 2,299 / titles 74(단어별로 읽으면 틀리는 제목) / artists 1,111(가수 이름 통째, 한국 공식 이름·일본 이름 성-이름 순서 포함)
- 만든 방법: DB 영어 제목 단어 2,265개·가수 이름 1,155개(+ 영어 위키백과 → 한국어 문서 이름 764개)를 10묶음으로 나눠 검수, 띄어쓰기 보정, 손으로 고친 것(overrides). 작업 파일은 저장소 밖(`~/work/mq/lex/`)
- 두 표기가 흔하면 둘 다(썸머/서머), 확실하지 않은 것은 넣지 않음(제목 단어 16, 가수 60)
- 정답 판정 기본값이 띄어쓰기를 보므로 띄어 쓴 꼴과 붙여 쓴 꼴 둘 다 넣음(로드 스튜어트 / 로드스튜어트)
- 띄어 쓴 꼴과 붙여 쓴 꼴 둘 다 넣음(로드 스튜어트 / 로드스튜어트). 처음에는 기본값이 띄어쓰기를 봐서 넣었고, 2026-11-04부터 기본값은 띄어쓰기를 무시하지만 방장이 띄어쓰기를 켠 방을 위해 그대로 둠
- 표기표에 없는 단어가 있으면 그 글에는 발음 정답 없음 → `unknownWords`. 새 곡(02:50 clean-titles)은 '확인 필요' 검토(비고 '발음 확인 필요: …'), 관리자 → 제목 정리에서 '제목/가수 정답 더하기'로 직접 넣고 적용
- 다음 표기표 갱신: `cli.ts lexicon-missing`(없는 단어, 규칙 후보, 곡 수) → lexicon.json에 추가 → 배포
- 이미 들어간 발음 정답 바꾸기: `cli.ts redo-readings [--dry-run] [--old-lexicon 고치기전.json]` — 옛 규칙(과 넘긴 이전 표기표)이 그 곡 이름에서 만든 것과 같은 정답(source auto)만 빼고 표기표 표기를 넣음. 관리자가 넣은 별칭·퀴즈에 직접 쓴 정답은 그대로, 이지선다 퀴즈는 안 건드림. 표기표를 고친 뒤에는 `git show <고치기 전>:apps/server/src/answers/lexicon.json`을 --old-lexicon으로 넘겨야 이전 표기가 빠짐
- 멜론 차트 파서: 재생이 막힌 곡은 제목 칸에 링크가 없어 다음 링크(가수)를 제목으로 읽던 것 → 제목 칸만 읽음. `cli.ts fix-melon-titles [--dry-run]`: 제목이 가수 이름과 같은 멜론 곡을 곡 정보 페이지 제목으로 고침(자기 이름 곡 소녀시대 등은 그대로), 자동 정답·제목 정리 행을 지우고 clean-titles로 다시, 제목으로 잘못 찾은 후보 영상은 원곡 찾기로 되돌림
- `decodeEntities`: `&eacute;`·`&deg;` 등 라틴 문자 이름 추가(C&eacute;line Dion) → `cli.ts fix-text`로 DB 고침
- 퀴즈 파일 가수 칸의 따옴표 안('Miki Matsubara Official "stay with me"')을 with로 자르지 않음(가수 정답 '미' 같은 조각)
- 배포 (2026-11-04 20:44~): 백업 `~/backups/music_quiz/app-before-readings-20261104-2044.db` → eac4d97 배포 → `fix-text`(16곡, C&eacute;line Dion 등) → `fix-melon-titles` 18곡(Rod Stewart → Your Song 등, Chuckie는 같은 곡 10449에 합침, 16곡 바로 반영) → `redo-readings`(DB 3,707곡: 옛 발음 2,328개 빼고 10,533개 넣음 / 일반 퀴즈 30곡) → 테스트용1 真夜中のドア 가수 칸 'Miki Matsubara'로 → `redo-readings` 한 번 더(그 곡 가수 발음 6개). 두 번째부터는 바뀌는 것 없음. 표기표에 없는 단어가 남은 곡 56곡(대부분 누군지 확인 안 된 가수 이름)
- redo-readings는 아직 적용 안 된 제목 정리 행(pending)의 정답도 같이 바꿈(나중에 적용해도 옛 발음이 안 돌아오게). 퀴즈 정답에는 누가 썼는지 기록이 없어서 '그 곡 이름으로 옛 규칙이 만든 것과 같은 값'을 자동으로 봄 — 연결된 DB 곡에 사람이 넣은 별칭(source quiz/admin)으로도 있는 값은 남김. 반영 때 빠진 퀴즈 정답 18개는 백업과 대조해 모두 옛 규칙 결과(융 쿠크, 어 하, 헤벤, 미 …)임을 확인
- 'Sheep (Alan Walker Relift)'(10550)는 리믹스라 휴지통 기준에 해당 — 사용자 확인 대기
## 운영 DB에서 확인한 숫자 (2026-11-04 사본)
- 10,762곡, 제목이 바뀌는 곡 617곡

View File

@@ -1,5 +1,6 @@
import { describe, expect, test } from 'bun:test';
import { artistCandidates, chosung, hintText, isCorrect, titleCandidates, type Strictness } from './answer';
import { DEFAULT_ROOM_CONFIG } from './room-config';
const STRICT: Strictness = { space: true, number: true, symbol: true };
const LOOSE: Strictness = { space: false, number: false, symbol: false };
@@ -42,6 +43,20 @@ describe('정답인식 toggles (docs/12 Q2): on = must match, off = ignored', ()
expect(isCorrect('시간이 모자라', song('24시간이 모자라'), 'title', STRICT)).toBe(false);
expect(isCorrect('시간이 모자라', song('24시간이 모자라'), 'title', st({ number: false }))).toBe(true);
});
test('새 방 기본값: 띄어쓰기·대소문자 무시, 숫자·특수문자는 쳐야 정답', () => {
const d = DEFAULT_ROOM_CONFIG.strict;
expect(d).toEqual({ space: false, number: true, symbol: true });
expect(isCorrect('사건의지평선', song('사건의 지평선'), 'title', d)).toBe(true);
expect(isCorrect('사 건의지평선', song('사건의 지평선'), 'title', d)).toBe(true);
expect(isCorrect('yoursong', song('Your Song'), 'title', d)).toBe(true);
expect(isCorrect('YOUR SONG', song('Your Song'), 'title', d)).toBe(true);
expect(isCorrect('love', song('Love?'), 'title', d)).toBe(false);
expect(isCorrect('LOVE?', song('Love?'), 'title', d)).toBe(true);
expect(isCorrect('1111', song('11:11'), 'title', d)).toBe(false);
expect(isCorrect('11:11', song('11:11'), 'title', d)).toBe(true);
expect(isCorrect('시간이 모자라', song('24시간이 모자라'), 'title', d)).toBe(false);
expect(isCorrect('24시간이모자라', song('24시간이 모자라'), 'title', d)).toBe(true);
});
test('no fuzzy matching', () => {
expect(isCorrect('사건의 지평산', song('사건의 지평선'), 'title', LOOSE)).toBe(false);
expect(isCorrect('사건의', song('사건의 지평선'), 'title', LOOSE)).toBe(false);

View File

@@ -46,7 +46,7 @@ export interface RoomConfig {
/** Exactly this level (docs/12 Q7). */
level: number;
answer: 'title' | 'artist' | 'both';
/** 정답인식: true = must match that element too (docs/12 Q2). */
/** 정답인식: true = must match that element too (docs/12 Q2). Default: spaces ignored, digits and symbols must match. */
strict: { space: boolean; number: boolean; symbol: boolean };
/** 'none' | seconds | 'manual' (직접선택). */
hint: 'none' | (typeof HINT_TIMES)[number] | 'manual';
@@ -79,7 +79,7 @@ export const DEFAULT_ROOM_CONFIG: RoomConfig = {
yearTo: null,
level: 3,
answer: 'title',
strict: { space: true, number: true, symbol: true },
strict: { space: false, number: true, symbol: true },
hint: 'none',
hintVotes: '1/3',
skipVotes: '1/3',