scoreMutator - Initialization - Reports API

Reports API Initialization

scoreMutator()

Callback function used in the learning outcomes report to mutate scores shown in each cell of the report.

You would want to use this to modify the presentation of scores, for example, applying your own business rule to treat unattempted questions as incorrect.

This function is called before scores are rendered in the report.

Examples

var callbacks = {
    scoreMutator: function (scores) {
        for (var i = 0; i < scores.length; i++) {
            // apply a custom business rule to treat
            // unattempted questions as incorrect
            var unattempted = scores[i].unattempted();
            var incorrect = scores[i].incorrect();

            scores[i].unattempted(0);
            scores[i].incorrect(incorrect + unattempted);
        }
    },
    // ...
};

Arguments

  • scores array[scoreMutatorObject]

    An array of objects, each corresponding to a single cell in the report. Each object exposes methods for mutating the score shown in the report.

    • scoreMutatorObject object

      An object containing methods to mutate a score, as well as assign HTML data attributes to certain elements to make them accessible for design and behavioral changes. The individual correct, incorrect, unattempted, and unmarked components of the score are exposed as getter methods, and each component can be overridden using the corresponding setter methods. The components of the score will be used to render score percentages, score bars, and tooltips.

      • correct() function

        Returns the correct component of the score.

      • correct(number) function

        Sets the correct component of the score.

      • countSeen() function

        Returns the number of Items from which this score is calculated, i.e. the number of Items presented to the user that meet the filters for this particular report (or cell within the report).

      • domData(object) function

        Used to store custom data attributes against this score's cell, for the purpose of custom logic or CSS selectors.

        You can provide a map of key-value pairs which will be stored in the DOM as custom data attributes. Each key will be added to the score's cell as a data attribute in the form data-custom_keyname="value". The data attribute can then be used as a CSS selector for applying custom styles, or a DOM selector to apply your own custom logic.

        See an example of how to customize this option in the demo for Learning Outcomes - Class Demo.

      • incorrect() function

        Returns the incorrect component of the score.

      • incorrect(number) function

        Sets the incorrect component of the score.

      • percentScore(number) function

        Sets the overall percent score.

        Reports API uses correct / maxScore to calculate the percentage score value, but this setter method can be used to override the shown percentage regardless of the values of the individual score components.

      • unmarked() function

        Returns the unmarked component of the score.

      • unmarked(number) function

        Sets the unmarked component of the score.

      • unattempted() function

        Returns the unattempted component of the score.

      • unattempted(number) function

        Sets the unattempted component of the score.

Return value

None (undefined).

Was this article helpful?

Did you arrive here by accident? If so, learn more about Learnosity.