<commit_before>'use strict';

const forEach = require('lodash.foreach'),
  statsHelpers = require('../../support/statsHelpers');

const timings = ['firstPaint', 'rumSpeedIndex', 'timeToDomContentFlushed'];

module.exports = {
  statsPerType: {},
  groups: {},

  addToAggregate(browsertimeRunData, group) {
    if (this.groups[group] === undefined) {
      this.groups[group] = {};
    }

    if (browsertimeRunData.fullyLoaded) {
      statsHelpers.pushGroupStats(
        this.statsPerType,
        this.groups[group],
        ['timings', 'fullyLoaded'],
        browsertimeRunData.fullyLoaded
      );
    }

    forEach(timings, timing => {
      if (browsertimeRunData.timings[timing]) {
        statsHelpers.pushGroupStats(
          this.statsPerType,
          this.groups[group],
          timing,
          browsertimeRunData.timings[timing]
        );
      }
    });

    forEach(browsertimeRunData.timings.navigationTiming, (value, name) => {
      statsHelpers.pushGroupStats(
        this.statsPerType,
        this.groups[group],
        ['navigationTiming', name],
        value
      );
    });

    // pick up one level of custom metrics
    forEach(browsertimeRunData.custom, (value, name) => {
      statsHelpers.pushGroupStats(
        this.statsPerType,
        this.groups[group],
        ['custom', name],
        value
      );
    });

    forEach(browsertimeRunData.timings.pageTimings, (value, name) => {
      statsHelpers.pushGroupStats(
        this.statsPerType,
        this.groups[group],
        ['pageTimings', name],
        value
      );
    });

    forEach(browsertimeRunData.timings.paintTiming, (value, name) => {
      statsHelpers.pushGroupStats(
        this.statsPerType,
        this.groups[group],
        ['paintTiming', name],
        value
      );
    });

    forEach(browsertimeRunData.timings.userTimings.marks, timing => {
      statsHelpers.pushGroupStats(
        this.statsPerType,
        this.groups[group],
        ['userTimings', 'marks', timing.name],
        timing.startTime
      );
    });

    forEach(browsertimeRunData.timings.userTimings.measures, timing => {
      statsHelpers.pushGroupStats(
        this.statsPerType,
        this.groups[group],
        ['userTimings', 'measures', timing.name],
        timing.duration
      );
    });

    forEach(browsertimeRunData.visualMetrics, (value, name) => {
      // Sometimes visual elements fails and gives us null values
      if (name !== 'VisualProgress' && value !== null) {
        statsHelpers.pushGroupStats(
          this.statsPerType,
          this.groups[group],
          ['visualMetrics', name],
          value
        );
      }
    });

    if (browsertimeRunData.cpu) {
      if (browsertimeRunData.cpu.longTasks) {
        statsHelpers.pushGroupStats(
          this.statsPerType,
          this.groups[group],
          ['cpu', 'longTasks', 'tasks'],
          browsertimeRunData.cpu.longTasks.tasks
        );

        statsHelpers.pushGroupStats(
          this.statsPerType,
          this.groups[group],<commit_msg>Skip collecting stats about progress<commit_after>'use strict';

const forEach = require('lodash.foreach'),
  statsHelpers = require('../../support/statsHelpers');

const timings = ['firstPaint', 'rumSpeedIndex', 'timeToDomContentFlushed'];

module.exports = {
  statsPerType: {},
  groups: {},

  addToAggregate(browsertimeRunData, group) {
    if (this.groups[group] === undefined) {
      this.groups[group] = {};
    }

    if (browsertimeRunData.fullyLoaded) {
      statsHelpers.pushGroupStats(
        this.statsPerType,
        this.groups[group],
        ['timings', 'fullyLoaded'],
        browsertimeRunData.fullyLoaded
      );
    }

    forEach(timings, timing => {
      if (browsertimeRunData.timings[timing]) {
        statsHelpers.pushGroupStats(
          this.statsPerType,
          this.groups[group],
          timing,
          browsertimeRunData.timings[timing]
        );
      }
    });

    forEach(browsertimeRunData.timings.navigationTiming, (value, name) => {
      statsHelpers.pushGroupStats(
        this.statsPerType,
        this.groups[group],
        ['navigationTiming', name],
        value
      );
    });

    // pick up one level of custom metrics
    forEach(browsertimeRunData.custom, (value, name) => {
      statsHelpers.pushGroupStats(
        this.statsPerType,
        this.groups[group],
        ['custom', name],
        value
      );
    });

    forEach(browsertimeRunData.timings.pageTimings, (value, name) => {
      statsHelpers.pushGroupStats(
        this.statsPerType,
        this.groups[group],
        ['pageTimings', name],
        value
      );
    });

    forEach(browsertimeRunData.timings.paintTiming, (value, name) => {
      statsHelpers.pushGroupStats(
        this.statsPerType,
        this.groups[group],
        ['paintTiming', name],
        value
      );
    });

    forEach(browsertimeRunData.timings.userTimings.marks, timing => {
      statsHelpers.pushGroupStats(
        this.statsPerType,
        this.groups[group],
        ['userTimings', 'marks', timing.name],
        timing.startTime
      );
    });

    forEach(browsertimeRunData.timings.userTimings.measures, timing => {
      statsHelpers.pushGroupStats(
        this.statsPerType,
        this.groups[group],
        ['userTimings', 'measures', timing.name],
        timing.duration
      );
    });

    forEach(browsertimeRunData.visualMetrics, (value, name) => {
      // Sometimes visual elements fails and gives us null values
      // And skip VisualProgress, ContentfulSpeedIndexProgress and others
      if (name.indexOf('Progress') === -1 && value !== null) {
        statsHelpers.pushGroupStats(
          this.statsPerType,
          this.groups[group],
          ['visualMetrics', name],
          value
        );
      }
    });

    if (browsertimeRunData.cpu) {
      if (browsertimeRunData.cpu.longTasks) {
        statsHelpers.pushGroupStats(
          this.statsPerType,
          this.groups[group],
          ['cpu', 'longTasks', 'tasks'],
          browsertimeRunData.cpu.longTasks.tasks
        );

        statsHelpers.pushGroupStats(
          this.statsPerType,
          this.groups[group],
{'fraction_non_alphanumeric': 0.12598298828438453, 'fraction_numerical': 0.00016048788316482104, 'mean_word_length': 2.318423855165069, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '1441570', 'n_tokens_mistral': 1867, 'n_tokens_neox': 1856, 'n_words': 281}