<commit_before>const EventEmitter = require('events').EventEmitter;
const PassThrough  = require('stream').PassThrough;
const Speedometer  = require('./speedometer');


module.exports = class StreamSpeed extends EventEmitter {
  /**
   * Emits speed for a group of streams.
   *
   * @constructor
   * @extends {EventEmitter}
   * @param {number?} per The time unit speed will be measured in.
   */
  constructor(per) {
    super();
    this.per = per || 1000;
    this._streams = [];
    this.speed = 0;
    this.avg = 0;
  }


  /**
   * Updates the group with the latest change in speed.
   *
   * @param {Object} meta
   * @param {number} speed
   * @param {number} avg
   */
  _update(meta, speed, avg) {
    meta.speed = speed;
    meta.avg = avg;

    this._streams.forEach((m) => {
      // Skip own stream, streams that haven't started,
      // and streams that are paused.
      if (m === meta || m.speed === 0 || m.stream.paused) {
        return;
      }

      // Add other streams' speeds to total.
      speed += m.speed;
      avg += m.avg;
    });

    this.speed = speed;
    this.avg = avg;
    this.emit('speed', speed, avg);
  }


  /**
   * Convenient method that returns list of streams in this group.<commit_msg>test: fix for node v13<commit_after>const EventEmitter = require('events').EventEmitter;
const PassThrough  = require('stream').PassThrough;
const Speedometer  = require('./speedometer');


module.exports = class StreamSpeed extends EventEmitter {
  /**
   * Emits speed for a group of streams.
   *
   * @constructor
   * @extends {EventEmitter}
   * @param {number?} per The time unit speed will be measured in.
   */
  constructor(per) {
    super();
    this.per = per || 1000;
    this._streams = [];
    this.speed = 0;
    this.avg = 0;
  }


  /**
   * Updates the group with the latest change in speed.
   *
   * @param {Object} meta
   * @param {number} speed
   * @param {number} avg
   */
  _update(meta, speed, avg) {
    meta.speed = speed;
    meta.avg = avg;

    this._streams.forEach((m) => {
      // Skip own stream, streams that haven't started,
      // and streams that are paused.
      if (m === meta || m.speed === 0) {
        return;
      }

      // Add other streams' speeds to total.
      speed += m.speed;
      avg += m.avg;
    });

    this.speed = speed;
    this.avg = avg;
    this.emit('speed', speed, avg);
  }


  /**
   * Convenient method that returns list of streams in this group.
{'fraction_non_alphanumeric': 0.13758116883116883, 'fraction_numerical': 0.006493506493506494, 'mean_word_length': 2.372093023255814, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '705963', 'n_tokens_mistral': 811, 'n_tokens_neox': 782, 'n_words': 236}