<commit_before>var Session = (function() {
  'use strict';

  var solves = [];

  function reset() {
    solves = [];
  }

  function add(solve) {
    solves.push(solve);
  }

  function length() {
    return solves.length;
  }

  function remove(index) {
    index = index || solves.length - 1;
    solves.splice(index, 1);
  }

  function at(index) {
    return solves[index];
  }

  function toggle_dnf(index) {}

  function toggle_plus2(index) {}

  function get_trim(size) {
    return Math.ceil(size / 20);
  }

  function solve_sort(a, b) {
    return a.time - b.time;
  }

  function average(start, length) {
    start = start || 0;
    length = length || solves.length;

    if (length < 3) return -1;
    if (solves.length < length) return -1;

    var end = start + length;
    var trim = get_trim(length);

    var copy = solves.slice(start, end);
    copy.sort(solve_sort);
    copy.splice(0, trim);
    copy.splice(copy.length - trim, trim);

    var sum = 0;
    for (var i = 0; i < copy.length; ++i) {
      sum += copy[i].time;
    }
    return sum / (length - (2 * trim));
  }

  function current_average(length) {
    return average(solves.length - length, length);
  }

  return {
    reset: reset,
    add: add,
    remove: remove,
    at: at,
    length: length,
    toggle_dnf: toggle_dnf,
    toggle_plus2: toggle_plus2,
    average: average,
    current_average: current_average
  };
});

if (typeof module !== 'undefined')
  module.exports = Session;<commit_msg>Add a naive best_average(length) function.<commit_after>var Session = (function() {
  'use strict';

  var solves = [];

  function reset() {
    solves = [];
  }

  function add(solve) {
    solves.push(solve);
  }

  function length() {
    return solves.length;
  }

  function remove(index) {
    index = index || solves.length - 1;
    solves.splice(index, 1);
  }

  function at(index) {
    return solves[index];
  }

  function toggle_dnf(index) {}

  function toggle_plus2(index) {}

  function get_trim(size) {
    return Math.ceil(size / 20);
  }

  function solve_sort(a, b) {
    return a.time - b.time;
  }

  function average(start, length) {
    start = start || 0;
    length = length || solves.length;

    if (length < 3) return -1;
    if (solves.length < length) return -1;

    var end = start + length;
    var trim = get_trim(length);

    var copy = solves.slice(start, end);
    copy.sort(solve_sort);
    copy.splice(0, trim);
    copy.splice(copy.length - trim, trim);

    var sum = 0;
    for (var i = 0; i < copy.length; ++i) {
      sum += copy[i].time;
    }
    return sum / (length - (2 * trim));
  }

  function current_average(length) {
    return average(solves.length - length, length);
  }

  function best_average(length) {
    var bestIndex = -1, bestAvg = -1;
    for(var index = 0; solves.length >= index + length; index += 1) {
      var avg = average(index, length);
      if (avg < bestAvg || bestAvg == -1) {
        bestAvg = avg;
        bestIndex = index;
      }
    }
    return bestAvg;
  }

  return {
    reset: reset,
    add: add,
    remove: remove,
    at: at,
    length: length,
    toggle_dnf: toggle_dnf,
    toggle_plus2: toggle_plus2,
    average: average,
    current_average: current_average,
    best_average: best_average
  };
});

if (typeof module !== 'undefined')
  module.exports = Session;
{'fraction_non_alphanumeric': 0.13902147971360382, 'fraction_numerical': 0.010441527446300716, 'mean_word_length': 2.5481481481481483, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 4, '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': '6109242', 'n_tokens_mistral': 1223, 'n_tokens_neox': 1144, 'n_words': 291}