-
-
-
{question.statement}
+ {creativeQuestions.map((question, index) => {
+ const dimensionInfo = getDimensionInfo(question.category)
+ return (
+
+
+
+
第 {index + 1} 題
+
+ {dimensionInfo.name}
+
+
+
+ {question.score} 分
+
+
+
+
+
+
{question.statement}
+
-
-
-
-
{question.userAnswer}
-
-
-
-
{question.score} 分
+
+
+
+
{question.userAnswer}
+
+
+
+
{question.score} 分
+
-
- ))}
+ )
+ })}
)}
diff --git a/app/api/admin/test-results/detail/route.ts b/app/api/admin/test-results/detail/route.ts
index 454bff0..ce4ed7c 100644
--- a/app/api/admin/test-results/detail/route.ts
+++ b/app/api/admin/test-results/detail/route.ts
@@ -127,7 +127,91 @@ export async function GET(request: NextRequest) {
// 獲取詳細答案
try {
- if (testType === "logic") {
+ if (testType === "creative") {
+ console.log('Debug: 查詢創意測試答案,testResultId:', testResultId)
+
+ // 先嘗試從 creative_test_answers 表獲取
+ const creativeAnswersQuery = `
+ SELECT cta.*, cq.statement, cq.is_reverse, cq.category
+ FROM creative_test_answers cta
+ LEFT JOIN creative_questions cq ON cta.question_id = cq.id
+ WHERE cta.test_result_id = ?
+ ORDER BY cta.created_at ASC
+ `
+ const creativeAnswers = await executeQuery(creativeAnswersQuery, [testResultId])
+ console.log('Debug: 創意測試答案數量:', creativeAnswers.length)
+
+ if (creativeAnswers.length > 0) {
+ // 處理創意題答案
+ for (const answer of creativeAnswers) {
+ if (answer.statement) {
+ questions.push({
+ id: answer.question_id,
+ statement: answer.statement,
+ is_reverse: answer.is_reverse,
+ category: answer.category,
+ type: 'creative',
+ userAnswer: answer.user_answer,
+ score: answer.score,
+ isReverse: answer.is_reverse
+ })
+ }
+ }
+
+ // 計算維度分數
+ const dimensionScores = {
+ innovation: { total: 0, count: 0 },
+ imagination: { total: 0, count: 0 },
+ flexibility: { total: 0, count: 0 },
+ originality: { total: 0, count: 0 }
+ }
+
+ creativeAnswers.forEach((answer: any) => {
+ if (answer.category && dimensionScores[answer.category as keyof typeof dimensionScores]) {
+ dimensionScores[answer.category as keyof typeof dimensionScores].total += answer.score
+ dimensionScores[answer.category as keyof typeof dimensionScores].count += 1
+ }
+ })
+
+ // 計算百分比分數
+ const resultDimensionScores = {
+ innovation: { percentage: 0, rawScore: 0, maxScore: 0 },
+ imagination: { percentage: 0, rawScore: 0, maxScore: 0 },
+ flexibility: { percentage: 0, rawScore: 0, maxScore: 0 },
+ originality: { percentage: 0, rawScore: 0, maxScore: 0 }
+ }
+
+ Object.keys(dimensionScores).forEach(category => {
+ const { total, count } = dimensionScores[category as keyof typeof dimensionScores]
+ const maxScore = count * 5
+ const percentage = count > 0 ? Math.round((total / maxScore) * 100) : 0
+
+ resultDimensionScores[category as keyof typeof resultDimensionScores] = {
+ percentage: percentage,
+ rawScore: total,
+ maxScore: maxScore
+ }
+ })
+
+ // 將維度分數添加到結果中
+ result.dimensionScores = resultDimensionScores
+ } else {
+ // 如果沒有找到答案,只顯示題目不顯示假答案
+ console.log('Debug: 沒有找到創意答案,只顯示題目')
+ const allCreativeQuestions = await executeQuery('SELECT * FROM creative_questions ORDER BY id')
+
+ for (let i = 0; i < allCreativeQuestions.length; i++) {
+ const question = allCreativeQuestions[i]
+ questions.push({
+ ...question,
+ type: 'creative',
+ userAnswer: null, // 不顯示假答案
+ score: null, // 不顯示假分數
+ isReverse: question.is_reverse
+ })
+ }
+ }
+ } else if (testType === "logic") {
console.log('Debug: 查詢邏輯測試答案,testResultId:', testResultId)
@@ -180,51 +264,6 @@ export async function GET(request: NextRequest) {
})
}
}
- } else if (testType === "creative") {
- console.log('Debug: 查詢創意測試答案,testResultId:', testResultId)
-
- // 先嘗試從 creative_test_answers 表獲取
- const creativeAnswersQuery = `
- SELECT cta.*, cq.statement, cq.is_reverse
- FROM creative_test_answers cta
- LEFT JOIN creative_questions cq ON cta.question_id = cq.id
- WHERE cta.test_result_id = ?
- ORDER BY cta.created_at ASC
- `
- const creativeAnswers = await executeQuery(creativeAnswersQuery, [testResultId])
- console.log('Debug: 創意測試答案數量:', creativeAnswers.length)
-
- if (creativeAnswers.length > 0) {
- // 處理創意題答案
- for (const answer of creativeAnswers) {
- if (answer.statement) {
- questions.push({
- id: answer.question_id,
- statement: answer.statement,
- is_reverse: answer.is_reverse,
- type: 'creative',
- userAnswer: answer.user_answer,
- score: answer.score,
- isReverse: answer.is_reverse
- })
- }
- }
- } else {
- // 如果沒有找到答案,只顯示題目不顯示假答案
- console.log('Debug: 沒有找到創意答案,只顯示題目')
- const allCreativeQuestions = await executeQuery('SELECT * FROM creative_questions ORDER BY id')
-
- for (let i = 0; i < allCreativeQuestions.length; i++) {
- const question = allCreativeQuestions[i]
- questions.push({
- ...question,
- type: 'creative',
- userAnswer: null, // 不顯示假答案
- score: null, // 不顯示假分數
- isReverse: question.is_reverse
- })
- }
- }
}
} catch (error) {
console.error('獲取詳細答案失敗:', error)
diff --git a/components/creative-analysis.tsx b/components/creative-analysis.tsx
new file mode 100644
index 0000000..f334876
--- /dev/null
+++ b/components/creative-analysis.tsx
@@ -0,0 +1,308 @@
+"use client"
+
+import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
+import { Badge } from "@/components/ui/badge"
+import { Progress } from "@/components/ui/progress"
+import { TrendingUp } from "lucide-react"
+
+interface DimensionScore {
+ percentage: number
+ rawScore: number
+ maxScore: number
+}
+
+interface CreativeAnalysisProps {
+ score: number
+ dimensionScores: {
+ innovation: DimensionScore
+ imagination: DimensionScore
+ flexibility: DimensionScore
+ originality: DimensionScore
+ }
+ creativityLevel: {
+ level: string
+ description: string
+ suggestion: string
+ }
+ totalScore?: number
+ maxScore?: number
+}
+
+export function CreativeAnalysis({ score, dimensionScores, creativityLevel, totalScore, maxScore }: CreativeAnalysisProps) {
+ // 計算各維度分數
+ const categoryResults = [
+ {
+ category: 'innovation',
+ name: '創新能力',
+ score: dimensionScores.innovation.percentage,
+ rawScore: dimensionScores.innovation.rawScore,
+ maxRawScore: dimensionScores.innovation.maxScore
+ },
+ {
+ category: 'imagination',
+ name: '想像力',
+ score: dimensionScores.imagination.percentage,
+ rawScore: dimensionScores.imagination.rawScore,
+ maxRawScore: dimensionScores.imagination.maxScore
+ },
+ {
+ category: 'flexibility',
+ name: '靈活性',
+ score: dimensionScores.flexibility.percentage,
+ rawScore: dimensionScores.flexibility.rawScore,
+ maxRawScore: dimensionScores.flexibility.maxScore
+ },
+ {
+ category: 'originality',
+ name: '原創性',
+ score: dimensionScores.originality.percentage,
+ rawScore: dimensionScores.originality.rawScore,
+ maxRawScore: dimensionScores.originality.maxScore
+ }
+ ]
+
+ return (
+
+ {/* 創意能力評估 */}
+
+
+
+
+ 創意能力評估
+
+
+
+
+
創意能力評估
+
+ 基於您的測試結果,您在創意思維方面表現為「{creativityLevel.level}」水平。
+ {score >= 75 &&
+ "您具備出色的創新思維能力,善於從不同角度思考問題,能夠產生獨特的想法和解決方案。"}
+ {score >= 50 &&
+ score < 75 &&
+ "您具有一定的創造性思維潛力,建議多參與創新活動,培養發散性思維。"}
+ {score < 50 && "建議您多接觸創新思維訓練,培養好奇心和探索精神,提升創造性解決問題的能力。"}
+
+
+
+
+
+ {/* 能力維度分析 */}
+
+
+
+
+ 能力維度分析
+
+
+
+
+ {categoryResults.map((category) => (
+
+
+
{category.name}
+ {category.score}分
+
+
+
+ {category.rawScore} / {category.maxRawScore} 分
+
+
+ ))}
+
+
+
+
+ {/* 創意能力分析圖表 */}
+
+
+
+
+ 創意能力分析圖表
+
+
+
+
+ {/* 能力維度雷達圖 */}
+
+
能力維度雷達圖
+
+
+ {/* Radar Chart Background */}
+
+
+
+
+ {/* Legend */}
+
+
+ {categoryResults.map((category) => (
+
+ ))}
+
+
+
+ {/* Dimension Details */}
+
+ {categoryResults.map((category) => {
+ const getDescription = (categoryName: string) => {
+ switch (categoryName) {
+ case '創新能力':
+ return '善於提出新想法,勇於嘗試不同的解決方案'
+ case '想像力':
+ return '能夠從不同角度思考,具有豐富的創意思維'
+ case '靈活性':
+ return '適應變化能力強,能夠靈活調整思維方式'
+ case '原創性':
+ return '具有獨特的創見,能夠產生原創性想法'
+ default:
+ return ''
+ }
+ }
+
+ const getLevel = (score: number) => {
+ if (score >= 80) return { text: '優秀', color: 'text-green-600' }
+ if (score >= 60) return { text: '良好', color: 'text-blue-600' }
+ if (score >= 40) return { text: '一般', color: 'text-yellow-600' }
+ return { text: '待提升', color: 'text-red-600' }
+ }
+
+ const level = getLevel(category.score)
+
+ return (
+
+
+
{category.name}
+
+ {category.score}%
+ {level.text}
+
+
+
+ {getDescription(category.name)}
+
+
+ )
+ })}
+
+
+
+
+
+
+ )
+}