邏輯題結果與資料庫整合
This commit is contained in:
@@ -65,8 +65,7 @@ pnpm install
|
|||||||
| option_b | VARCHAR(500) | 選項 B |
|
| option_b | VARCHAR(500) | 選項 B |
|
||||||
| option_c | VARCHAR(500) | 選項 C |
|
| option_c | VARCHAR(500) | 選項 C |
|
||||||
| option_d | VARCHAR(500) | 選項 D |
|
| option_d | VARCHAR(500) | 選項 D |
|
||||||
| option_e | VARCHAR(500) | 選項 E |
|
| correct_answer | ENUM('A', 'B', 'C', 'D') | 正確答案 |
|
||||||
| correct_answer | ENUM('A', 'B', 'C', 'D', 'E') | 正確答案 |
|
|
||||||
| explanation | TEXT | 解說 |
|
| explanation | TEXT | 解說 |
|
||||||
| created_at | TIMESTAMP | 建立時間 |
|
| created_at | TIMESTAMP | 建立時間 |
|
||||||
|
|
||||||
@@ -89,8 +88,6 @@ npx tsx lib/database/seed.ts
|
|||||||
- `npm run test-db` - 測試資料庫連接
|
- `npm run test-db` - 測試資料庫連接
|
||||||
- `npm run check-passwords` - 檢查密碼雜湊狀態
|
- `npm run check-passwords` - 檢查密碼雜湊狀態
|
||||||
- `npm run check-logic-questions` - 檢查邏輯思維題目
|
- `npm run check-logic-questions` - 檢查邏輯思維題目
|
||||||
- `npm run test-logic-flow` - 測試邏輯思維測試完整流程
|
|
||||||
- `npm run update-logic-table` - 更新邏輯思維題目表結構(加入 E 選項)
|
|
||||||
- `npm run reset-users` - 重新建立用戶數據(使用雜湊密碼)
|
- `npm run reset-users` - 重新建立用戶數據(使用雜湊密碼)
|
||||||
- `npm run seed-logic-questions` - 上傳邏輯思維題目到資料庫
|
- `npm run seed-logic-questions` - 上傳邏輯思維題目到資料庫
|
||||||
- `npm run test-login` - 測試登入功能(需要先啟動開發伺服器)
|
- `npm run test-login` - 測試登入功能(需要先啟動開發伺服器)
|
||||||
|
@@ -44,15 +44,17 @@ export default function LogicResultsPage() {
|
|||||||
setResults(JSON.parse(savedResults))
|
setResults(JSON.parse(savedResults))
|
||||||
}
|
}
|
||||||
|
|
||||||
// 載入題目數據
|
// 載入題目資料
|
||||||
const response = await fetch('/api/logic-questions')
|
const response = await fetch('/api/logic-questions')
|
||||||
const data = await response.json()
|
const data = await response.json()
|
||||||
|
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
setQuestions(data.questions)
|
setQuestions(data.questions)
|
||||||
|
} else {
|
||||||
|
console.error('Failed to load questions:', data.error)
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('載入數據失敗:', error)
|
console.error('Error loading data:', error)
|
||||||
} finally {
|
} finally {
|
||||||
setIsLoading(false)
|
setIsLoading(false)
|
||||||
}
|
}
|
||||||
@@ -90,37 +92,29 @@ export default function LogicResultsPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const getScoreLevel = (score: number) => {
|
const getScoreLevel = (score: number) => {
|
||||||
if (score === 100) {
|
if (score === 100) return {
|
||||||
return {
|
level: "邏輯巔峰者",
|
||||||
level: "邏輯巔峰者",
|
color: "bg-purple-600",
|
||||||
color: "bg-purple-600",
|
description: "近乎完美的邏輯典範!你像一台「推理引擎」,嚴謹又高效,幾乎不受陷阱干擾。",
|
||||||
description: "近乎完美的邏輯典範!你像一台「推理引擎」,嚴謹又高效,幾乎不受陷阱干擾。",
|
suggestion: "多和他人分享你的思考路徑,能幫助團隊整體邏輯力提升。"
|
||||||
suggestion: "多和他人分享你的思考路徑,能幫助團隊整體邏輯力提升。"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (score >= 80) {
|
if (score >= 80) return {
|
||||||
return {
|
level: "邏輯大師",
|
||||||
level: "邏輯大師",
|
color: "bg-green-500",
|
||||||
color: "bg-green-600",
|
description: "你的思維如同精密儀器,能快速抓住題目關鍵,並做出有效推理。常常是團隊中「冷靜的分析者」。",
|
||||||
description: "你的思維如同精密儀器,能快速抓住題目關鍵,並做出有效推理。常常是團隊中「冷靜的分析者」。",
|
suggestion: "挑戰更高層次的難題,讓你的邏輯力更加精進。"
|
||||||
suggestion: "挑戰更高層次的難題,讓你的邏輯力更加精進。"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (score >= 60) {
|
if (score >= 60) return {
|
||||||
return {
|
level: "邏輯高手",
|
||||||
level: "邏輯高手",
|
color: "bg-blue-500",
|
||||||
color: "bg-blue-500",
|
description: "邏輯清晰穩定,大部分情境都能正確判斷。偶爾會因粗心錯過陷阱。",
|
||||||
description: "邏輯清晰穩定,大部分情境都能正確判斷。偶爾會因粗心錯過陷阱。",
|
suggestion: "在思維縝密之餘,更加留心細節,就能把錯誤率降到最低。"
|
||||||
suggestion: "在思維縝密之餘,更加留心細節,就能把錯誤率降到最低。"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (score >= 30) {
|
if (score >= 30) return {
|
||||||
return {
|
level: "邏輯學徒",
|
||||||
level: "邏輯學徒",
|
color: "bg-yellow-500",
|
||||||
color: "bg-yellow-500",
|
description: "已經抓到一些邏輯規律,能解決中等難度的問題。遇到複雜情境時,仍可能卡關。",
|
||||||
description: "已經抓到一些邏輯規律,能解決中等難度的問題。遇到複雜情境時,仍可能卡關。",
|
suggestion: "嘗試將問題拆解成小步驟,就像組裝樂高,每一塊拼好,答案就自然浮現。"
|
||||||
suggestion: "嘗試將問題拆解成小步驟,就像組裝樂高,每一塊拼好,答案就自然浮現。"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
level: "邏輯探險新手",
|
level: "邏輯探險新手",
|
||||||
@@ -167,11 +161,7 @@ export default function LogicResultsPage() {
|
|||||||
{scoreLevel.level}
|
{scoreLevel.level}
|
||||||
</Badge>
|
</Badge>
|
||||||
</div>
|
</div>
|
||||||
<p className="text-lg text-muted-foreground mb-4">{scoreLevel.description}</p>
|
<p className="text-lg text-muted-foreground">{scoreLevel.description}</p>
|
||||||
<div className="bg-muted/50 rounded-lg p-4 border-l-4 border-primary">
|
|
||||||
<p className="text-sm font-medium text-foreground mb-1">💡 建議:</p>
|
|
||||||
<p className="text-sm text-muted-foreground">{scoreLevel.suggestion}</p>
|
|
||||||
</div>
|
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-6 mb-6">
|
<div className="grid grid-cols-1 md:grid-cols-3 gap-6 mb-6">
|
||||||
@@ -205,7 +195,7 @@ export default function LogicResultsPage() {
|
|||||||
const userAnswer = results.answers[index]
|
const userAnswer = results.answers[index]
|
||||||
const isCorrect = userAnswer === question.correct_answer
|
const isCorrect = userAnswer === question.correct_answer
|
||||||
|
|
||||||
// 獲取選項文字
|
// 根據選項字母獲取對應的選項文字
|
||||||
const getOptionText = (option: string) => {
|
const getOptionText = (option: string) => {
|
||||||
switch (option) {
|
switch (option) {
|
||||||
case 'A': return question.option_a
|
case 'A': return question.option_a
|
||||||
@@ -213,12 +203,12 @@ export default function LogicResultsPage() {
|
|||||||
case 'C': return question.option_c
|
case 'C': return question.option_c
|
||||||
case 'D': return question.option_d
|
case 'D': return question.option_d
|
||||||
case 'E': return question.option_e
|
case 'E': return question.option_e
|
||||||
default: return '未知選項'
|
default: return "未作答"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const correctOptionText = getOptionText(question.correct_answer)
|
const correctOptionText = getOptionText(question.correct_answer)
|
||||||
const userOptionText = userAnswer ? getOptionText(userAnswer) : '未作答'
|
const userOptionText = userAnswer ? getOptionText(userAnswer) : "未作答"
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div key={question.id} className="border rounded-lg p-4">
|
<div key={question.id} className="border rounded-lg p-4">
|
||||||
|
@@ -11,7 +11,6 @@
|
|||||||
"test-login": "node scripts/test-login.js",
|
"test-login": "node scripts/test-login.js",
|
||||||
"check-passwords": "node scripts/check-passwords.js",
|
"check-passwords": "node scripts/check-passwords.js",
|
||||||
"check-logic-questions": "node scripts/check-logic-questions.js",
|
"check-logic-questions": "node scripts/check-logic-questions.js",
|
||||||
"test-logic-flow": "node scripts/test-logic-flow.js",
|
|
||||||
"update-logic-table": "node scripts/update-logic-table.js",
|
"update-logic-table": "node scripts/update-logic-table.js",
|
||||||
"seed-db": "npx tsx lib/database/seed.ts",
|
"seed-db": "npx tsx lib/database/seed.ts",
|
||||||
"seed-logic-questions": "npx tsx lib/database/seed-logic-questions.ts",
|
"seed-logic-questions": "npx tsx lib/database/seed-logic-questions.ts",
|
||||||
|
@@ -1,80 +0,0 @@
|
|||||||
const fetch = require('node-fetch').default || require('node-fetch')
|
|
||||||
|
|
||||||
async function testLogicFlow() {
|
|
||||||
console.log('🔄 正在測試邏輯思維測試完整流程...')
|
|
||||||
|
|
||||||
try {
|
|
||||||
// 1. 測試獲取題目 API
|
|
||||||
console.log('\n1. 測試獲取題目 API...')
|
|
||||||
const questionsResponse = await fetch('http://localhost:3000/api/logic-questions')
|
|
||||||
const questionsData = await questionsResponse.json()
|
|
||||||
|
|
||||||
if (questionsData.success) {
|
|
||||||
console.log(`✅ 成功獲取 ${questionsData.questions.length} 道題目`)
|
|
||||||
|
|
||||||
// 檢查第一道題目是否包含 E 選項
|
|
||||||
const firstQuestion = questionsData.questions[0]
|
|
||||||
if (firstQuestion.option_e) {
|
|
||||||
console.log('✅ 題目包含 E 選項')
|
|
||||||
console.log(` 範例:${firstQuestion.question.substring(0, 30)}...`)
|
|
||||||
console.log(` E 選項:${firstQuestion.option_e}`)
|
|
||||||
} else {
|
|
||||||
console.log('❌ 題目缺少 E 選項')
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
console.log('❌ 獲取題目失敗:', questionsData.error)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. 模擬測試結果
|
|
||||||
console.log('\n2. 模擬測試結果...')
|
|
||||||
const mockResults = {
|
|
||||||
type: "logic",
|
|
||||||
score: 60,
|
|
||||||
correctAnswers: 6,
|
|
||||||
totalQuestions: 10,
|
|
||||||
answers: {
|
|
||||||
0: "C",
|
|
||||||
1: "C",
|
|
||||||
2: "B",
|
|
||||||
3: "B",
|
|
||||||
4: "E",
|
|
||||||
5: "B",
|
|
||||||
6: "E",
|
|
||||||
7: "A",
|
|
||||||
8: "C",
|
|
||||||
9: "D"
|
|
||||||
},
|
|
||||||
completedAt: new Date().toISOString()
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('✅ 模擬測試結果已準備')
|
|
||||||
console.log(` 答對題數:${mockResults.correctAnswers}/${mockResults.totalQuestions}`)
|
|
||||||
console.log(` 正確率:${mockResults.score}%`)
|
|
||||||
|
|
||||||
// 3. 檢查結果頁面需要的數據結構
|
|
||||||
console.log('\n3. 檢查數據結構...')
|
|
||||||
const hasAllRequiredFields = questionsData.questions.every(q =>
|
|
||||||
q.question &&
|
|
||||||
q.option_a &&
|
|
||||||
q.option_b &&
|
|
||||||
q.option_c &&
|
|
||||||
q.option_d &&
|
|
||||||
q.option_e &&
|
|
||||||
q.correct_answer &&
|
|
||||||
q.explanation
|
|
||||||
)
|
|
||||||
|
|
||||||
if (hasAllRequiredFields) {
|
|
||||||
console.log('✅ 所有題目都包含完整字段')
|
|
||||||
} else {
|
|
||||||
console.log('❌ 部分題目缺少必要字段')
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('\n✅ 邏輯思維測試流程驗證完成')
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
console.error('❌ 測試失敗:', error.message)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
testLogicFlow()
|
|
Reference in New Issue
Block a user