<commit_before>/*
 * aggregate.js: Module that will aggregate Metrics and emit stats
 *
 * (C) 2012, Nodejitsu Inc.
 *
 */

var constants = require('../../config/constants'),
    common = require('../csock/common');

exports.meta = {
  name: 'aggregate',
  title: 'Aggregate Metrics'
};

exports.outbound = function outbound() {

  var metrics = this.metrics;

  metrics.socket.on('metrics::available', function(data) {
    var aggregated = {};

    Object.keys(data).forEach(function(containerName) {

      var container = data[containerName];

      Object.keys(container).forEach(function(key) {

        var value = container[key];
        value = value.mean || value.precision;

        if (key.indexOf('-aggregate') < 0) {
          var aggregatedKey = key + '-aggregate';
          if (! aggregated[aggregatedKey]) {
            aggregated[aggregatedKey] = [];
          }
          aggregated[aggregatedKey].push(value);
        }
      });
    });

    //
    // Emit the aggregated means
    //

    Object.keys(aggregated).forEach(function(key) {
      var pop = aggregated[key].length;

      var sum = aggregated[key].reduce(function(sum, mean) {
        return sum + mean;
      }, 0);

      var average = sum / pop;
      var metric = {
        key: key,
        precision: average,
        average: false
      };

      metrics.observe(metric);

    });

  });

};

<commit_msg>[refactor] Bankruptcy for old aggreate implementation in `nodejitsu/orchestrion`<commit_after>/*
 * aggregate.js: Module that will aggregate Metrics and emit stats
 *
 * (C) 2012, Nodejitsu Inc.
 *
 */


{'fraction_non_alphanumeric': 0.141875, 'fraction_numerical': 0.00625, 'mean_word_length': 2.4578833693304536, 'pattern_counts': {'":': 0, '<': 4, '<?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': '219908', 'n_tokens_mistral': 508, 'n_tokens_neox': 464, 'n_words': 107}