<commit_before>var robohornet = {};

/**
 * Class representing a the RoboHornet test runner.
 *
 * @param {string} version String describing this version of the benchmark.
 * @param {Array.<Object>} benchmarkDetails Array of benchmark json objects.
 * @constructor
 */
robohornet.Runner = function(version, benchmarkDetails) {
  this.version = version;
  this.testFrame = document.getElementById('testFrame');
  this.testsContainer = document.getElementById('tests');
  this.statusElement_ = document.getElementById('status');
  this.runElement_ = document.getElementById('runButton');
  this.progressElement_ = document.getElementById('progress');
  this.indexElement_ = document.getElementById('index');
  var ele = document.getElementById('index-prefix');
  if (ele) ele.innerHTML = version + ":";
  var benchmark;
  var benchmarks = [];
  var benchmarksMap = {};
  for (var details, i = 0; details = benchmarkDetails[i]; i++) {
    benchmark = new robohornet.Benchmark(this, details);
    benchmarks.push(benchmark);
    benchmarksMap[benchmark.id] = benchmark;
  }
  this.benchmarks_ = benchmarks;
  this.benchmarksMap_ = benchmarksMap;
  this.currentIndex_ = -1;
  this.overallIndex_ = 0;
  this.benchmarkCount_ = 0;
  this.benchmarksRun_ = 0;
  this.benchmarksFailed_ = 0;
  this.nextProgressLocation_ = 0;
  this.progressLocation_ = 0;
};

(function() {
  var _p = robohornet.Runner.prototype;

  _p.init = function() {
    var totalWeight = 0;
    for (var benchmark, i = 0; benchmark = this.benchmarks_[i]; i++) {
      totalWeight += benchmark.weight;
    }
    for (var benchmark, i = 0; benchmark = this.benchmarks_[i]; i++) {
      benchmark.computedWeight = (benchmark.weight / totalWeight) * 100;
      benchmark.index = i;
      benchmark.register();
    }
    this.benchmarkCount_ = this.benchmarks_.length;
    this.digestHash_();
    this.runElement_.disabled = false;
    this.setRunStatus_(true);
  };

  _p.run = function() {
    this.currentIndex_ = -1;
    this.overallIndex_ = 0;
    this.setRunStatus_(false);
    this.setStatusMessage_('Please wait while the benchmark runs. For best results, close all other programs and pages while the test is running.', false);
    this.progressElement_.style.opacity = "0.1";
    for (var benchmark, i = 0; benchmark = this.benchmarks_[i]; i++) {
      var identifier = 'benchmark-' + benchmark.index;
      document.getElementById(identifier + '-toggle').disabled = true;
      benchmark.setStatus_('Waiting...');
    }
    this.benchmarksRun_ = 0;
    this.benchmarksFailed_ = 0;
    this.setProgressLocation_(0);
    this.nextProgressLocation_ = 0;
    this.next_();
  };

  _p.benchmarkSucceeded = function() {
    this.benchmarksRun_++;
    this.next_();
  }

  _p.benchmarkSkipped = function(failed) {
    if (failed)
      this.benchmarksFailed_++;
    this.next_();
  }

  _p.next_ = function() {
    this.currentIndex_++;
    this.setProgressLocation_(this.nextProgressLocation_);
    this.nextProgressLocation_ = ((this.currentIndex_ + 1) / this.benchmarkCount_) * 100;
    if (this.nextProgressLocation_ > 100) this.nextProgressLocation_ = 100;
    if (this.currentIndex_ < this.benchmarks_.length) {
       this.benchmarks_[this.currentIndex_].load();
    } else
      this.done_();
  };

  _p.setProgressLocation_ = function(location) {
    this.progressLocation_ = location;
    this.progressElement_.style.marginLeft = "-" + (100 - this.progressLocation_).toString() + "%";
  }

  _p.incrementOverallIndex = function(index) {
    this.overallIndex_ += index;
    this.setIndex_(this.overallIndex_, false);
  }

  _p.done_ = function() {
    this.testFrame.src = 'javascript:void(0)';
    if (this.benchmarksRun_ == this.benchmarkCount_) {
      this.setIndex_(this.overallIndex_, true);
      this.setStatusMessage_("The RoboHornet index is normalized to 100 and roughly shows your browser's performance compared to other modern browsers. <a target='_blank' href='http://code.google.com/p/robohornet/wiki/BenchmarkScoring'>Learn more</a>.");
    } else if (this.benchmarksFailed_ == this.benchmarkCount_) {
      this.setStatusMessage_('Test failed', false);
      alert('To run RoboHornet locally you need to run Chrome with the --allow-file-access-from-files flag.');
    } else {
      this.setStatusMessage_('Enable all tests to see the index. Ran ' + this.benchmarksRun_ + ' out of ' + this.benchmarkCount_ + ' benchmarks.');
    }
    this.runElement_.disabled = false;
    for (var benchmark, i = 0; benchmark = this.benchmarks_[i]; i++) {
      var identifier = 'benchmark-' + benchmark.index;
      document.getElementById(identifier + '-toggle').disabled = false;
    }
    this.setRunStatus_(true);
  };
  
  _p.progressTransitionDone_ = function() {
    this.progressElement_.style.opacity = '0.0';
    this.progressElement_.style.marginLeft = "-100%";
  }

  _p.setRunStatus_ = function(enabled) {
    this.runElement_.textContent = enabled ? 'Run' : 'Running...';
    this.runElement_.disabled = !enabled;
    document.body.className = enabled ? 'ready' : 'running';
  };

  _p.setIndex_ = function(index, final) {
    //Ensure that we have 4 digits in front of the dot and 2 after.
    var parts = (Math.round(index * 100) / 100).toString().split('.');
    if (parts.length < 2) parts.push('00');
    while (!final && parts[0].length < 3) {
      parts[0] = "0" + parts[0];
    }
    while (parts[1].length < 2) {
      parts[1] = parts[1] + "0";
    }
    /* In Chrome Canary (18.0.1005.0) if we put in a string that starts with the 
     * same prefix then the DOM gets updated (as seen in Web Inspector) but it
     * doesn't update in the layout for some reason. If this ceases to be a<commit_msg>Fixed a mistake in the last commit where the progress bar wouldn't actually fade out.<commit_after>var robohornet = {};

/**
 * Class representing a the RoboHornet test runner.
 *
 * @param {string} version String describing this version of the benchmark.
 * @param {Array.<Object>} benchmarkDetails Array of benchmark json objects.
 * @constructor
 */
robohornet.Runner = function(version, benchmarkDetails) {
  this.version = version;
  this.testFrame = document.getElementById('testFrame');
  this.testsContainer = document.getElementById('tests');
  this.statusElement_ = document.getElementById('status');
  this.runElement_ = document.getElementById('runButton');
  this.progressElement_ = document.getElementById('progress');
  this.indexElement_ = document.getElementById('index');
  var ele = document.getElementById('index-prefix');
  if (ele) ele.innerHTML = version + ":";
  var benchmark;
  var benchmarks = [];
  var benchmarksMap = {};
  for (var details, i = 0; details = benchmarkDetails[i]; i++) {
    benchmark = new robohornet.Benchmark(this, details);
    benchmarks.push(benchmark);
    benchmarksMap[benchmark.id] = benchmark;
  }
  this.benchmarks_ = benchmarks;
  this.benchmarksMap_ = benchmarksMap;
  this.currentIndex_ = -1;
  this.overallIndex_ = 0;
  this.benchmarkCount_ = 0;
  this.benchmarksRun_ = 0;
  this.benchmarksFailed_ = 0;
  this.nextProgressLocation_ = 0;
  this.progressLocation_ = 0;
  this.progressCallback_ = bind(this.progressTransitionDone_, this);
};

(function() {
  var _p = robohornet.Runner.prototype;

  _p.init = function() {
    var totalWeight = 0;
    for (var benchmark, i = 0; benchmark = this.benchmarks_[i]; i++) {
      totalWeight += benchmark.weight;
    }
    for (var benchmark, i = 0; benchmark = this.benchmarks_[i]; i++) {
      benchmark.computedWeight = (benchmark.weight / totalWeight) * 100;
      benchmark.index = i;
      benchmark.register();
    }
    this.benchmarkCount_ = this.benchmarks_.length;
    this.digestHash_();
    this.runElement_.disabled = false;
    this.setRunStatus_(true);
  };

  _p.run = function() {
    this.currentIndex_ = -1;
    this.overallIndex_ = 0;
    this.setRunStatus_(false);
    this.setStatusMessage_('Please wait while the benchmark runs. For best results, close all other programs and pages while the test is running.', false);
    this.progressElement_.style.opacity = "0.1";
    for (var benchmark, i = 0; benchmark = this.benchmarks_[i]; i++) {
      var identifier = 'benchmark-' + benchmark.index;
      document.getElementById(identifier + '-toggle').disabled = true;
      benchmark.setStatus_('Waiting...');
    }
    this.benchmarksRun_ = 0;
    this.benchmarksFailed_ = 0;
    this.setProgressLocation_(0);
    this.nextProgressLocation_ = 0;
    this.next_();
  };

  _p.benchmarkSucceeded = function() {
    this.benchmarksRun_++;
    this.next_();
  }

  _p.benchmarkSkipped = function(failed) {
    if (failed)
      this.benchmarksFailed_++;
    this.next_();
  }

  _p.next_ = function() {
    this.currentIndex_++;
    this.setProgressLocation_(this.nextProgressLocation_);
    this.nextProgressLocation_ = ((this.currentIndex_ + 1) / this.benchmarkCount_) * 100;
    if (this.nextProgressLocation_ > 100) this.nextProgressLocation_ = 100;
    if (this.currentIndex_ < this.benchmarks_.length) {
       this.benchmarks_[this.currentIndex_].load();
    } else
      this.done_();
  };

  _p.setProgressLocation_ = function(location) {
    this.progressLocation_ = location;
    this.progressElement_.style.marginLeft = "-" + (100 - this.progressLocation_).toString() + "%";
  }

  _p.incrementOverallIndex = function(index) {
    this.overallIndex_ += index;
    this.setIndex_(this.overallIndex_, false);
  }

  _p.done_ = function() {
    this.testFrame.src = 'javascript:void(0)';
    this.progressElement_.addEventListener("webkitTransitionEnd", this.progressCallback_, false);
    this.progressElement_.style.opacity = '0.0';
    if (this.benchmarksRun_ == this.benchmarkCount_) {
      this.setIndex_(this.overallIndex_, true);
      this.setStatusMessage_("The RoboHornet index is normalized to 100 and roughly shows your browser's performance compared to other modern browsers. <a target='_blank' href='http://code.google.com/p/robohornet/wiki/BenchmarkScoring'>Learn more</a>.");
    } else if (this.benchmarksFailed_ == this.benchmarkCount_) {
      this.setStatusMessage_('Test failed', false);
      alert('To run RoboHornet locally you need to run Chrome with the --allow-file-access-from-files flag.');
    } else {
      this.setStatusMessage_('Enable all tests to see the index. Ran ' + this.benchmarksRun_ + ' out of ' + this.benchmarkCount_ + ' benchmarks.');
    }
    this.runElement_.disabled = false;
    for (var benchmark, i = 0; benchmark = this.benchmarks_[i]; i++) {
      var identifier = 'benchmark-' + benchmark.index;
      document.getElementById(identifier + '-toggle').disabled = false;
    }
    this.setRunStatus_(true);
  };
  
  _p.progressTransitionDone_ = function() {
    //Wait until the progress bar fades out to put it back to the left.
    this.progressElement_.style.marginLeft = "-100%";
    this.progressElement_.removeEventListener("webkitTransitionEnd", this.progressCallback_, false);
  }

  _p.setRunStatus_ = function(enabled) {
    this.runElement_.textContent = enabled ? 'Run' : 'Running...';
    this.runElement_.disabled = !enabled;
    document.body.className = enabled ? 'ready' : 'running';
  };

  _p.setIndex_ = function(index, final) {
    //Ensure that we have 4 digits in front of the dot and 2 after.
    var parts = (Math.round(index * 100) / 100).toString().split('.');
    if (parts.length < 2) parts.push('00');
    while (!final && parts[0].length < 3) {
      parts[0] = "0" + parts[0];
    }
    while (parts[1].length < 2) {
      parts[1] = parts[1] + "0";
    }
    /* In Chrome Canary (18.0.1005.0) if we put in a string that starts with the 
     * same prefix then the DOM gets updated (as seen in Web Inspector) but it
     * doesn't update in the layout for some reason. If this ceases to be a
{'fraction_non_alphanumeric': 0.13230560731831273, 'fraction_numerical': 0.012705404031848213, 'mean_word_length': 3.571041424699961, 'pattern_counts': {'":': 2, '<': 17, '<?xml version=': 0, '>': 11, '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': '2302067', 'n_tokens_mistral': 3777, 'n_tokens_neox': 3585, 'n_words': 856}