新增評分項目設定、資料庫整合

This commit is contained in:
2025-09-22 00:33:12 +08:00
parent 8de09129be
commit 9d4c586ad3
20 changed files with 2321 additions and 79 deletions

View File

@@ -0,0 +1,41 @@
// 測試權重修復
console.log('🔄 測試權重修復...');
// 模擬可能出現的權重數據類型
const testCases = [
{ weight: 25.00 }, // 正常數字
{ weight: "25.00" }, // 字符串數字
{ weight: "25" }, // 字符串整數
{ weight: null }, // null 值
{ weight: undefined }, // undefined 值
{ weight: "" }, // 空字符串
{ weight: "abc" }, // 非數字字符串
];
console.log('\n測試各種權重數據類型:');
testCases.forEach((item, index) => {
const originalWeight = item.weight;
const safeWeight = Number(item.weight) || 0;
const formattedWeight = safeWeight.toFixed(1);
console.log(`${index + 1}. 原始: ${originalWeight} (${typeof originalWeight})`);
console.log(` 安全轉換: ${safeWeight} (${typeof safeWeight})`);
console.log(` 格式化: ${formattedWeight}%`);
console.log('');
});
// 測試總權重計算
console.log('測試總權重計算:');
const criteria = [
{ weight: 25.00 },
{ weight: "20.00" },
{ weight: 20 },
{ weight: "15.00" },
{ weight: null },
];
const totalWeight = criteria.reduce((sum, item) => sum + (Number(item.weight) || 0), 0);
console.log(`總權重: ${totalWeight} (${typeof totalWeight})`);
console.log(`格式化總權重: ${Number(totalWeight).toFixed(1)}%`);
console.log('\n🎉 權重修復測試完成!');