<commit_before>var SamplesRestorer = mkClass({
  initialize: function (url, options) {
    this.birthTime = (new Date()).valueOf();
    this.url = url;
    this.options = options;
    this.valueTransformer = $m(this, 'transformData');
  },
  getRequestData: function () {
    var data = _.extend({}, this.options);
    _.each(data.nonQ, function (n) {
      delete data[n];
    });
    if (this.prevTimestamp !== undefined)
      data['haveTStamp'] = this.prevTimestamp;
    return data;
  },
  transformData: function (value) {
    var op = value.op;
    var samples = op.samples;
    this.samplesInterval = op.interval;
    this.prevTimestamp = op.lastTStamp;

    if (!op.tstampParam) {
      this.prevSamples = samples;
      return value;
    }

    var prevSamples = this.prevSamples;
    var newSamples = {};

    for (var keyName in samples) {
      newSamples[keyName] = prevSamples[keyName].concat(samples[keyName].slice(1)).slice(-60);
    }

    this.prevSamples = op.samples = newSamples;

    return value;
  },
  nextSampleTime: function () {
    var now = (new Date()).valueOf();
    if (this.samplesInterval === undefined)
      return now;
    if (this.samplesInterval < 2000)
      return now;
    return now + Math.min(this.samplesInterval/2, 60000);
  }
});

;(function () {
  var statsBucketURL = this.statsBucketURL = new StringHashFragmentCell("statsBucket");

  var targetCell = this.currentStatTargetCell = new Cell(function (poolDetails, mode) {
    if (mode != 'analytics')
      return;

    if (!this.bucketURL)
      return poolDetails;

    var bucket = BucketsSection.findBucket(this.bucketURL);
    if (bucket)
      return bucket;
    return future.get({url: this.bucketURL});
  }).setSources({bucketURL: statsBucketURL,
                 poolDetails: this.currentPoolDetailsCell,
                 mode: this.mode});

  var StatsArgsCell = new Cell(function (target) {
    return {url: target.stats.uri};
  }).setSources({target: targetCell});

  var statsOptionsCell = new Cell();
  statsOptionsCell.setValue({nonQ: ['keysInterval', 'nonQ'], resampleForUI: '1'});
  _.extend(statsOptionsCell, {
    update: function (options) {
      this.modifyValue(_.bind($.extend, $, {}), options);
    },
    equality: _.isEqual
  });

  var samplesRestorerCell = new Cell(function (target, options) {
    return new SamplesRestorer(target.stats.uri, options);
  }).setSources({target: targetCell, options: statsOptionsCell});

  var statsCell = new Cell(function (samplesRestorer) {
    return future.get({
      url: samplesRestorer.url,
      data: samplesRestorer.getRequestData()
    }, samplesRestorer.valueTransformer);
  }).setSources({samplesRestorer: samplesRestorerCell,
                 options: statsOptionsCell,
                 target: targetCell});
  statsCell.keepValueDuringAsync = true;

  statsCell.setRecalculateTime = function () {
    var at = this.context.samplesRestorer.value.nextSampleTime();
    this.recalculateAt(at);<commit_msg>ignore xhr errors on analytics<commit_after>var SamplesRestorer = mkClass({
  initialize: function (url, options) {
    this.birthTime = (new Date()).valueOf();
    this.url = url;
    this.options = options;
    this.valueTransformer = $m(this, 'transformData');
  },
  getRequestData: function () {
    var data = _.extend({}, this.options);
    _.each(data.nonQ, function (n) {
      delete data[n];
    });
    if (this.prevTimestamp !== undefined)
      data['haveTStamp'] = this.prevTimestamp;
    return data;
  },
  transformData: function (value) {
    var op = value.op;
    var samples = op.samples;
    this.samplesInterval = op.interval;
    this.prevTimestamp = op.lastTStamp;

    if (!op.tstampParam) {
      this.prevSamples = samples;
      return value;
    }

    var prevSamples = this.prevSamples;
    var newSamples = {};

    for (var keyName in samples) {
      newSamples[keyName] = prevSamples[keyName].concat(samples[keyName].slice(1)).slice(-60);
    }

    this.prevSamples = op.samples = newSamples;

    return value;
  },
  nextSampleTime: function () {
    var now = (new Date()).valueOf();
    if (this.samplesInterval === undefined)
      return now;
    if (this.samplesInterval < 2000)
      return now;
    return now + Math.min(this.samplesInterval/2, 60000);
  }
});

;(function () {
  var statsBucketURL = this.statsBucketURL = new StringHashFragmentCell("statsBucket");

  var targetCell = this.currentStatTargetCell = new Cell(function (poolDetails, mode) {
    if (mode != 'analytics')
      return;

    if (!this.bucketURL)
      return poolDetails;

    var bucket = BucketsSection.findBucket(this.bucketURL);
    if (bucket)
      return bucket;
    return future.get({url: this.bucketURL});
  }).setSources({bucketURL: statsBucketURL,
                 poolDetails: this.currentPoolDetailsCell,
                 mode: this.mode});

  var StatsArgsCell = new Cell(function (target) {
    return {url: target.stats.uri};
  }).setSources({target: targetCell});

  var statsOptionsCell = new Cell();
  statsOptionsCell.setValue({nonQ: ['keysInterval', 'nonQ'], resampleForUI: '1'});
  _.extend(statsOptionsCell, {
    update: function (options) {
      this.modifyValue(_.bind($.extend, $, {}), options);
    },
    equality: _.isEqual
  });

  var samplesRestorerCell = new Cell(function (target, options) {
    return new SamplesRestorer(target.stats.uri, options);
  }).setSources({target: targetCell, options: statsOptionsCell});

  var statsCell = new Cell(function (samplesRestorer) {
    return future.get({
      url: samplesRestorer.url,
      ignoreErrors: true,
      data: samplesRestorer.getRequestData()
    }, samplesRestorer.valueTransformer);
  }).setSources({samplesRestorer: samplesRestorerCell,
                 options: statsOptionsCell,
                 target: targetCell});
  statsCell.keepValueDuringAsync = true;

  statsCell.setRecalculateTime = function () {
    var at = this.context.samplesRestorer.value.nextSampleTime();
    this.recalculateAt(at);
{'fraction_non_alphanumeric': 0.13184617945729982, 'fraction_numerical': 0.004661228566672216, 'mean_word_length': 3.3129935391241925, 'pattern_counts': {'":': 0, '<': 5, '<?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': '503624', 'n_tokens_mistral': 1835, 'n_tokens_neox': 1768, 'n_words': 395}