diff --git a/lib/metadata/policies.js b/lib/metadata/policies.js index c5a21aa..d88da7a 100644 --- a/lib/metadata/policies.js +++ b/lib/metadata/policies.js @@ -170,9 +170,9 @@ var policies = { "tool": "phantomas", "label": "CSS syntax error", "message": "

Yellow Lab Tools failed to parse a CSS file. I doubt the problem comes from the css parser.

Maybe a CSS validator can help you.

", - "isOkThreshold": 1, - "isBadThreshold": 2, - "isAbnormalThreshold": 3 + "isOkThreshold": 0, + "isBadThreshold": 1, + "isAbnormalThreshold": 1 }, "cssRules": { "tool": "phantomas", @@ -390,6 +390,14 @@ var policies = { "isBadThreshold": 12, "isAbnormalThreshold": 25 }, + "cachingNotSpecified": { + "tool": "phantomas", + "label": "Caching not specified", + "message": "

When no caching is specified, each browser will handle it differently. Most of the time, it will automatically add a cache for you, but a poor one. You'd better handle it yourself.

", + "isOkThreshold": 5, + "isBadThreshold": 20, + "isAbnormalThreshold": 40 + }, "cachingTooShort": { "tool": "phantomas", "label": "Caching too short", diff --git a/lib/scoreCalculator.js b/lib/scoreCalculator.js index 25a147c..2d8dfaf 100644 --- a/lib/scoreCalculator.js +++ b/lib/scoreCalculator.js @@ -9,8 +9,9 @@ var ScoreCalculator = function() { var results = { categories: {} }; - var weight; + var categoryScore; var categoryName; + var weight; debug('Starting calculating scores'); @@ -20,31 +21,24 @@ var ScoreCalculator = function() { label: profile.categories[categoryName].label }; - var sum = 0; - var totalWeight = 0; + categoryScore = new ScoreMerger(); var rules = []; + var policyScore; for (var policyName in profile.categories[categoryName].policies) { weight = profile.categories[categoryName].policies[policyName]; if (data.rules[policyName]) { - var policyScore = data.rules[policyName].score + data.rules[policyName].abnormalityScore; - sum += policyScore * weight; + policyScore = data.rules[policyName].score + (data.rules[policyName].abnormalityScore * 2); + categoryScore.push(policyScore, weight); } else { - // Max value if rule is not here - sum += 100 * weight; debug('Warning: could not find rule %s', policyName); } - totalWeight += weight; rules.push(policyName); } - if (totalWeight === 0) { - categoryResult.categoryScore = 100; - } else { - categoryResult.categoryScore = Math.round(Math.max(sum, 0) / totalWeight); - } + categoryResult.categoryScore = categoryScore.getScore(); categoryResult.rules = rules; results.categories[categoryName] = categoryResult; @@ -52,26 +46,17 @@ var ScoreCalculator = function() { // Calculate general score - var globalSum = 0; - var globalTotalWeight = 0; + var globalScore = new ScoreMerger(); for (categoryName in profile.globalScore) { weight = profile.globalScore[categoryName]; if (results.categories[categoryName]) { - globalSum += results.categories[categoryName].categoryScore * weight; - } else { - globalSum += 100 * weight; + globalScore.push(results.categories[categoryName].categoryScore, weight); } - globalTotalWeight += profile.globalScore[categoryName]; - } - - if (globalTotalWeight === 0) { - results.globalScore = 100; - } else { - results.globalScore = Math.round(globalSum / globalTotalWeight); } + results.globalScore = Math.round(globalScore.getScore()); debug('Score calculation finished:'); @@ -79,6 +64,24 @@ var ScoreCalculator = function() { return results; }; + + + var ScoreMerger = function() { + var sum = 0; + var totalWeight = 0; + + this.push = function(score, weight) { + sum += (100 - score) * weight; + totalWeight += weight; + }; + + this.getScore = function() { + if (totalWeight === 0) { + return 100; + } + return Math.round(100 - (sum / totalWeight)); + }; + }; }; module.exports = new ScoreCalculator(); \ No newline at end of file