187 lines
5.3 KiB
TypeScript
187 lines
5.3 KiB
TypeScript
import { EvaluationUploadService, defaultAIEvaluationResult } from '../lib/services/evaluation-upload';
|
||
|
||
/**
|
||
* 使用範例:上傳 AI 評分結果到資料庫
|
||
*/
|
||
|
||
// 範例 1: 使用預設的 AI 評分結果
|
||
async function uploadDefaultEvaluation() {
|
||
try {
|
||
console.log('🚀 開始上傳預設的 AI 評分結果...');
|
||
|
||
const projectId = 1; // 假設專案 ID 為 1
|
||
const analysisDuration = 120; // 分析耗時 2 分鐘
|
||
const aiModelVersion = 'gemini-1.5-pro';
|
||
|
||
const evaluationId = await EvaluationUploadService.uploadEvaluationResult(
|
||
projectId,
|
||
defaultAIEvaluationResult,
|
||
analysisDuration,
|
||
aiModelVersion
|
||
);
|
||
|
||
console.log(`✅ 上傳成功!Evaluation ID: ${evaluationId}`);
|
||
console.log(`📊 評分結果: ${defaultAIEvaluationResult.overallScore}/${defaultAIEvaluationResult.totalPossible} (${defaultAIEvaluationResult.grade})`);
|
||
|
||
} catch (error) {
|
||
console.error('❌ 上傳失敗:', error);
|
||
}
|
||
}
|
||
|
||
// 範例 2: 使用自定義的 AI 評分結果
|
||
async function uploadCustomEvaluation() {
|
||
try {
|
||
console.log('🚀 開始上傳自定義的 AI 評分結果...');
|
||
|
||
const customAIResult = {
|
||
projectTitle: "自定義專案",
|
||
overallScore: 85.0,
|
||
totalPossible: 100,
|
||
grade: "A",
|
||
performanceStatus: "表現優秀",
|
||
recommendedStars: 5,
|
||
analysisDate: "2024-10-27",
|
||
criteria: [
|
||
{
|
||
name: "應用實務性",
|
||
score: 9,
|
||
maxScore: 10,
|
||
weight: 30,
|
||
weightedScore: 27,
|
||
feedback: "專案具有很高的實務價值",
|
||
strengths: ["解決了實際問題", "具備良好的可行性"],
|
||
improvements: ["可以增加更多案例"]
|
||
},
|
||
{
|
||
name: "創新性",
|
||
score: 8,
|
||
maxScore: 10,
|
||
weight: 15,
|
||
weightedScore: 12,
|
||
feedback: "展現了良好的創新思維",
|
||
strengths: ["技術創新", "應用創新"],
|
||
improvements: ["可以探索更多創新點"]
|
||
}
|
||
],
|
||
overview: {
|
||
excellentItems: 2,
|
||
improvementItems: 0,
|
||
overallPerformance: 85
|
||
},
|
||
detailedAnalysis: {
|
||
summary: "整體表現優秀,各項指標都達到高水準",
|
||
keyFindings: ["創新性強", "實務價值高"]
|
||
},
|
||
improvementSuggestions: {
|
||
overallSuggestions: "繼續保持現有優勢,可以考慮擴大應用範圍",
|
||
maintainStrengths: [
|
||
{
|
||
title: "創新思維",
|
||
description: "保持創新的思維方式"
|
||
}
|
||
],
|
||
keyImprovements: [
|
||
{
|
||
title: "擴大應用",
|
||
description: "考慮將專案應用到更多領域",
|
||
suggestions: ["研究其他應用場景", "建立合作夥伴關係"]
|
||
}
|
||
],
|
||
actionPlan: [
|
||
{
|
||
phase: "短期目標",
|
||
description: "完善現有功能"
|
||
}
|
||
]
|
||
}
|
||
};
|
||
|
||
const projectId = 2;
|
||
const evaluationId = await EvaluationUploadService.uploadEvaluationResult(
|
||
projectId,
|
||
customAIResult
|
||
);
|
||
|
||
console.log(`✅ 自定義評分結果上傳成功!Evaluation ID: ${evaluationId}`);
|
||
|
||
} catch (error) {
|
||
console.error('❌ 上傳失敗:', error);
|
||
}
|
||
}
|
||
|
||
// 範例 3: 更新 criteria_item_id 對應關係
|
||
async function updateCriteriaMapping() {
|
||
try {
|
||
console.log('🔄 更新 criteria_item_id 對應關係...');
|
||
|
||
// 假設您有新的 criteria_items 表,ID 有所不同
|
||
const newMapping = {
|
||
"應用實務性": 101,
|
||
"創新性": 102,
|
||
"成效與效益": 103,
|
||
"擴散與可複用性": 104,
|
||
"簡報與表達": 105
|
||
};
|
||
|
||
EvaluationUploadService.updateCriteriaMapping(newMapping);
|
||
|
||
// 驗證更新
|
||
const currentMapping = EvaluationUploadService.getCriteriaMapping();
|
||
console.log('✅ 對應關係已更新:', currentMapping);
|
||
|
||
} catch (error) {
|
||
console.error('❌ 更新失敗:', error);
|
||
}
|
||
}
|
||
|
||
// 範例 4: 在 API 路由中使用
|
||
export async function handleEvaluationUpload(projectId: number, aiResult: any) {
|
||
try {
|
||
// 驗證必要欄位
|
||
if (!aiResult.projectTitle || !aiResult.overallScore || !aiResult.criteria) {
|
||
throw new Error('AI 評分結果缺少必要欄位');
|
||
}
|
||
|
||
// 上傳到資料庫
|
||
const evaluationId = await EvaluationUploadService.uploadEvaluationResult(
|
||
projectId,
|
||
aiResult
|
||
);
|
||
|
||
return {
|
||
success: true,
|
||
evaluationId,
|
||
message: '評分結果上傳成功'
|
||
};
|
||
|
||
} catch (error) {
|
||
console.error('處理評分結果上傳時發生錯誤:', error);
|
||
return {
|
||
success: false,
|
||
error: error instanceof Error ? error.message : '未知錯誤'
|
||
};
|
||
}
|
||
}
|
||
|
||
// 執行範例(如果直接運行此文件)
|
||
if (require.main === module) {
|
||
async function runExamples() {
|
||
console.log('📚 開始執行上傳範例...\n');
|
||
|
||
// 範例 1: 上傳預設評分結果
|
||
await uploadDefaultEvaluation();
|
||
console.log('\n' + '='.repeat(50) + '\n');
|
||
|
||
// 範例 2: 上傳自定義評分結果
|
||
await uploadCustomEvaluation();
|
||
console.log('\n' + '='.repeat(50) + '\n');
|
||
|
||
// 範例 3: 更新對應關係
|
||
await updateCriteriaMapping();
|
||
|
||
console.log('\n🎉 所有範例執行完成!');
|
||
}
|
||
|
||
runExamples().catch(console.error);
|
||
}
|