修正總分語細項不統一的問題
This commit is contained in:
@@ -263,7 +263,7 @@ export async function POST(request: NextRequest) {
|
||||
score: score,
|
||||
max_score: maxScore,
|
||||
weight: criteriaItem.weight,
|
||||
weighted_score: (score / maxScore) * criteriaItem.weight,
|
||||
weighted_score: (score / maxScore) * (criteriaItem.weight / 100),
|
||||
percentage: (score / maxScore) * 100
|
||||
};
|
||||
|
||||
@@ -274,7 +274,7 @@ export async function POST(request: NextRequest) {
|
||||
score: score,
|
||||
max_score: maxScore,
|
||||
weight: criteriaItem.weight,
|
||||
weighted_score: (score / maxScore) * criteriaItem.weight,
|
||||
weighted_score: (score / maxScore) * (criteriaItem.weight / 100),
|
||||
percentage: (score / maxScore) * 100
|
||||
});
|
||||
|
||||
|
@@ -85,7 +85,7 @@ export async function GET(
|
||||
overview: {
|
||||
excellentItems: evaluationWithDetails.excellent_items || 0,
|
||||
improvementItems: evaluationWithDetails.improvement_items || 0,
|
||||
overallPerformance: Number(evaluationWithDetails.overall_score) || 0
|
||||
overallPerformance: Math.round(Number(evaluationWithDetails.overall_score) || 0)
|
||||
},
|
||||
improvementSuggestions: {
|
||||
overallSuggestions: feedbackByType.overall[0]?.content || '無詳細分析',
|
||||
|
@@ -109,7 +109,7 @@ export async function GET(
|
||||
overview: {
|
||||
excellentItems: evaluationWithDetails.excellent_items || 0,
|
||||
improvementItems: evaluationWithDetails.improvement_items || 0,
|
||||
overallPerformance: Number(evaluationWithDetails.overall_score) || 0
|
||||
overallPerformance: Math.round(Number(evaluationWithDetails.overall_score) || 0)
|
||||
},
|
||||
detailedAnalysis: {
|
||||
summary: feedbackByType.overall[0]?.content || '無詳細分析',
|
||||
|
@@ -103,7 +103,7 @@ const calculateMockOverview = (criteria: any[]) => {
|
||||
const improvementItems = criteria.filter(item => item.score < averageScore).length;
|
||||
|
||||
// 整體表現:基於權重的加權平均分數
|
||||
const overallPerformance = Math.round(criteria.reduce((sum, item) => sum + (item.score / item.maxScore) * item.weight, 0));
|
||||
const overallPerformance = Math.round(criteria.reduce((sum, item) => sum + (item.score / item.maxScore) * (item.weight / 100), 0));
|
||||
|
||||
return {
|
||||
excellentItems,
|
||||
@@ -254,7 +254,7 @@ export default function ResultsContent() {
|
||||
const improvementItems = criteria.filter(item => item.score < averageScore).length;
|
||||
|
||||
// 整體表現:基於權重的加權平均分數
|
||||
const overallPerformance = Math.round(criteria.reduce((sum, item) => sum + (item.score / item.maxScore) * item.weight, 0));
|
||||
const overallPerformance = Math.round(criteria.reduce((sum, item) => sum + (item.score / item.maxScore) * (item.weight / 100), 0) * 10) / 10;
|
||||
|
||||
return {
|
||||
excellentItems,
|
||||
@@ -263,9 +263,24 @@ export default function ResultsContent() {
|
||||
};
|
||||
};
|
||||
|
||||
// 重新計算基於權重的總分
|
||||
const calculateWeightedTotalScore = (criteria: any[]): number => {
|
||||
if (!criteria || criteria.length === 0) return 0;
|
||||
|
||||
const totalScore = criteria.reduce((sum, item) => {
|
||||
const weightedScore = (item.score / item.maxScore) * (item.weight / 100);
|
||||
return sum + weightedScore;
|
||||
}, 0);
|
||||
|
||||
// 將小數轉換為100分制的分數,保留一位小數
|
||||
return Math.round(totalScore * 100 * 10) / 10; // 保留一位小數
|
||||
};
|
||||
|
||||
// 確保所有必要的數據結構存在
|
||||
const safeResults = {
|
||||
...results,
|
||||
// 重新計算總分
|
||||
overallScore: calculateWeightedTotalScore(results.criteria || []),
|
||||
overview: results.overview || calculateOverview(results.criteria || []),
|
||||
chartData: results.chartData || {
|
||||
barChart: [],
|
||||
|
Reference in New Issue
Block a user