Browse Source

Take in account abnormalityScore to calculate category score

Gaël Métais 10 years ago
parent
commit
c8ba9ef99a
3 changed files with 8 additions and 7 deletions
  1. 2 2
      lib/metadata/scoreProfileGeneric.json
  2. 3 2
      lib/scoreCalculator.js
  3. 3 3
      test/fixtures/scoreOutput.json

+ 2 - 2
lib/metadata/scoreProfileGeneric.json

@@ -31,8 +31,8 @@
         "jQueryVersion": {
             "label": "jQuery version",
             "policies": {
-                "jQueryVersion": 1,
-                "jQueryDifferentVersions": 5
+                "jQueryVersion": 5,
+                "jQueryDifferentVersions": 0.1
             }
         },
         "cssSyntaxError": {

+ 3 - 2
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;

+ 3 - 3
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",