diff --git a/front/src/views/rule.html b/front/src/views/rule.html index b2ee64b..7961171 100644 --- a/front/src/views/rule.html +++ b/front/src/views/rule.html @@ -20,7 +20,16 @@ {{rule.policy.isOkThreshold}} {{rule.policy.unit}} or less or more - to get the 100/100 score. + to get the 100/100 score on this issue. + +
+ Your new global would increase by {{rule.globalScoreIfFixed - result.scoreProfiles.generic.globalScore}} points ({{rule.globalScoreIfFixed}}/100). +
+
+ Your new global score would increase, but still not enough to reach 0/100. That's embarassing... +
+
+ Your new global score would slightly increase, but not enough to gain a single point.
diff --git a/lib/runner.js b/lib/runner.js index 93255e8..31e2044 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -51,10 +51,28 @@ var Runner = function(params) { // Scores calculator var scoreProfileGeneric = require('./metadata/scoreProfileGeneric.json'); data.scoreProfiles = { - generic : scoreCalculator.calculate(data, scoreProfileGeneric) + generic : scoreCalculator.calculate(data, scoreProfileGeneric, true) }; + // Calculate "If you fix this issue, your new score is..." on each rule + debug('Calculate "If you fix this issue..." scores'); + Object.keys(data.rules).forEach(function(ruleName) { + // Save current values + var oldScore = data.rules[ruleName].score; + var oldAbnormalityScore = data.rules[ruleName].abnormalityScore; + // Simulate a 100/100 score on a specific rule + data.rules[ruleName].score = 100; + data.rules[ruleName].abnormalityScore = 0; + // Calculate new score + data.rules[ruleName].globalScoreIfFixed = scoreCalculator.calculate(data, scoreProfileGeneric, false).globalScore; + // Revert values + data.rules[ruleName].score = oldScore; + data.rules[ruleName].abnormalityScore = oldAbnormalityScore; + }); + debug('Calculating is finished'); + + if (data.toolsResults.phantomas.offenders.blockedRequests) { data.blockedRequests = data.toolsResults.phantomas.offenders.blockedRequests; } diff --git a/lib/scoreCalculator.js b/lib/scoreCalculator.js index 2d8dfaf..3fde310 100644 --- a/lib/scoreCalculator.js +++ b/lib/scoreCalculator.js @@ -4,7 +4,7 @@ var debug = require('debug')('ylt:scoreCalculator'); var ScoreCalculator = function() { 'use strict'; - this.calculate = function(data, profile) { + this.calculate = function(data, profile, debugFlag) { var results = { categories: {} @@ -13,7 +13,9 @@ var ScoreCalculator = function() { var categoryName; var weight; - debug('Starting calculating scores'); + if (debugFlag) { + debug('Starting calculating scores'); + } // Calculate categories for (categoryName in profile.categories) { @@ -31,7 +33,7 @@ var ScoreCalculator = function() { if (data.rules[policyName]) { policyScore = data.rules[policyName].score + (data.rules[policyName].abnormalityScore * 2); categoryScore.push(policyScore, weight); - } else { + } else if (debugFlag) { debug('Warning: could not find rule %s', policyName); } @@ -59,8 +61,10 @@ var ScoreCalculator = function() { results.globalScore = Math.round(globalScore.getScore()); - debug('Score calculation finished:'); - debug(results); + if (debugFlag) { + debug('Score calculation finished:'); + debug(results); + } return results; };