From d94b1786d64b3662e13de3fab73b762eee7dd5a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B3=E4=BD=A9=E5=BA=AD?= Date: Tue, 23 Sep 2025 21:29:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=B9=B3=E5=9D=87=E5=88=86?= =?UTF-8?q?=E6=95=B8=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/history/route.ts | 2 +- app/api/history/stats/route.ts | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/api/history/route.ts b/app/api/history/route.ts index 557facc..93c5b73 100644 --- a/app/api/history/route.ts +++ b/app/api/history/route.ts @@ -68,7 +68,7 @@ export async function GET(request: NextRequest) { id: project.id.toString(), title: project.title, type: fileType, - score: latestEvaluation?.overall_score || 0, + score: latestEvaluation?.overall_score ? Number(latestEvaluation.overall_score) : 0, grade: latestEvaluation?.grade || '-', date: formatDate(project.created_at), status: project.status === 'completed' ? 'completed' : 'processing', diff --git a/app/api/history/stats/route.ts b/app/api/history/stats/route.ts index 3a57603..131be7b 100644 --- a/app/api/history/stats/route.ts +++ b/app/api/history/stats/route.ts @@ -23,14 +23,27 @@ export async function GET(request: NextRequest) { const evaluation = await EvaluationService.findByProjectId(project.id); console.log(`專案 ${project.id} (${project.title}): 狀態=${project.status}, 評審=${evaluation ? '有' : '無'}, 分數=${evaluation?.overall_score || '無'}`); if (evaluation && evaluation.overall_score) { - totalScore += evaluation.overall_score; - scoredProjects++; + // 確保 overall_score 是數字類型 + const score = Number(evaluation.overall_score); + if (!isNaN(score)) { + totalScore += score; + scoredProjects++; + } else { + console.warn(`專案 ${project.id} 的分數不是有效數字: ${evaluation.overall_score}`); + } } } } const averageScore = scoredProjects > 0 ? Math.round(totalScore / scoredProjects) : 0; console.log(`平均分數計算: 總分=${totalScore}, 有分數的專案數=${scoredProjects}, 平均分數=${averageScore}`); + + // 額外的調試信息 + if (scoredProjects === 0) { + console.log('⚠️ 沒有找到任何有分數的專案'); + } else { + console.log(`✅ 成功計算平均分數: ${averageScore}`); + } const stats = { totalProjects,