Reviewed-on: #375 Co-authored-by: miteruzo <miteruzo@naver.com> Co-committed-by: miteruzo <miteruzo@naver.com>
このコミットはPull リクエスト #375 でマージされました.
このコミットが含まれているのは:
バイナリファイルは表示されません.
|
変更前 幅: | 高さ: | サイズ: 559 KiB |
バイナリファイルは表示されません.
|
変更前 幅: | 高さ: | サイズ: 146 KiB |
バイナリファイルは表示されません.
|
変更前 幅: | 高さ: | サイズ: 1.2 MiB |
バイナリファイルは表示されません.
|
変更前 幅: | 高さ: | サイズ: 188 KiB |
バイナリファイルは表示されません.
|
変更前 幅: | 高さ: | サイズ: 201 KiB |
バイナリファイルは表示されません.
|
変更前 幅: | 高さ: | サイズ: 196 KiB |
バイナリファイルは表示されません.
|
変更前 幅: | 高さ: | サイズ: 179 KiB |
@@ -62,6 +62,7 @@ export type GekanatorExtraQuestion = {
|
||||
priorityWeight: number }
|
||||
|
||||
export type StoredGekanatorQuestion = {
|
||||
recordId?: number
|
||||
id: string
|
||||
text: string
|
||||
kind: GekanatorQuestionKind
|
||||
@@ -71,6 +72,7 @@ export type StoredGekanatorQuestion = {
|
||||
exampleAnswers?: Record<`${ number }`, GekanatorAnswerValue> }
|
||||
|
||||
export type GekanatorQuestion = {
|
||||
recordId?: number
|
||||
id: string
|
||||
text: string
|
||||
kind: GekanatorQuestionKind
|
||||
@@ -148,7 +150,7 @@ const directExampleAnswerFor = (
|
||||
question: StoredGekanatorQuestion,
|
||||
post: Post,
|
||||
): GekanatorAnswerValue | null => {
|
||||
if (question.kind !== 'post_similarity')
|
||||
if (question.kind !== 'post_similarity' && question.kind !== 'tag')
|
||||
return null
|
||||
|
||||
const direct = question.exampleAnswers?.[String (post.id) as `${ number }`]
|
||||
@@ -348,6 +350,7 @@ export const restoreGekanatorQuestion = (
|
||||
const normalizedCondition = normalizeTitleLengthCondition (question.condition)
|
||||
const normalizedQuestion = {
|
||||
...question,
|
||||
recordId: question.recordId,
|
||||
id: normalizedCondition.type === 'title-length-at-least'
|
||||
? `title:length-at-least:${ normalizedCondition.length }`
|
||||
: question.id,
|
||||
@@ -367,6 +370,7 @@ export const storeGekanatorQuestion = (
|
||||
id: question.condition.type === 'title-length-greater-than'
|
||||
? `title:length-at-least:${ question.condition.length + 1 }`
|
||||
: question.id,
|
||||
recordId: question.recordId,
|
||||
text: question.text,
|
||||
kind: question.kind,
|
||||
condition: normalizeTitleLengthCondition (question.condition),
|
||||
@@ -581,7 +585,7 @@ export const saveGekanatorGame = async ({
|
||||
guessedPostId: number
|
||||
correctPostId: number
|
||||
answers: GekanatorAnswerLog[]
|
||||
}): Promise<{ id: number }> =>
|
||||
}): Promise<{ id: number; learnedExampleCount: number }> =>
|
||||
await apiPost ('/gekanator/games', {
|
||||
guessed_post_id: guessedPostId,
|
||||
correct_post_id: correctPostId,
|
||||
@@ -595,15 +599,18 @@ export const saveGekanatorGame = async ({
|
||||
|
||||
export const saveGekanatorQuestionSuggestion = async ({
|
||||
gekanatorGameId,
|
||||
existingQuestionId,
|
||||
questionText,
|
||||
answer,
|
||||
}: {
|
||||
gekanatorGameId: number
|
||||
questionText: string
|
||||
existingQuestionId?: number
|
||||
questionText?: string
|
||||
answer: GekanatorAnswerValue
|
||||
}): Promise<{ id: number; count: number }> =>
|
||||
await apiPost ('/gekanator/question_suggestions', {
|
||||
gekanator_game_id: gekanatorGameId,
|
||||
existing_question_id: existingQuestionId,
|
||||
question_text: questionText,
|
||||
answer })
|
||||
|
||||
|
||||
@@ -51,6 +51,21 @@ const postSimilarityQuestion = (
|
||||
})
|
||||
|
||||
|
||||
const sourceQuestion = (
|
||||
host: string,
|
||||
): GekanatorQuestion => ({
|
||||
id: `source:${ host }`,
|
||||
text: `${ host }?`,
|
||||
kind: 'source',
|
||||
condition: {
|
||||
type: 'source',
|
||||
host },
|
||||
source: 'default',
|
||||
priorityWeight: 1,
|
||||
test: candidate => new URL (candidate.url).hostname === host,
|
||||
})
|
||||
|
||||
|
||||
const answer = (
|
||||
question: GekanatorQuestion,
|
||||
value: GekanatorAnswerValue,
|
||||
@@ -64,7 +79,7 @@ const answer = (
|
||||
|
||||
|
||||
describe('candidatePostsFor', () => {
|
||||
it('lets recovered candidates ignore old answers but not later answers', () => {
|
||||
it('does not hard-filter semantic post_similarity answers', () => {
|
||||
const posts = [post (1), post (2), post (3)]
|
||||
const oldQuestion = postSimilarityQuestion ('old', {
|
||||
1: 'no',
|
||||
@@ -77,6 +92,29 @@ describe('candidatePostsFor', () => {
|
||||
3: 'yes',
|
||||
})
|
||||
|
||||
const candidates = candidatePostsFor ({
|
||||
posts,
|
||||
questions: [oldQuestion, laterQuestion],
|
||||
answers: [answer (oldQuestion, 'yes'), answer (laterQuestion, 'yes')],
|
||||
softenedQuestionIds: new Set (),
|
||||
rejectedPostIds: new Set (),
|
||||
recoveredCandidatePosts: new Map ([
|
||||
[1, 1],
|
||||
[3, 1],
|
||||
]) })
|
||||
|
||||
expect(candidates.map (candidate => candidate.id)).toEqual ([1, 2, 3])
|
||||
})
|
||||
|
||||
it('lets recovered candidates ignore old fact answers but not later fact answers', () => {
|
||||
const posts = [
|
||||
{ ...post (1), url: 'https://other.example/posts/1' },
|
||||
post (2),
|
||||
{ ...post (3), url: 'https://example.com/posts/3' },
|
||||
]
|
||||
const oldQuestion = sourceQuestion ('old.example.com')
|
||||
const laterQuestion = sourceQuestion ('example.com')
|
||||
|
||||
const candidates = candidatePostsFor ({
|
||||
posts,
|
||||
questions: [oldQuestion, laterQuestion],
|
||||
@@ -112,7 +150,7 @@ describe('candidatePostsFor', () => {
|
||||
|
||||
|
||||
describe('hardFilteredPostsForAnswer', () => {
|
||||
it('returns zero candidates without falling back to the original pool', () => {
|
||||
it('keeps the original pool for semantic post_similarity answers', () => {
|
||||
const posts = [post (1), post (2)]
|
||||
const question = postSimilarityQuestion ('question', {
|
||||
1: 'yes',
|
||||
@@ -123,7 +161,41 @@ describe('hardFilteredPostsForAnswer', () => {
|
||||
posts,
|
||||
question,
|
||||
answer: 'no',
|
||||
})).toEqual ([])
|
||||
})).toEqual (posts)
|
||||
})
|
||||
|
||||
it('hard-filters fact answers only for yes and no', () => {
|
||||
const posts = [
|
||||
{ ...post (1), url: 'https://example.com/posts/1' },
|
||||
{ ...post (2), url: 'https://other.example/posts/2' },
|
||||
]
|
||||
const question = sourceQuestion ('example.com')
|
||||
|
||||
expect(hardFilteredPostsForAnswer ({
|
||||
posts,
|
||||
question,
|
||||
answer: 'yes',
|
||||
}).map (candidate => candidate.id)).toEqual ([1])
|
||||
expect(hardFilteredPostsForAnswer ({
|
||||
posts,
|
||||
question,
|
||||
answer: 'no',
|
||||
}).map (candidate => candidate.id)).toEqual ([2])
|
||||
expect(hardFilteredPostsForAnswer ({
|
||||
posts,
|
||||
question,
|
||||
answer: 'partial',
|
||||
})).toEqual (posts)
|
||||
expect(hardFilteredPostsForAnswer ({
|
||||
posts,
|
||||
question,
|
||||
answer: 'probably_no',
|
||||
})).toEqual (posts)
|
||||
expect(hardFilteredPostsForAnswer ({
|
||||
posts,
|
||||
question,
|
||||
answer: 'unknown',
|
||||
})).toEqual (posts)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -1,33 +1,33 @@
|
||||
import { expectedAnswerForQuestion } from '@/lib/gekanator'
|
||||
|
||||
import type {
|
||||
GekanatorAnswerLog,
|
||||
GekanatorAnswerValue,
|
||||
GekanatorQuestion,
|
||||
} from '@/lib/gekanator'
|
||||
import type { GekanatorAnswerLog, GekanatorAnswerValue, GekanatorQuestion } from '@/lib/gekanator'
|
||||
import type { Post } from '@/types'
|
||||
|
||||
|
||||
export type RecoveredCandidatePost = {
|
||||
postId: number
|
||||
answerCountAtRecovery: number }
|
||||
|
||||
|
||||
export const candidatePostsFor = ({
|
||||
posts,
|
||||
questions,
|
||||
answers,
|
||||
softenedQuestionIds,
|
||||
rejectedPostIds,
|
||||
recoveredCandidatePosts,
|
||||
}: {
|
||||
posts: Post[]
|
||||
questions: GekanatorQuestion[]
|
||||
answers: GekanatorAnswerLog[]
|
||||
softenedQuestionIds: Set<string>
|
||||
rejectedPostIds: Set<number>
|
||||
recoveredCandidatePosts: Map<number, number>
|
||||
}): Post[] => {
|
||||
const questionIsFactLikeForHardFiltering = (question: GekanatorQuestion): boolean =>
|
||||
!(question.kind === 'post_similarity'
|
||||
|| (question.kind === 'tag'
|
||||
&& question.condition.type === 'tag'
|
||||
&& !(question.condition.key.startsWith ('nico:'))))
|
||||
|
||||
|
||||
export const candidatePostsFor = (
|
||||
{ posts,
|
||||
questions,
|
||||
answers,
|
||||
softenedQuestionIds,
|
||||
rejectedPostIds,
|
||||
recoveredCandidatePosts }: { posts: Post[]
|
||||
questions: GekanatorQuestion[]
|
||||
answers: GekanatorAnswerLog[]
|
||||
softenedQuestionIds: Set<string>
|
||||
rejectedPostIds: Set<number>
|
||||
recoveredCandidatePosts: Map<number, number> },
|
||||
): Post[] => {
|
||||
const questionById = new Map (questions.map (question => [question.id, question]))
|
||||
|
||||
return posts.filter (post => {
|
||||
@@ -37,7 +37,7 @@ export const candidatePostsFor = ({
|
||||
const answerCountAtRecovery = recoveredCandidatePosts.get (post.id)
|
||||
|
||||
return answers.every ((answer, index) => {
|
||||
if (answerCountAtRecovery !== undefined && index < answerCountAtRecovery)
|
||||
if (answerCountAtRecovery != null && index < answerCountAtRecovery)
|
||||
return true
|
||||
|
||||
if (softenedQuestionIds.has (answer.questionId))
|
||||
@@ -46,14 +46,17 @@ export const candidatePostsFor = ({
|
||||
const question = questionById.get (answer.questionId)
|
||||
if (!(question))
|
||||
return true
|
||||
if (!(questionIsFactLikeForHardFiltering (question)))
|
||||
return true
|
||||
|
||||
switch (answer.answer)
|
||||
{
|
||||
case 'yes':
|
||||
case 'no': {
|
||||
const expected = expectedAnswerForQuestion (question, post)
|
||||
return expected === null || expected === 'unknown' || expected === answer.answer
|
||||
}
|
||||
case 'no':
|
||||
{
|
||||
const expected = expectedAnswerForQuestion (question, post)
|
||||
return expected === null || expected === 'unknown' || expected === answer.answer
|
||||
}
|
||||
default:
|
||||
return true
|
||||
}
|
||||
@@ -62,30 +65,25 @@ export const candidatePostsFor = ({
|
||||
}
|
||||
|
||||
|
||||
export const hardFilteredPostsForAnswer = ({
|
||||
posts,
|
||||
question,
|
||||
answer,
|
||||
}: {
|
||||
posts: Post[]
|
||||
question: GekanatorQuestion
|
||||
answer: GekanatorAnswerValue
|
||||
}): Post[] => {
|
||||
if (answer === 'unknown')
|
||||
export const hardFilteredPostsForAnswer = (
|
||||
{ posts, question, answer }: { posts: Post[]
|
||||
question: GekanatorQuestion
|
||||
answer: GekanatorAnswerValue },
|
||||
): Post[] => {
|
||||
if (!(questionIsFactLikeForHardFiltering (question)))
|
||||
return posts
|
||||
|
||||
if (!(answer === 'yes' || answer === 'no'))
|
||||
return posts
|
||||
|
||||
return posts.filter (post => {
|
||||
const expected = expectedAnswerForQuestion (question, post)
|
||||
return expected === null || expected === 'unknown' || expected === answer
|
||||
return expected == null || expected === 'unknown' || expected === answer
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
const concreteAnswerOptions: GekanatorAnswerValue[] = [
|
||||
'yes',
|
||||
'no',
|
||||
'partial',
|
||||
'probably_no']
|
||||
const concreteAnswerOptions: GekanatorAnswerValue[] = ['yes', 'no', 'partial', 'probably_no']
|
||||
|
||||
|
||||
export const allConcreteAnswerOptionsExhausted = (
|
||||
@@ -104,45 +102,39 @@ const nextRecoveryTargetSize = (recoveryStepCount: number): number =>
|
||||
6 * (2 ** recoveryStepCount)
|
||||
|
||||
|
||||
export const recoverCandidatePosts = ({
|
||||
posts,
|
||||
scores,
|
||||
rejectedPostIds,
|
||||
recoveredCandidatePosts,
|
||||
eligiblePostIds,
|
||||
answerCountAtRecovery,
|
||||
recoveryStepCount,
|
||||
}: {
|
||||
posts: Post[]
|
||||
scores: Map<number, number>
|
||||
rejectedPostIds: Set<number>
|
||||
recoveredCandidatePosts: Map<number, number>
|
||||
eligiblePostIds: Set<number>
|
||||
answerCountAtRecovery: number
|
||||
recoveryStepCount: number
|
||||
}): {
|
||||
recoveredCandidatePosts: Map<number, number>
|
||||
recoveryStepCount: number
|
||||
} | null => {
|
||||
export const recoverCandidatePosts = (
|
||||
{ posts,
|
||||
scores,
|
||||
rejectedPostIds,
|
||||
recoveredCandidatePosts,
|
||||
eligiblePostIds,
|
||||
answerCountAtRecovery,
|
||||
recoveryStepCount }: { posts: Post[]
|
||||
scores: Map<number, number>
|
||||
rejectedPostIds: Set<number>
|
||||
recoveredCandidatePosts: Map<number, number>
|
||||
eligiblePostIds: Set<number>
|
||||
answerCountAtRecovery: number
|
||||
recoveryStepCount: number },
|
||||
): { recoveredCandidatePosts: Map<number, number>
|
||||
recoveryStepCount: number } | null => {
|
||||
const recovered = new Map (recoveredCandidatePosts)
|
||||
const targetSize = nextRecoveryTargetSize (recoveryStepCount)
|
||||
const countedPostIds = new Set ([
|
||||
...eligiblePostIds,
|
||||
...recovered.keys ()])
|
||||
const countedPostIds = new Set ([...eligiblePostIds, ...recovered.keys ()])
|
||||
const addCount = targetSize - countedPostIds.size
|
||||
if (addCount <= 0)
|
||||
return {
|
||||
recoveredCandidatePosts: recovered,
|
||||
recoveryStepCount: recoveryStepCount + 1 }
|
||||
{
|
||||
return { recoveredCandidatePosts: recovered,
|
||||
recoveryStepCount: recoveryStepCount + 1 }
|
||||
}
|
||||
|
||||
const candidates = posts
|
||||
.filter (post =>
|
||||
!(rejectedPostIds.has (post.id))
|
||||
&& !(eligiblePostIds.has (post.id))
|
||||
&& !(recovered.has (post.id)))
|
||||
.sort ((a, b) =>
|
||||
(scores.get (b.id) ?? Number.NEGATIVE_INFINITY)
|
||||
- (scores.get (a.id) ?? Number.NEGATIVE_INFINITY))
|
||||
const candidates =
|
||||
posts
|
||||
.filter (post => (!(rejectedPostIds.has (post.id))
|
||||
&& !(eligiblePostIds.has (post.id))
|
||||
&& !(recovered.has (post.id))))
|
||||
.sort ((a, b) => ((scores.get (b.id) ?? Number.NEGATIVE_INFINITY)
|
||||
- (scores.get (a.id) ?? Number.NEGATIVE_INFINITY)))
|
||||
.slice (0, addCount)
|
||||
|
||||
if (candidates.length === 0)
|
||||
@@ -150,7 +142,6 @@ export const recoverCandidatePosts = ({
|
||||
|
||||
candidates.forEach (post => recovered.set (post.id, answerCountAtRecovery))
|
||||
|
||||
return {
|
||||
recoveredCandidatePosts: recovered,
|
||||
recoveryStepCount: recoveryStepCount + 1 }
|
||||
return { recoveredCandidatePosts: recovered,
|
||||
recoveryStepCount: recoveryStepCount + 1 }
|
||||
}
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { resolve } from 'node:path'
|
||||
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import { isQuestionHardFilteredAfterAnswers } from '@/lib/gekanatorQuestionFilters'
|
||||
@@ -49,6 +52,57 @@ const blocked = (
|
||||
isQuestionHardFilteredAfterAnswers (question (candidate), [answer (previous, value)])
|
||||
|
||||
|
||||
const gekanatorPageSource = readFileSync (
|
||||
resolve (process.cwd (), 'src/pages/GekanatorPage.tsx'),
|
||||
'utf8')
|
||||
|
||||
const gekanatorBackdropSource = gekanatorPageSource.slice (
|
||||
gekanatorPageSource.indexOf ('const GekanatorBackdrop'),
|
||||
gekanatorPageSource.indexOf ('const expectedAnswerFor'))
|
||||
|
||||
|
||||
describe('GekanatorBackdrop regression structure', () => {
|
||||
it('keeps displayedBackdropMode as the render-time source of truth', () => {
|
||||
expect(gekanatorBackdropSource).not.toContain ('isLeavingGuessBackdrop')
|
||||
expect(gekanatorBackdropSource).not.toContain ('renderBackdropMode')
|
||||
expect(gekanatorBackdropSource).not.toContain ('renderWinningRunCount')
|
||||
expect(gekanatorBackdropSource).not.toContain ('renderThumbnails')
|
||||
expect(gekanatorBackdropSource).not.toContain ('renderIsCrossfading')
|
||||
|
||||
expect(gekanatorBackdropSource).toContain (
|
||||
"const renderedSettings = settingsForMode (displayedBackdropMode)")
|
||||
expect(gekanatorBackdropSource).toContain (
|
||||
'scaleForMode (displayedBackdropMode, displayedWinningRunCount)')
|
||||
expect(gekanatorBackdropSource).toContain (
|
||||
"backdropMode === 'guess' || displayedBackdropMode === 'guess'")
|
||||
})
|
||||
|
||||
it('does not split guess into a separate renderer or force a remount', () => {
|
||||
expect(gekanatorBackdropSource).not.toContain ('renderStaticGuessBackdrop')
|
||||
expect(gekanatorBackdropSource).not.toContain ('guessZoomAnimationKey')
|
||||
expect(gekanatorBackdropSource).not.toContain ('shouldAnimateGuessZoomIn')
|
||||
expect(gekanatorBackdropSource).not.toContain ('previousBackdropModeRef')
|
||||
expect(gekanatorBackdropSource).not.toContain (
|
||||
'if (isGuessPresentation && guessThumbnail)')
|
||||
})
|
||||
|
||||
it('keeps tile keys independent from backdrop mode', () => {
|
||||
expect(gekanatorBackdropSource).toContain ('key={duplicate}')
|
||||
expect(gekanatorBackdropSource).toContain ('key={`${ duplicate }:${ index }`}')
|
||||
expect(gekanatorBackdropSource).not.toMatch (/key=\{`\$\{\s*mode/)
|
||||
expect(gekanatorBackdropSource).not.toMatch (/key=\{`\$\{\s*displayedBackdropMode/)
|
||||
})
|
||||
|
||||
it('keeps guess on the shared scale, x, and y animation path', () => {
|
||||
expect(gekanatorBackdropSource).toContain ('animate={{ scale: renderedScale')
|
||||
expect(gekanatorBackdropSource).toContain (
|
||||
"x: displayedBackdropMode === 'guess' ? guessFocusOffset.x : '0%'")
|
||||
expect(gekanatorBackdropSource).toContain (
|
||||
"y: displayedBackdropMode === 'guess' ? guessFocusOffset.y : '0%'")
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
describe('isQuestionHardFilteredAfterAnswers', () => {
|
||||
it('blocks only contradictory or redundant month questions after a yes answer', () => {
|
||||
const previous: GekanatorQuestionCondition = { type: 'original-month', month: 12 }
|
||||
|
||||
+1095
-770
ファイル差分が大きすぎるため省略します
差分を読込み
@@ -139,6 +139,10 @@ export type Post = {
|
||||
title: string | null
|
||||
thumbnail: string | null
|
||||
thumbnailBase: string | null
|
||||
postSimilarityEdges?: {
|
||||
targetPostId: number
|
||||
cos: number
|
||||
}[]
|
||||
tags: Tag[]
|
||||
parentPosts?: Post[]
|
||||
childPosts?: Post[]
|
||||
|
||||
新しい課題から参照
ユーザをブロックする