<commit_before>EventStats = new Mongo.Collection('eventStats');

Meteor.methods({
  updateEventStats: function () {
    console.log("Aggregating jobs...");
    //FIXME after upgrade to Mongo 2.6
    var results = Events.aggregate( [
      { $match: {} },
      { 
        $group: {
          _id: "$jobId",
          max: {$max: "$responseTime"},
          avg: {$avg: "$responseTime"},
          count: {$sum: 1},
          min: {$min: "$responseTime"}
        }
      },
      { $out: "eventStats" }
    ]);
    console.log("Aggregating jobs done !");

    // EventStats.remove({});
    // results.forEach(function(element, index, array) {
    //   EventStats.insert(element);
    // });
  }
});<commit_msg>Implemented mongoDB aggregation.<commit_after>EventStats = new Mongo.Collection('eventStats');

Meteor.methods({
  updateEventStats: function () {
    var results = Events.aggregate( [
      { $match: {} },
      { 
        $group: {
          _id: "$jobId",
          max: {$max: "$responseTime"},
          avg: {$avg: "$responseTime"},
          count: {$sum: 1},
          min: {$min: "$responseTime"}
        }
      },
      { $out: "eventStats" }
    ]);
  }
});
{'fraction_non_alphanumeric': 0.18505942275042445, 'fraction_numerical': 0.003395585738539898, 'mean_word_length': 2.127320954907162, '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': '7633281', 'n_tokens_mistral': 375, 'n_tokens_neox': 360, 'n_words': 72}