<commit_before>'use strict';

var filterModule = angular.module('uchiwa.filters', []);

filterModule.filter('arrayLength', function() {
  return function(array) {
    if (!array) { return 0; }
    if (array.constructor.toString().indexOf('Array') === -1) { return 0; }
    return array.length;
  };
});

filterModule.filter('arrayToString', function() {
  return function(array) {
    if (!array) { return ''; }
    if (array.constructor.toString().indexOf('Array') === -1) { return array; }
    return array.join(' ');
  };
});

filterModule.filter('buildEvents', function() {
  return function(events) {
    if (Object.prototype.toString.call(events) !== '[object Array]') {
      return events;
    }
    angular.forEach(events, function(event) {
      if (typeof(event.check) === 'undefined' && typeof(event.client) === 'undefined') {
        event.sourceName = 'unknown';
        return true;
      }
      else if (typeof(event.check) === 'undefined') {
        event.check = {};
      }
      event.sourceName = event.check.source || event.client.name;
    });
    return events;
  };
});

filterModule.filter('buildEventCount', function() {
  return function(events) {
    var eventCount = {};
    angular.forEach(events, function(event) {
      if (eventCount[event.check.name] === 'undefined' || !eventCount[event.check.name]) {
        eventCount[event.check.name] = 0;
      }
      eventCount[event.check.name] = eventCount[event.check.name] + 1;
    });
    var keys = [];
    keys = Object.keys(eventCount);
    var len = keys.length;
    keys.sort(alphabetical);
    var events = {};
    for (var i = 0; i < len; i++)
    {
        var k = keys[i];
        events[k] = eventCount[k];
    }
    eventCount = {};
    return events;
  };

  function alphabetical(a, b)<commit_msg>Fix tests<commit_after>'use strict';

var filterModule = angular.module('uchiwa.filters', []);

filterModule.filter('arrayLength', function() {
  return function(array) {
    if (!array) { return 0; }
    if (array.constructor.toString().indexOf('Array') === -1) { return 0; }
    return array.length;
  };
});

filterModule.filter('arrayToString', function() {
  return function(array) {
    if (!array) { return ''; }
    if (array.constructor.toString().indexOf('Array') === -1) { return array; }
    return array.join(' ');
  };
});

filterModule.filter('buildEvents', function() {
  return function(events) {
    if (Object.prototype.toString.call(events) !== '[object Array]') {
      return events;
    }
    angular.forEach(events, function(event) {
      if (typeof(event.check) === 'undefined' && typeof(event.client) === 'undefined') {
        event.sourceName = 'unknown';
        return true;
      }
      else if (typeof(event.check) === 'undefined') {
        event.check = {};
      }
      event.sourceName = event.check.source || event.client.name;
    });
    return events;
  };
});

filterModule.filter('buildEventCount', function() {
  return function(events) {
    var eventCount = {};
    angular.forEach(events, function(event) {
      if (eventCount[event.check.name] === 'undefined' || !eventCount[event.check.name]) {
        eventCount[event.check.name] = 0;
      }
      eventCount[event.check.name] = eventCount[event.check.name] + 1;
    });
    var keys = [];
    keys = Object.keys(eventCount);
    var len = keys.length;
    keys.sort(alphabetical);
    var eventsCounted = {};
    for (var i = 0; i < len; i++)
    {
        var k = keys[i];
        eventsCounted[k] = eventCount[k];
    }
    eventCount = {};
    return eventsCounted;
  };

  function alphabetical(a, b)
{'fraction_non_alphanumeric': 0.17485428809325562, 'fraction_numerical': 0.0038856508465167916, 'mean_word_length': 3.0223214285714284, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '2429225', 'n_tokens_mistral': 1126, 'n_tokens_neox': 1108, 'n_words': 220}