工程级参考答案(带完整注释):
// 生产级毕业作品评分系统
interface ProjectGradingRubric {
dimensions: {
name: string;
weight: number;
description: string;
criteria: Record;
}[];
}
interface GradingResult {
studentId: string;
projectName: string;
scores: Record;
finalScore: number;
feedback: string[];
autoChecks: Record;
humanReview?: {
reviewed: boolean;
reviewer: string;
adjustments: Record;
};
}
async function gradeProject(
projectPath: string,
studentId: string,
rubric: ProjectGradingRubric
): Promise {
const result: GradingResult = {
studentId,
projectName: projectPath.split('/').pop() || '',
scores: {},
finalScore: 0,
feedback: [],
autoChecks: {}
};
// 自动化检查
result.autoChecks.testCoverage = await getTestCoverage(projectPath);
result.autoChecks.codeQuality = await runLinter(projectPath);
result.autoChecks.buildSuccess = await testBuild(projectPath);
// 给每个维度打分
for (const dim of rubric.dimensions) {
let score = 3; // 默认 3 分
if (dim.name === 'testCoverage') {
score = Math.min(5, Math.floor((result.autoChecks.testCoverage / 20))); // 80% 覆盖率 = 5 分
} else if (dim.name === 'codeQuality') {
score = result.autoChecks.codeQuality.passed ? 5 : 2;
}
result.scores[dim.name] = score;
result.feedback.push(`${dim.name}: ${score}/5 - ${dim.criteria[score] || 'N/A'}`);
}
// 计算加权总分
for (const dim of rubric.dimensions) {
result.finalScore += result.scores[dim.name] * dim.weight;
}
return result;
}
async function getTestCoverage(projectPath: string): Promise {
// 实现:读取 coverage 报告
return 85;
}
async function runLinter(projectPath: string): Promise<{ passed: boolean; errors: string[] }> {
// 实现:运行 ESLint 或类似工具
return { passed: true, errors: [] };
}
async function testBuild(projectPath: string): Promise {
// 实现:运行 npm build
return true;
}