dramaling-vocab-learning/frontend/data/mockTestData.ts

101 lines
3.2 KiB
TypeScript

/**
* 測試用假數據 - 使用 example-data.json 的真實數據結構
*/
import exampleData from '@/app/review-design/example-data.json'
export interface MockFlashcard {
id: string
word: string
definition: string
example: string
translation: string
exampleTranslation: string
pronunciation: string
difficultyLevel: 'A1' | 'A2' | 'B1' | 'B2' | 'C1' | 'C2'
exampleImage?: string
synonyms: string[]
filledQuestionText?: string
// 測試用欄位
testPriority?: number
testAttempts?: number
lastCorrect?: boolean
}
// 將 example-data.json 轉換為 MockFlashcard 格式,並添加測試優先級
export const mockFlashcards: MockFlashcard[] = (exampleData.data || []).map((card, index) => ({
id: card.id,
word: card.word,
definition: card.definition,
example: card.example,
translation: card.translation,
exampleTranslation: card.exampleTranslation,
pronunciation: card.pronunciation,
difficultyLevel: card.difficultyLevel as 'A1' | 'A2' | 'B1' | 'B2' | 'C1' | 'C2',
synonyms: card.synonyms || [],
filledQuestionText: card.filledQuestionText,
exampleImage: card.flashcardExampleImages?.[0]?.exampleImage ?
`http://localhost:5008/images/examples/${card.flashcardExampleImages[0].exampleImage.relativePath}` :
undefined,
// 模擬不同的測試狀態
testPriority: index % 4 === 0 ? 20 : index % 5 === 0 ? 10 : 100,
testAttempts: index % 4 === 0 ? 2 : index % 5 === 0 ? 1 : 0,
lastCorrect: index % 4 === 0 ? false : undefined
}))
export const testModes = [
'flip-memory',
'vocab-choice',
'sentence-fill',
'sentence-reorder',
'vocab-listening',
'sentence-listening',
'sentence-speaking'
] as const
export type TestMode = typeof testModes[number]
/**
* 生成測試隊列 - 模擬智能分配邏輯
*/
export function generateTestQueue(cards: MockFlashcard[]): Array<{card: MockFlashcard, mode: TestMode, priority: number}> {
const queue: Array<{card: MockFlashcard, mode: TestMode, priority: number}> = []
cards.forEach(card => {
// 每張卡片隨機分配2-3種測驗模式
const numTests = Math.floor(Math.random() * 2) + 2 // 2-3個測驗
const modesArray = [...testModes] // 創建可變數組
const selectedModes = modesArray
.sort(() => Math.random() - 0.5)
.slice(0, numTests) as TestMode[]
selectedModes.forEach((mode: TestMode) => {
queue.push({
card,
mode,
priority: card.testPriority || 100
})
})
})
// 按優先級排序
return queue.sort((a, b) => b.priority - a.priority)
}
/**
* 調試用資訊
*/
export function getTestStatistics(cards: MockFlashcard[]) {
const stats = {
total: cards.length,
untested: cards.filter(c => c.testAttempts === 0).length,
incorrect: cards.filter(c => c.lastCorrect === false).length,
skipped: cards.filter(c => c.testPriority === 10).length,
priorities: {
high: cards.filter(c => (c.testPriority || 100) >= 100).length,
medium: cards.filter(c => (c.testPriority || 100) === 20).length,
low: cards.filter(c => (c.testPriority || 100) === 10).length
}
}
return stats
}