<commit_before>// JavaScript code for the job-kernel.html template.
function showHideDefconfs(element) {
    switch (element.id) {
        case 'success-cell':
            if ($('#success-btn').attr('disabled') !== 'disabled') {
                $('.df-failed').hide();
                $('.df-success').show();
                $('.df-unknown').hide();
                $('#success-btn').addClass('active').siblings().removeClass('active');
            }
            break;
        case 'success-btn':
            $('.df-failed').hide();
            $('.df-success').show();
            $('.df-unknown').hide();
            break;
        case 'fail-cell':
            if ($('#fail-btn').attr('disabled') !== 'disabled') {
                $('.df-failed').show();
                $('.df-success').hide();
                $('.df-unknown').hide();
                $('#fail-btn').addClass('active').siblings().removeClass('active');
            }
            break;
        case 'fail-btn':
            $('.df-failed').show();
            $('.df-success').hide();
            $('.df-unknown').hide();
            break;
        case 'unknown-cell':
            if ($('#unknown-btn').attr('disabled') !== 'disabled') {
                $('.df-failed').hide();
                $('.df-success').hide();
                $('.df-unknown').show();
                $('#unknown-btn').addClass('active').siblings().removeClass('active');
            }
            break;
        case 'unknown-btn':
            $('.df-failed').hide();
            $('.df-success').hide();
            $('.df-unknown').show();
            break;
        default:
            $('.df-failed').show();
            $('.df-success').show();
            $('.df-unknown').show();
            break;
    }
}

$(document).ready(function() {
    $('body').tooltip({
        'selector': '[rel=tooltip]',
        'placement': 'auto top'
    });

    $('#li-job').addClass('active');

    $('.btn-group > .btn').click(function() {
        $(this).addClass('active').siblings().removeClass('active');
    });

    $.ajax({
        'url': '/_ajax/defconf',
        'traditional': true,
        'dataType': 'json',
        'data': {
            'job_id': $('#job-id').val(),
            'field': 'status',
            'nfield': '_id'
        },
        'dataFilter': function(data, type) {
            if (type === 'json') {
                return JSON.parse(data).result;
            }
            return data;
        }
    }).done(function(data) {
        var success = 0,
            fail = 0,
            unknown = 0,
            i = 0,
            len = data.length,
            width = 200,
            height = 200,
            radius = Math.min(width, height) / 2,
            // success, fail and unknown status colors.
            color = ['#5cb85c', '#d9534f', '#f0ad4e'],
            pie = d3.layout.pie().sort(null),
            arc = d3.svg.arc().innerRadius(radius - 30).outerRadius(radius - 50);

        for (i; i < len; i++) {
            switch (data[i].status) {
                case 'FAIL':
                    fail++;
                    break;
                case 'PASS':
                    success++;
                    break;
                default:
                    unknown++;
                    break;
            }
        }

        var dataset = [success, fail, unknown],
            svg = d3.select('#builds-chart').append('svg')
                .attr('width', width)
                .attr('height', height)
                .append('g')
                .attr('transform', 'translate(' + width / 2 + ',' +
                    height / 2 + ')'
                );
        
        svg.selectAll('path')
            .data(pie(dataset))
            .enter().append('path')
            .attr('fill', function(d, i) {
                return color[i];
            })
            .attr('d', arc);

        $('#success-cell')
            .empty()
            .append(
                '<span rel="tooltip" data-toggle="tooltip" ' +
                'title="Successful defconfigs built">' + success + '</span>'
            ).css('border-bottom-color', color[0]);
        $('#fail-cell')
            .empty()
            .append(
                '<span rel="tooltip" data-toggle="tooltip" ' +
                'title="Failed defconfigs built">' + fail + '</span>'
            ).css('border-bottom-color', color[1]);
        $('#unknown-cell')
            .empty()
            .append(
                '<span rel="tooltip" data-toggle="tooltip" ' +
                'title="Unknown status">' + unknown + '</span>'
            ).css('border-bottom-color', color[2]);
    });

    $.ajax({
        'url': '/_ajax/defconf',
        'traditional': true,
        'dataType': 'json',
        'context': $('#accordion'),
        'data': {
            'job_id': $('#job-id').val(),
            'sort': '_id',
            'sort_order': 1
        },
        'dataFilter': function(data, type) {
            if (type === 'json') {
                return JSON.parse(data).result;
            }
            return data;
        },
        'statusCode': {<commit_msg>job-kernel: Default to sort first on status.<commit_after>// JavaScript code for the job-kernel.html template.
function showHideDefconfs(element) {
    switch (element.id) {
        case 'success-cell':
            if ($('#success-btn').attr('disabled') !== 'disabled') {
                $('.df-failed').hide();
                $('.df-success').show();
                $('.df-unknown').hide();
                $('#success-btn').addClass('active').siblings().removeClass('active');
            }
            break;
        case 'success-btn':
            $('.df-failed').hide();
            $('.df-success').show();
            $('.df-unknown').hide();
            break;
        case 'fail-cell':
            if ($('#fail-btn').attr('disabled') !== 'disabled') {
                $('.df-failed').show();
                $('.df-success').hide();
                $('.df-unknown').hide();
                $('#fail-btn').addClass('active').siblings().removeClass('active');
            }
            break;
        case 'fail-btn':
            $('.df-failed').show();
            $('.df-success').hide();
            $('.df-unknown').hide();
            break;
        case 'unknown-cell':
            if ($('#unknown-btn').attr('disabled') !== 'disabled') {
                $('.df-failed').hide();
                $('.df-success').hide();
                $('.df-unknown').show();
                $('#unknown-btn').addClass('active').siblings().removeClass('active');
            }
            break;
        case 'unknown-btn':
            $('.df-failed').hide();
            $('.df-success').hide();
            $('.df-unknown').show();
            break;
        default:
            $('.df-failed').show();
            $('.df-success').show();
            $('.df-unknown').show();
            break;
    }
}

$(document).ready(function() {
    $('body').tooltip({
        'selector': '[rel=tooltip]',
        'placement': 'auto top'
    });

    $('#li-job').addClass('active');

    $('.btn-group > .btn').click(function() {
        $(this).addClass('active').siblings().removeClass('active');
    });

    $.ajax({
        'url': '/_ajax/defconf',
        'traditional': true,
        'dataType': 'json',
        'data': {
            'job_id': $('#job-id').val(),
            'field': 'status',
            'nfield': '_id'
        },
        'dataFilter': function(data, type) {
            if (type === 'json') {
                return JSON.parse(data).result;
            }
            return data;
        }
    }).done(function(data) {
        var success = 0,
            fail = 0,
            unknown = 0,
            i = 0,
            len = data.length,
            width = 200,
            height = 200,
            radius = Math.min(width, height) / 2,
            // success, fail and unknown status colors.
            color = ['#5cb85c', '#d9534f', '#f0ad4e'],
            pie = d3.layout.pie().sort(null),
            arc = d3.svg.arc().innerRadius(radius - 30).outerRadius(radius - 50);

        for (i; i < len; i++) {
            switch (data[i].status) {
                case 'FAIL':
                    fail++;
                    break;
                case 'PASS':
                    success++;
                    break;
                default:
                    unknown++;
                    break;
            }
        }

        var dataset = [success, fail, unknown],
            svg = d3.select('#builds-chart').append('svg')
                .attr('width', width)
                .attr('height', height)
                .append('g')
                .attr('transform', 'translate(' + width / 2 + ',' +
                    height / 2 + ')'
                );
        
        svg.selectAll('path')
            .data(pie(dataset))
            .enter().append('path')
            .attr('fill', function(d, i) {
                return color[i];
            })
            .attr('d', arc);

        $('#success-cell')
            .empty()
            .append(
                '<span rel="tooltip" data-toggle="tooltip" ' +
                'title="Successful defconfigs built">' + success + '</span>'
            ).css('border-bottom-color', color[0]);
        $('#fail-cell')
            .empty()
            .append(
                '<span rel="tooltip" data-toggle="tooltip" ' +
                'title="Failed defconfigs built">' + fail + '</span>'
            ).css('border-bottom-color', color[1]);
        $('#unknown-cell')
            .empty()
            .append(
                '<span rel="tooltip" data-toggle="tooltip" ' +
                'title="Unknown status">' + unknown + '</span>'
            ).css('border-bottom-color', color[2]);
    });

    $.ajax({
        'url': '/_ajax/defconf',
        'traditional': true,
        'dataType': 'json',
        'context': $('#accordion'),
        'data': {
            'job_id': $('#job-id').val(),
            'sort': ['status', '_id'],
            'sort_order': 1
        },
        'dataFilter': function(data, type) {
            if (type === 'json') {
                return JSON.parse(data).result;
            }
            return data;
        },
        'statusCode': {
{'fraction_non_alphanumeric': 0.19531629579244, 'fraction_numerical': 0.006413370906617433, 'mean_word_length': 1.3169743358847366, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '7313281', 'n_tokens_mistral': 2863, 'n_tokens_neox': 2756, 'n_words': 499}