新增 AI 解析、評分結果
This commit is contained in:
@@ -1,69 +0,0 @@
|
||||
const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));
|
||||
|
||||
const API_BASE = 'http://localhost:3000/api';
|
||||
|
||||
async function testCriteriaAPI() {
|
||||
try {
|
||||
console.log('🔄 測試評分標準 API...');
|
||||
|
||||
// 1. 測試獲取預設模板
|
||||
console.log('\n1. 測試獲取預設模板...');
|
||||
const defaultResponse = await fetch(`${API_BASE}/criteria-templates/default`);
|
||||
const defaultData = await defaultResponse.json();
|
||||
|
||||
if (defaultData.success) {
|
||||
console.log('✅ 預設模板獲取成功');
|
||||
console.log(` 模板名稱: ${defaultData.data.name}`);
|
||||
console.log(` 評分項目數量: ${defaultData.data.items.length}`);
|
||||
defaultData.data.items.forEach((item, index) => {
|
||||
console.log(` ${index + 1}. ${item.name} (權重: ${item.weight}%)`);
|
||||
});
|
||||
} else {
|
||||
console.log('❌ 預設模板獲取失敗:', defaultData.error);
|
||||
}
|
||||
|
||||
// 2. 測試創建新模板
|
||||
console.log('\n2. 測試創建新模板...');
|
||||
const newTemplate = {
|
||||
name: '測試模板',
|
||||
description: '這是一個測試模板',
|
||||
items: [
|
||||
{ name: '測試項目1', description: '測試描述1', weight: 50, maxScore: 10 },
|
||||
{ name: '測試項目2', description: '測試描述2', weight: 50, maxScore: 10 }
|
||||
]
|
||||
};
|
||||
|
||||
const createResponse = await fetch(`${API_BASE}/criteria-templates`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(newTemplate)
|
||||
});
|
||||
const createData = await createResponse.json();
|
||||
|
||||
if (createData.success) {
|
||||
console.log('✅ 新模板創建成功');
|
||||
console.log(` 模板 ID: ${createData.data.id}`);
|
||||
} else {
|
||||
console.log('❌ 新模板創建失敗:', createData.error);
|
||||
}
|
||||
|
||||
// 3. 測試獲取所有模板
|
||||
console.log('\n3. 測試獲取所有模板...');
|
||||
const allResponse = await fetch(`${API_BASE}/criteria-templates`);
|
||||
const allData = await allResponse.json();
|
||||
|
||||
if (allData.success) {
|
||||
console.log('✅ 所有模板獲取成功');
|
||||
console.log(` 模板總數: ${allData.data.length}`);
|
||||
} else {
|
||||
console.log('❌ 所有模板獲取失敗:', allData.error);
|
||||
}
|
||||
|
||||
console.log('\n🎉 API 測試完成!');
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ 測試失敗:', error.message);
|
||||
}
|
||||
}
|
||||
|
||||
testCriteriaAPI();
|
@@ -1,54 +0,0 @@
|
||||
const mysql = require('mysql2/promise');
|
||||
|
||||
// 資料庫配置
|
||||
const dbConfig = {
|
||||
host: process.env.DB_HOST || 'mysql.theaken.com',
|
||||
port: parseInt(process.env.DB_PORT || '33306'),
|
||||
user: process.env.DB_USER || 'root',
|
||||
password: process.env.DB_PASSWORD || 'zh6161168',
|
||||
database: process.env.DB_NAME || 'db_AI_scoring',
|
||||
charset: 'utf8mb4',
|
||||
timezone: '+08:00',
|
||||
};
|
||||
|
||||
async function testDatabase() {
|
||||
let connection;
|
||||
|
||||
try {
|
||||
console.log('🔄 正在測試資料庫連接...');
|
||||
|
||||
connection = await mysql.createConnection(dbConfig);
|
||||
|
||||
// 測試基本連接
|
||||
await connection.ping();
|
||||
console.log('✅ 資料庫連接成功');
|
||||
|
||||
// 測試查詢
|
||||
const [rows] = await connection.query('SELECT COUNT(*) as count FROM criteria_templates');
|
||||
console.log(`✅ 找到 ${rows[0].count} 個評分標準模板`);
|
||||
|
||||
// 顯示所有資料表
|
||||
const [tables] = await connection.query('SHOW TABLES');
|
||||
console.log('📊 資料庫中的資料表:');
|
||||
tables.forEach(table => {
|
||||
console.log(` - ${Object.values(table)[0]}`);
|
||||
});
|
||||
|
||||
// 測試預設數據
|
||||
const [criteriaItems] = await connection.query('SELECT * FROM criteria_items ORDER BY sort_order');
|
||||
console.log('📋 預設評分項目:');
|
||||
criteriaItems.forEach(item => {
|
||||
console.log(` - ${item.name} (權重: ${item.weight}%, 滿分: ${item.max_score})`);
|
||||
});
|
||||
|
||||
await connection.end();
|
||||
console.log('🎉 資料庫測試完成!');
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ 資料庫測試失敗:', error.message);
|
||||
console.error('詳細錯誤:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
testDatabase();
|
@@ -1,79 +0,0 @@
|
||||
const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));
|
||||
|
||||
const API_BASE = 'http://localhost:3000/api';
|
||||
|
||||
async function testSingleTemplateMode() {
|
||||
try {
|
||||
console.log('🔄 測試單一模板模式...');
|
||||
|
||||
// 1. 測試獲取現有模板
|
||||
console.log('\n1. 測試獲取現有模板...');
|
||||
const getResponse = await fetch(`${API_BASE}/criteria-templates`);
|
||||
const getData = await getResponse.json();
|
||||
|
||||
if (getData.success) {
|
||||
console.log(`✅ 找到 ${getData.data.length} 個模板`);
|
||||
if (getData.data.length > 0) {
|
||||
const template = getData.data[0];
|
||||
console.log(` 模板名稱: ${template.name}`);
|
||||
console.log(` 評分項目數量: ${template.items.length}`);
|
||||
}
|
||||
} else {
|
||||
console.log('❌ 獲取模板失敗:', getData.error);
|
||||
}
|
||||
|
||||
// 2. 測試覆蓋模板
|
||||
console.log('\n2. 測試覆蓋模板...');
|
||||
const templateData = {
|
||||
name: '我的評分標準',
|
||||
description: '這是我的自定義評分標準',
|
||||
items: [
|
||||
{ name: '內容品質', description: '內容的準確性和完整性', weight: 30, maxScore: 10 },
|
||||
{ name: '視覺設計', description: '版面設計和視覺效果', weight: 25, maxScore: 10 },
|
||||
{ name: '邏輯結構', description: '內容組織的邏輯性', weight: 25, maxScore: 10 },
|
||||
{ name: '創新性', description: '創意思維的展現', weight: 20, maxScore: 10 }
|
||||
]
|
||||
};
|
||||
|
||||
const saveResponse = await fetch(`${API_BASE}/criteria-templates`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(templateData)
|
||||
});
|
||||
const saveData = await saveResponse.json();
|
||||
|
||||
if (saveData.success) {
|
||||
console.log('✅ 模板覆蓋成功');
|
||||
console.log(` 模板 ID: ${saveData.data.id}`);
|
||||
} else {
|
||||
console.log('❌ 模板覆蓋失敗:', saveData.error);
|
||||
}
|
||||
|
||||
// 3. 驗證覆蓋結果
|
||||
console.log('\n3. 驗證覆蓋結果...');
|
||||
const verifyResponse = await fetch(`${API_BASE}/criteria-templates`);
|
||||
const verifyData = await verifyResponse.json();
|
||||
|
||||
if (verifyData.success) {
|
||||
console.log(`✅ 驗證成功,現在有 ${verifyData.data.length} 個模板`);
|
||||
if (verifyData.data.length > 0) {
|
||||
const template = verifyData.data[0];
|
||||
console.log(` 模板名稱: ${template.name}`);
|
||||
console.log(` 模板描述: ${template.description}`);
|
||||
console.log(` 評分項目數量: ${template.items.length}`);
|
||||
template.items.forEach((item, index) => {
|
||||
console.log(` ${index + 1}. ${item.name} (權重: ${item.weight}%)`);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
console.log('❌ 驗證失敗:', verifyData.error);
|
||||
}
|
||||
|
||||
console.log('\n🎉 單一模板模式測試完成!');
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ 測試失敗:', error.message);
|
||||
}
|
||||
}
|
||||
|
||||
testSingleTemplateMode();
|
@@ -1,23 +0,0 @@
|
||||
// 測試權重顯示格式
|
||||
const testWeights = [25.00, 20.00, 20.00, 15.00, 20.00];
|
||||
|
||||
console.log('🔄 測試權重顯示格式...');
|
||||
|
||||
// 計算總權重
|
||||
const totalWeight = testWeights.reduce((sum, weight) => sum + weight, 0);
|
||||
|
||||
console.log('個別權重:');
|
||||
testWeights.forEach((weight, index) => {
|
||||
console.log(` ${index + 1}. ${weight.toFixed(1)}%`);
|
||||
});
|
||||
|
||||
console.log(`\n總權重: ${totalWeight.toFixed(1)}%`);
|
||||
console.log(`是否等於 100%: ${totalWeight === 100 ? '✅' : '❌'}`);
|
||||
|
||||
// 測試權重顯示的各種格式
|
||||
console.log('\n權重顯示格式測試:');
|
||||
console.log(`原始格式: ${totalWeight}%`);
|
||||
console.log(`toFixed(1): ${totalWeight.toFixed(1)}%`);
|
||||
console.log(`toFixed(0): ${totalWeight.toFixed(0)}%`);
|
||||
|
||||
console.log('\n🎉 權重顯示格式測試完成!');
|
@@ -1,41 +0,0 @@
|
||||
// 測試權重修復
|
||||
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🎉 權重修復測試完成!');
|
Reference in New Issue
Block a user