tasks/lib/conditions.js
function(results) {
    var globalScoreSum = 0;
    var globalScoreCount = 0;

    var rulesScoresSum = {};
    var rulesScoresCount = {};
    var rulesValuesSum = {};
    var rulesValuesCount = {};


    results.forEach(function(result) {
        
        // Global score
        globalScoreSum += result.scoreProfiles.generic.globalScore;
        globalScoreCount ++;

        // Rules
        for (var ruleName in result.rules) {
            if (!rulesScoresCount[ruleName]) {
                rulesScoresSum[ruleName] = 0;
                rulesScoresCount[ruleName] = 0;
                rulesValuesSum[ruleName] = 0;
                rulesValuesCount[ruleName] = 0;
            }

            rulesScoresSum[ruleName] += result.rules[ruleName].score;
            rulesScoresCount[ruleName] ++;
            rulesValuesSum[ruleName] += result.rules[ruleName].value;
            rulesValuesCount[ruleName] ++;
        }
    });

    // Calculate averages
    var averageObject = {
        scoreProfiles: {
            generic: {
                globalScore: globalScoreSum / globalScoreCount
            }
        },
        rules: {}
    };

    for (var ruleName in rulesScoresCount) {
        var score = rulesScoresSum[ruleName] / rulesScoresCount[ruleName];
        var value = rulesValuesSum[ruleName] / rulesValuesCount[ruleName];

        averageObject.rules[ruleName] = {
            score: score
        };

        if (!isNaN(value)) {
            averageObject.rules[ruleName].value = value;
        }
    }

    return averageObject;
}
function(results) {
    var globalScoreSum = 0;
    var globalScoreCount = 0;

    var rulesScoresSum = {};
    var rulesScoresCount = {};
    var rulesValuesSum = {};
    var rulesValuesCount = {};


    results.forEach(function(result) {
        
        // Global score
        globalScoreSum += result.scoreProfiles.generic.globalScore;
        globalScoreCount ++;

        // Rules
        for (var ruleName in result.rules) {
            if (!rulesScoresCount[ruleName]) {
                rulesScoresSum[ruleName] = 0;
                rulesScoresCount[ruleName] = 0;
                rulesValuesSum[ruleName] = 0;
                rulesValuesCount[ruleName] = 0;
            }

            rulesScoresSum[ruleName] += result.rules[ruleName].score;
            rulesScoresCount[ruleName] ++;
            rulesValuesSum[ruleName] += result.rules[ruleName].value;
            rulesValuesCount[ruleName] ++;
        }
    });

    // Calculate averages
    var averageObject = {
        scoreProfiles: {
            generic: {
                globalScore: globalScoreSum / globalScoreCount
            }
        },
        rules: {}
    };

    for (var ruleName in rulesScoresCount) {
        var score = rulesScoresSum[ruleName] / rulesScoresCount[ruleName];
        var value = rulesValuesSum[ruleName] / rulesValuesCount[ruleName];

        averageObject.rules[ruleName] = {
            score: score
        };

        if (!isNaN(value)) {
            averageObject.rules[ruleName].value = value;
        }
    }

    return averageObject;
}
function ( results ) { var globalScoreSum = 0 ; var globalScoreCount = 0 ; var rulesScoresSum = { } ; var rulesScoresCount = { } ; var rulesValuesSum = { } ; var rulesValuesCount = { } ; results . forEach ( function ( result ) { // Global score globalScoreSum += result . scoreProfiles . generic . globalScore ; globalScoreCount ++ ; // Rules for ( var ruleName in result . rules ) { if ( ! rulesScoresCount [ ruleName ] ) { rulesScoresSum [ ruleName ] = 0 ; rulesScoresCount [ ruleName ] = 0 ; rulesValuesSum [ ruleName ] = 0 ; rulesValuesCount [ ruleName ] = 0 ; } rulesScoresSum [ ruleName ] += result . rules [ ruleName ] . score ; rulesScoresCount [ ruleName ] ++ ; rulesValuesSum [ ruleName ] += result . rules [ ruleName ] . value ; rulesValuesCount [ ruleName ] ++ ; } } ) ; // Calculate averages var averageObject = { scoreProfiles : { generic : { globalScore : globalScoreSum / globalScoreCount } } , rules : { } } ; for ( var ruleName in rulesScoresCount ) { var score = rulesScoresSum [ ruleName ] / rulesScoresCount [ ruleName ] ; var value = rulesValuesSum [ ruleName ] / rulesValuesCount [ ruleName ] ; averageObject . rules [ ruleName ] = { score : score } ; if ( ! isNaN ( value ) ) { averageObject . rules [ ruleName ] . value = value ; } } return averageObject ; }
Gets every score or value from all results and calculates their average NOT USED FOR THE MOMENT
Gets every score or value from all results and calculates their average NOT USED FOR THE MOMENT