<commit_before><commit_msg>Add job to count events by parser.<commit_after>/**
 * Collect event count by parser.
 */

'use strict';

require(__dirname + '/../modules/diana.js');
var storage = diana.requireModule('storage/storage').createInstance();

var options = {out: {replace : "top_parsers"}};

var map = function() {
  emit(this.parser, {count: 1});
};

var reduce = function(key, values) {
  var result = {count: 0};
  values.forEach(function(value) {
    result.count += value.count;
  });
  return result;
};

storage.dbConnectAndOpen(function() {}, function(err, db) {
  storage.dbCollection(db, storage.collection, function() {}, function(err, collection) {
    collection.mapReduce(map, reduce, options, function(err, results, stats) {
      storage.dbClose();
    });
  });
});

{'fraction_non_alphanumeric': 0.17468354430379746, 'fraction_numerical': 0.002531645569620253, 'mean_word_length': 4.455172413793103, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2855024', 'n_tokens_mistral': 249, 'n_tokens_neox': 246, 'n_words': 58}