修正平均分數 bug
This commit is contained in:
@@ -68,7 +68,7 @@ export async function GET(request: NextRequest) {
|
|||||||
id: project.id.toString(),
|
id: project.id.toString(),
|
||||||
title: project.title,
|
title: project.title,
|
||||||
type: fileType,
|
type: fileType,
|
||||||
score: latestEvaluation?.overall_score || 0,
|
score: latestEvaluation?.overall_score ? Number(latestEvaluation.overall_score) : 0,
|
||||||
grade: latestEvaluation?.grade || '-',
|
grade: latestEvaluation?.grade || '-',
|
||||||
date: formatDate(project.created_at),
|
date: formatDate(project.created_at),
|
||||||
status: project.status === 'completed' ? 'completed' : 'processing',
|
status: project.status === 'completed' ? 'completed' : 'processing',
|
||||||
|
@@ -23,8 +23,14 @@ export async function GET(request: NextRequest) {
|
|||||||
const evaluation = await EvaluationService.findByProjectId(project.id);
|
const evaluation = await EvaluationService.findByProjectId(project.id);
|
||||||
console.log(`專案 ${project.id} (${project.title}): 狀態=${project.status}, 評審=${evaluation ? '有' : '無'}, 分數=${evaluation?.overall_score || '無'}`);
|
console.log(`專案 ${project.id} (${project.title}): 狀態=${project.status}, 評審=${evaluation ? '有' : '無'}, 分數=${evaluation?.overall_score || '無'}`);
|
||||||
if (evaluation && evaluation.overall_score) {
|
if (evaluation && evaluation.overall_score) {
|
||||||
totalScore += evaluation.overall_score;
|
// 確保 overall_score 是數字類型
|
||||||
|
const score = Number(evaluation.overall_score);
|
||||||
|
if (!isNaN(score)) {
|
||||||
|
totalScore += score;
|
||||||
scoredProjects++;
|
scoredProjects++;
|
||||||
|
} else {
|
||||||
|
console.warn(`專案 ${project.id} 的分數不是有效數字: ${evaluation.overall_score}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -32,6 +38,13 @@ export async function GET(request: NextRequest) {
|
|||||||
const averageScore = scoredProjects > 0 ? Math.round(totalScore / scoredProjects) : 0;
|
const averageScore = scoredProjects > 0 ? Math.round(totalScore / scoredProjects) : 0;
|
||||||
console.log(`平均分數計算: 總分=${totalScore}, 有分數的專案數=${scoredProjects}, 平均分數=${averageScore}`);
|
console.log(`平均分數計算: 總分=${totalScore}, 有分數的專案數=${scoredProjects}, 平均分數=${averageScore}`);
|
||||||
|
|
||||||
|
// 額外的調試信息
|
||||||
|
if (scoredProjects === 0) {
|
||||||
|
console.log('⚠️ 沒有找到任何有分數的專案');
|
||||||
|
} else {
|
||||||
|
console.log(`✅ 成功計算平均分數: ${averageScore}`);
|
||||||
|
}
|
||||||
|
|
||||||
const stats = {
|
const stats = {
|
||||||
totalProjects,
|
totalProjects,
|
||||||
completedProjects,
|
completedProjects,
|
||||||
|
Reference in New Issue
Block a user