<commit_before>String.prototype.capitalize = function() {
    return this.charAt(0).toUpperCase() + this.slice(1);
}

var addFormGroup = function(name) {
    filterdiv = $('<div class="form-group"></div>').appendTo( $('#filters') );
    labeldiv = $('<label for="'+name+'-filter">'+name.capitalize()+'</label>').appendTo( $(filterdiv) );
    formitem = $('<select data-filter="'+name+'" class="form-control" id="'+name+'-filter"><option value=""></option></select>').appendTo($(labeldiv));
    formitem.on('change', function() {
        updateDataTablesUrl();
        document.eventstable.ajax.reload(null, false);
    });
}

var addFilters = function() {
    $('#filters').addClass('form-inline');
    addFormGroup('status');
    addFormGroup('datacenter');
    addFormGroup('checkname');
}

var addOption = function(selectID, option, value=null) {
    if (value === null) {
        value = option;
    }
    if ( $('#'+selectID+':has(option[value='+value+'])').length == 0) {
        $('#'+selectID).append('<option value="'+value+'">'+option+'</option>');
    }
}

var updateFilters = function() {

    $.getJSON('/api/events/checks', function(data) {
        $.each(data.checks, function(idx, obj) {
            addOption('checkname-filter', obj);
        });
    });
    $.getJSON('/api/events/datacenters', function(data) {
        $.each(data.datacenters, function(idx, obj) {
            addOption('datacenter-filter', obj);
        });
    });
}

var updateDataTablesUrl = function() {
    params = {}
    $('#filters select').each(function(idx, obj) {
        params[$(obj).data('filter')] = $(obj).children('option:selected').val()
    });
    if ( $.QueryString['dashboard'] ) {
        params['dashboard'] = $.QueryString['dashboard'];
    }
    console.log(params);
    return '/api/events?'+$.param(params);
}

$(document).ready(function() {
    (function($) {
        $.QueryString = (function(a) {
            if (a == "") return {};
            var b = {};
            for (var i = 0; i < a.length; ++i)
            {
                var p=a[i].split('=');
                if (p.length != 2) continue;
                b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
            }
            return b;
        })(window.location.search.substr(1).split('&'))
    })(jQuery);
    statusclasses = {
        'OK': 'success',
        'Warning': 'warning',
        'Critical': 'danger'
    }
    statusnames = {
        0: 'OK',
        1: 'Warning',
        2: 'Critical'
    }
    document.eventstable = $('#events').DataTable({
        'lengthMenu': [ [25, 50, 100, -1], [25, 50, 100, "All"] ],
        //'stateSave' : true,
        'columnDefs': [
            {
                "targets": [ 0 ],
                "visible": false,
                "searchable": true
            },
        ],
        'order': [
            [ 0, 'asc' ],
            [ 5, 'desc' ],
        ],
        'ajax': {
            url: updateDataTablesUrl(),
            dataSrc: 'events'
        },
        'dom': "<'row'<'col-sm-2'l><'col-sm-8'<'#filters'>><'col-sm-2'f>><'row'<'col-sm-12'tr>><'row'<'col-sm-5'i><'col-sm-7'p>>",
        'columns': [
            {data: 'check.status',
             name: 'status'},
            {data: 'datacenter',
             name: 'datacenter'},
            {data: 'client.name',
             name: 'source'},
            {data: 'check.name',
             name: 'check-name'},
            {data: 'check.output',
             name: 'check-output'},
            {data: 'occurrences',
             name: 'occurrences'},
            {data: 'timestamp',
             name: 'timestamp'},
        ],
        'fnRowCallback': function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
            $(nRow).addClass(statusclasses[aData['check']['status']]);
            var d = new Date(0);
            d.setUTCSeconds(aData['timestamp']);
            $('td:last', nRow).html('<time class="timeago" datetime="'+d.toISOString()+'">'+d+'</time>');<commit_msg>Fix up dashboards and filtering<commit_after>String.prototype.capitalize = function() {
    return this.charAt(0).toUpperCase() + this.slice(1);
}

var addFormGroup = function(name) {
    filterdiv = $('<div class="form-group"></div>').appendTo( $('#filters') );
    labeldiv = $('<label for="'+name+'-filter">'+name.capitalize()+'</label>').appendTo( $(filterdiv) );
    formitem = $('<select data-filter="'+name+'" class="form-control" id="'+name+'-filter"><option value=""></option></select>').appendTo($(labeldiv));
    formitem.on('change', function() {
        updateDataTablesUrl();
    });
}

var addFilters = function() {
    $('#filters').addClass('form-inline');
    addFormGroup('status');
    addFormGroup('datacenter');
    addFormGroup('checkname');
}

var addOption = function(selectID, option, value=null) {
    if (value === null) {
        value = option;
    }
    if ( $('#'+selectID+':has(option[value='+value+'])').length == 0) {
        $('#'+selectID).append('<option value="'+value+'">'+option+'</option>');
    }
}

var updateFilters = function() {

    $.getJSON('/api/events/checks', function(data) {
        $.each(data.checks.sort(), function(idx, obj) {
            addOption('checkname-filter', obj);
        });
    });
    $.getJSON('/api/events/datacenters', function(data) {
        $.each(data.datacenters, function(idx, obj) {
            addOption('datacenter-filter', obj);
        });
    });
}

var setDataTablesUrl = function() {
    params = {}
    $('#filters select').each(function(idx, obj) {
        params[$(obj).data('filter')] = $(obj).children('option:selected').val()
    });
    if ( $.QueryString['dashboard'] ) {
        params['dashboard'] = $.QueryString['dashboard'];
    }
    console.log(params);
    return '/api/events?'+$.param(params);
}

var updateDataTablesUrl = function() {
    params = {}
    $('#filters select').each(function(idx, obj) {
        params[$(obj).data('filter')] = $(obj).children('option:selected').val()
    });
    if ( $.QueryString['dashboard'] ) {
        params['dashboard'] = $.QueryString['dashboard'];
    }
    console.log(params);
    document.eventstable.ajax.url('/api/events?'+$.param(params));
    document.eventstable.ajax.reload(null, false);
}

$(document).ready(function() {
    (function($) {
        $.QueryString = (function(a) {
            if (a == "") return {};
            var b = {};
            for (var i = 0; i < a.length; ++i)
            {
                var p=a[i].split('=');
                if (p.length != 2) continue;
                b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
            }
            return b;
        })(window.location.search.substr(1).split('&'))
    })(jQuery);
    statusclasses = {
        'OK': 'success',
        'Warning': 'warning',
        'Critical': 'danger'
    }
    statusnames = {
        0: 'OK',
        1: 'Warning',
        2: 'Critical'
    }
    document.eventstable = $('#events').DataTable({
        'lengthMenu': [ [25, 50, 100, -1], [25, 50, 100, "All"] ],
        //'stateSave' : true,
        'columnDefs': [
            {
                "targets": [ 0 ],
                "visible": false,
                "searchable": true
            },
        ],
        'order': [
            [ 0, 'asc' ],
            [ 5, 'desc' ],
        ],
        'ajax': {
            url: setDataTablesUrl(),
            dataSrc: 'events'
        },
        'dom': "<'row'<'col-sm-2'l><'col-sm-8'<'#filters'>><'col-sm-2'f>><'row'<'col-sm-12'tr>><'row'<'col-sm-5'i><'col-sm-7'p>>",
        'columns': [
            {data: 'check.status',
             name: 'status'},
            {data: 'datacenter',
             name: 'datacenter'},
            {data: 'client.name',
             name: 'source'},
            {data: 'check.name',
             name: 'check-name'},
            {data: 'check.output',
             name: 'check-output'},
            {data: 'occurrences',
             name: 'occurrences'},
            {data: 'timestamp',
             name: 'timestamp'},
        ],
        'fnRowCallback': function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
            $(nRow).addClass(statusclasses[aData['check']['status']]);
            var d = new Date(0);
            d.setUTCSeconds(aData['timestamp']);
            $('td:last', nRow).html('<time class="timeago" datetime="'+d.toISOString()+'">'+d+'</time>');
{'fraction_non_alphanumeric': 0.2143283582089552, 'fraction_numerical': 0.008835820895522388, 'mean_word_length': 2.2314814814814814, 'pattern_counts': {'":': 6, '<': 49, '<?xml version=': 0, '>': 47, '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': '1871770', 'n_tokens_mistral': 2666, 'n_tokens_neox': 2616, 'n_words': 420}