CoolFace
Apppublic

hpcompaq435/accessaudit-scanner

sourceHugging Faceupdated 4mo agoView on Hugging Face
0likes
score.ts39 linesDownload Raw Back to src
1import type { ScannedViolation, ScanSummary, Impact } from "./types.js";2 3/**4 * Transparent, tunable scoring. We start at 100 and subtract a penalty per5 * violation, weighted by severity and (capped) number of failing elements.6 * The cap stops a single rule from zeroing the whole score.7 *8 * This is intentionally simple and explainable — we never claim it equals9 * "legal compliance", only a relative health indicator.10 */11const WEIGHTS: Record<Impact, number> = {12  critical: 15,13  serious: 7,14  moderate: 3,15  minor: 1,16};17 18const NODE_CAP = 5;19 20export function computeScore(violations: ScannedViolation[]): number {21  let penalty = 0;22  for (const v of violations) {23    penalty += WEIGHTS[v.impact] * Math.min(v.nodeCount, NODE_CAP);24  }25  return Math.max(0, 100 - penalty);26}27 28export function summarize(violations: ScannedViolation[]): ScanSummary {29  const summary: ScanSummary = {30    critical: 0,31    serious: 0,32    moderate: 0,33    minor: 0,34    total: violations.length,35  };36  for (const v of violations) summary[v.impact] += 1;37  return summary;38}39