<commit_before>/*! Kernel CI Dashboard | Licensed under the GNU GPL v3 (or later) */
define([
    'd3',
    'charts/base',
    'utils/html',
    'charts/rate'
], function(d3, k, html) {
    'use strict';
    var passrate;

    passrate = {};

    function countBDReports(response) {
        var dataObj = null,
            i = 0,
            count,
            tData,
            dataLength,
            lData,
            kernel,
            status;

        count = response.count;
        if (count > 0) {
            dataObj = {};
            tData = response.result;
            dataLength = tData.length;

            for (i; i < dataLength; i = i + 1) {
                lData = tData[i];
                kernel = lData.kernel;
                status = lData.status;

                if (!dataObj.hasOwnProperty(kernel)) {
                    dataObj[kernel] = {};
                    dataObj[kernel].job = lData.job;
                    dataObj[kernel].kernel = kernel;
                    dataObj[kernel].pass = 0;
                    dataObj[kernel].fail = 0;
                    dataObj[kernel].other = 0;
                }

                switch (status) {
                    case 'PASS':
                        dataObj[kernel].pass = (dataObj[kernel].pass || 0) + 1;
                        break;
                    case 'FAIL':
                        dataObj[kernel].fail = (dataObj[kernel].fail || 0) + 1;
                        break;
                    default:
                        dataObj[kernel].other =
                            (dataObj[kernel].other || 0) + 1;
                        break;
                }

                dataObj[kernel].total = (dataObj[kernel].total || 0) + 1;
            }
        }

        return dataObj;
    }

    function createGraph(data, settings) {
        if (data) {
            settings.values = data;
            settings.chart = k.charts.rate();

            html.removeChildren(document.getElementById(settings.element));

            d3.select('#' + settings.element)
                .data([settings])
                .each(function(datum) {
                    d3.select(this).call(datum.chart);
                });
        } else {
            html.replaceContent(
                document.getElementById(settings.element),<commit_msg>Rework the non-webworker count function<commit_after>/*! Kernel CI Dashboard | Licensed under the GNU GPL v3 (or later) */
define([
    'd3',
    'charts/base',
    'utils/html',
    'charts/rate'
], function(d3, k, html) {
    'use strict';
    var passrate;

    passrate = {};

    function countBDReports(response) {
        var count,
            dataObj,
            kernel,
            results,
            status;

        function _count(result) {
            kernel = result.kernel;
            status = result.status;

            if (!dataObj.hasOwnProperty(kernel)) {
                dataObj[kernel] = {};
                dataObj[kernel].job = result.job;
                dataObj[kernel].kernel = kernel;
                dataObj[kernel].pass = 0;
                dataObj[kernel].fail = 0;
                dataObj[kernel].other = 0;
            }

            switch (status) {
                case 'PASS':
                    dataObj[kernel].pass = (dataObj[kernel].pass || 0) + 1;
                    break;
                case 'FAIL':
                    dataObj[kernel].fail = (dataObj[kernel].fail || 0) + 1;
                    break;
                default:
                    dataObj[kernel].other = (dataObj[kernel].other || 0) + 1;
                    break;
            }

            dataObj[kernel].total = (dataObj[kernel].total || 0) + 1;
        }

        dataObj = null;
        count = response.count;

        if (count > 0) {
            dataObj = {};
            results = response.result;
            results.forEach(_count);
        }

        return dataObj;
    }

    function createGraph(data, settings) {
        if (data) {
            settings.values = data;
            settings.chart = k.charts.rate();

            html.removeChildren(document.getElementById(settings.element));

            d3.select('#' + settings.element)
                .data([settings])
                .each(function(datum) {
                    d3.select(this).call(datum.chart);
                });
        } else {
            html.replaceContent(
                document.getElementById(settings.element),
{'fraction_non_alphanumeric': 0.11605937921727395, 'fraction_numerical': 0.008097165991902834, 'mean_word_length': 1.2124378109452736, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7478546', 'n_tokens_mistral': 1235, 'n_tokens_neox': 1128, 'n_words': 232}