<commit_before>/**!
 *
 * Copyright (c) 2015-2017 Cisco Systems, Inc. See LICENSE file.
 * @private
 */

import {Interceptor} from '@ciscospark/http-core';

const sequenceNumbers = new WeakMap();

/**
 * @class
 */
export default class SparkTrackingIdInterceptor extends Interceptor {
  /**
   * Sequence number; increments on access
   * @type {Number}
   */
  get sequence() {
    let sq = sequenceNumbers.get(this) || 0;
    sq += 1;
    sequenceNumbers.set(this, sq);
    return sq;
  }

  /**
   * @returns {SparkTrackingIdInterceptor}
   */
  static create() {
    return new SparkTrackingIdInterceptor({spark: this});
  }

  /**
   * @see Interceptor#onRequest
   * @param {Object} options
   * @returns {Object}
   */
  onRequest(options) {
    options.headers = options.headers || {};
    if (this.requiresTrackingId(options)) {
      options.headers.trackingid = `${this.spark.sessionId}_${this.sequence}`;
    }
    return options;
  }

  /**
   * Determines whether or not include a tracking id
   * @param {Object} options
   * @returns {boolean}
   */
  requiresTrackingId(options) {
    return !options.headers.trackingid;
  }
}
<commit_msg>feat(spark-core): include replayCount in tracking id<commit_after>/**!
 *
 * Copyright (c) 2015-2017 Cisco Systems, Inc. See LICENSE file.
 * @private
 */

import {Interceptor} from '@ciscospark/http-core';

const sequenceNumbers = new WeakMap();

/**
 * @class
 */
export default class SparkTrackingIdInterceptor extends Interceptor {
  /**
   * Sequence number; increments on access
   * @type {Number}
   */
  get sequence() {
    let sq = sequenceNumbers.get(this) || 0;
    sq += 1;
    sequenceNumbers.set(this, sq);
    return sq;
  }

  /**
   * @returns {SparkTrackingIdInterceptor}
   */
  static create() {
    return new SparkTrackingIdInterceptor({spark: this});
  }

  /**
   * @see Interceptor#onRequest
   * @param {Object} options
   * @returns {Object}
   */
  onRequest(options) {
    options.headers = options.headers || {};
    if (this.requiresTrackingId(options)) {
      options.headers.trackingid = `${this.spark.sessionId}_${this.sequence}`;
    }

    if (options.headers.trackingid && options.replayCount) {
      const tid = options.headers.trackingid.split(`+`);
      tid[1] = options.replayCount;
      options.headers.trackingid = tid.join(`+`);
    }

    return options;
  }

  /**
   * Determines whether or not include a tracking id
   * @param {Object} options
   * @returns {boolean}
   */
  requiresTrackingId(options) {
    return !options.headers.trackingid;
  }
}

{'fraction_non_alphanumeric': 0.14202106905969566, 'fraction_numerical': 0.008193523214982443, 'mean_word_length': 3.1421647819063003, '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': '5041580', 'n_tokens_mistral': 862, 'n_tokens_neox': 806, 'n_words': 185}