修正總分語細項不統一的問題
This commit is contained in:
@@ -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