UNPKG

agentsqripts

Version:

Comprehensive static code analysis toolkit for identifying technical debt, security vulnerabilities, performance issues, and code quality problems

57 lines (45 loc) 1.68 kB
/** * @file Performance score calculator * @description Calculates performance score and grade */ /** * Calculate performance score based on issues * @param {Array} issues - Array of performance issues * @returns {number} Performance score (0-100) */ function calculatePerformanceScore(issues, linesOfCode = 0) { // Enhanced scoring that considers issue severity and impact if (!issues || issues.length === 0) return 100; // Weight issues by severity and impact for more accurate scoring let totalWeight = 0; for (const issue of issues) { let weight = 1; // Base weight // Severity multiplier if (issue.severity === 'HIGH') weight *= 3; else if (issue.severity === 'MEDIUM') weight *= 2; else if (issue.severity === 'LOW') weight *= 1; // Impact multiplier (if provided) if (issue.impact && typeof issue.impact === 'number') { weight *= (issue.impact / 5); // Normalize impact to reasonable range } totalWeight += weight; } // Calculate score: 100 - (weighted issues with cap) // High-impact issues will result in score < 90 as expected by tests const score = 100 - Math.min(50, totalWeight * 2); // Cap deduction at 50 points // Round to nearest integer and ensure 0-100 range return Math.max(0, Math.min(100, Math.round(score))); } const { getLetterGrade } = require('../utils/gradeUtils'); /** * Get performance grade based on score * @param {number} score - Performance score (0-100) * @returns {string} Performance grade */ function getPerformanceGrade(score) { return getLetterGrade(score); } module.exports = { calculatePerformanceScore, getPerformanceGrade };