<commit_before>window.point = null;
window.traveled = 0;

var createRingBuffer = function (length){
  var pointer = 0, buffer = [], sum = 0;

  return {
    push: function (item) {
      if (buffer[pointer] > 0) {
        sum -= buffer[pointer];
        if (sum <= 0) sum = 0;
      }
      buffer[pointer] = item;
      sum += item;
      pointer = (length + pointer + 1) % length;
    },
    sum: function () {
      return sum;
    }
  };
};

var revs = 0;
$(document).bind('keydown.space', function () {
  revs += 1;

  var dist = localStorage['multiplier'] * c();
  Session.set('distance', Session.get('distance') + dist);
  window.traveled += dist;

  if (window.traveled >= window.point.distance) {
    var next = Points.findOne({_id: window.point.next});

    // Go to next point, if one exists
    if (next) {
      window.traveled -= next.distance;

      maps.travel(next._id, {route: true});
      window.point = next;
    }
  }
});

function speedo() {
  speed_buffer.push(revs * c());
  revs = 0;

  Session.set('speed', speed_buffer.sum() / 5);
}

setInterval(speedo, 500);

// 5sec, 2 values / sec.
var speed_buffer = createRingBuffer(5 * 2);
var speed_sum = 0;
var speed_avg = 0;

Template.sim.speed = function () {
  return Session.get('speed');
};

Template.sim.distance = function () {
  return Session.get('distance');
};

Template.sim.helpers({
  kmh: function (ms) {
    return (ms * 60 * 60 / 1000).toFixed(1);
  },
  km: function (m) {<commit_msg>sdfsdf<commit_after>window.point = null;
window.traveled = 0;

var createRingBuffer = function (length){
  var pointer = 0, buffer = [], sum = 0;

  return {
    push: function (item) {
      if (buffer[pointer] > 0) {
        sum -= buffer[pointer];
        if (sum <= 0) sum = 0;
      }
      buffer[pointer] = item;
      sum += item;
      pointer = (length + pointer + 1) % length;
    },
    sum: function () {
      return sum;
    }
  };
};

var revs = 0;
$(document).bind('keydown.space', function () {
  revs += 1;

  var dist = localStorage['multiplier'] * c();
  Session.set('distance', Session.get('distance') + dist);
  window.traveled += dist;

  if (window.traveled >= window.point.distance) {
    var next = Points.findOne({_id: window.point.next});

    // Go to next point, if one exists
    if (next) {
      window.traveled -= next.distance;

      maps.travel(next._id, {route: true});
      window.point = next;
    }
  }
});

// function speedo() {
//   speed_buffer.push(revs * c());
//   revs = 0;

//   Session.set('speed', speed_buffer.sum() / 5);
// }

// setInterval(speedo, 500);

// 5sec, 2 values / sec.
var speed_buffer = createRingBuffer(5 * 2);
var speed_sum = 0;
var speed_avg = 0;

Template.sim.speed = function () {
  return Session.get('speed');
};

Template.sim.distance = function () {
  return Session.get('distance');
};

Template.sim.helpers({
  kmh: function (ms) {
    return (ms * 60 * 60 / 1000).toFixed(1);
  },
  km: function (m) {
{'fraction_non_alphanumeric': 0.1746192893401015, 'fraction_numerical': 0.019627749576988155, 'mean_word_length': 2.718238993710692, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '5242129', 'n_tokens_mistral': 1085, 'n_tokens_neox': 1011, 'n_words': 250}