From c8ba9ef99a1bf92977c5a657e364a21ada1f6cbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20M=C3=A9tais?= Date: Mon, 22 Dec 2014 23:11:25 +0100 Subject: [PATCH] Take in account abnormalityScore to calculate category score --- lib/metadata/scoreProfileGeneric.json | 4 ++-- lib/scoreCalculator.js | 5 +++-- test/fixtures/scoreOutput.json | 6 +++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/metadata/scoreProfileGeneric.json b/lib/metadata/scoreProfileGeneric.json index 2260afb..8feb3ff 100644 --- a/lib/metadata/scoreProfileGeneric.json +++ b/lib/metadata/scoreProfileGeneric.json @@ -31,8 +31,8 @@ "jQueryVersion": { "label": "jQuery version", "policies": { - "jQueryVersion": 1, - "jQueryDifferentVersions": 5 + "jQueryVersion": 5, + "jQueryDifferentVersions": 0.1 } }, "cssSyntaxError": { diff --git a/lib/scoreCalculator.js b/lib/scoreCalculator.js index 8a0a399..25a147c 100644 --- a/lib/scoreCalculator.js +++ b/lib/scoreCalculator.js @@ -28,7 +28,8 @@ var ScoreCalculator = function() { weight = profile.categories[categoryName].policies[policyName]; if (data.rules[policyName]) { - sum += data.rules[policyName].score * weight; + var policyScore = data.rules[policyName].score + data.rules[policyName].abnormalityScore; + sum += policyScore * weight; } else { // Max value if rule is not here sum += 100 * weight; @@ -42,7 +43,7 @@ var ScoreCalculator = function() { if (totalWeight === 0) { categoryResult.categoryScore = 100; } else { - categoryResult.categoryScore = Math.round(sum / totalWeight); + categoryResult.categoryScore = Math.round(Math.max(sum, 0) / totalWeight); } categoryResult.rules = rules; diff --git a/test/fixtures/scoreOutput.json b/test/fixtures/scoreOutput.json index 4630bbf..7c0259f 100644 --- a/test/fixtures/scoreOutput.json +++ b/test/fixtures/scoreOutput.json @@ -1,9 +1,9 @@ { - "globalScore": 69, + "globalScore": 57, "categories": { "category1": { "label": "Category 1", - "categoryScore": 87, + "categoryScore": 83, "rules": [ "metric1", "metric2", @@ -13,7 +13,7 @@ }, "category2": { "label": "Category 2", - "categoryScore": 31, + "categoryScore": 0, "rules": [ "metric5", "metric6",