codeatlas-enterprise / frontend /src /utils /riskCalculator.js
Shivam311's picture
feat: CodeAtlas Enterprise - IBM Bob Engineering Intelligence Platform
3a7842d
Raw
History Blame Contribute Delete
1.05 kB
export function normalizeRiskScore(input) {
if (typeof input === 'number') return Math.min(100, Math.max(0, input));
const level = String(input || 'low').toUpperCase();
return { CRITICAL: 95, HIGH: 75, MEDIUM: 50, LOW: 20 }[level] ?? 20;
}
export function calculateModuleRisk(file) {
const path = typeof file === 'string' ? file : file?.path || '';
const lower = path.toLowerCase();
if (/(auth|security|oauth|permission|token)/.test(lower)) return { level: 'HIGH', score: 82 };
if (/(main|app|server|router|route|api)/.test(lower)) return { level: 'HIGH', score: 74 };
if (/(model|schema|migration|db|database)/.test(lower)) return { level: 'MEDIUM', score: 58 };
if (/(test|spec|docs|readme)/.test(lower)) return { level: 'LOW', score: 22 };
return { level: 'MEDIUM', score: 45 };
}
export function topRiskFiles(files = [], count = 8) {
return files
.map((file) => ({ ...file, risk: calculateModuleRisk(file) }))
.sort((a, b) => b.risk.score - a.risk.score || (b.lines || 0) - (a.lines || 0))
.slice(0, count);
}