<commit_before>// sensorData.js
// retrieving acceleration data
window.onload = function() {
  console.log("loaded");
  var xA = document.getElementById("xA"),
    xV = document.getElementById("xV");
    xP = document.getElementById("xP");

  var lastVelocity = false,
    lastPosition = 0,
    timeStep,
    lastT = new Date();


  function velocity (lastVelocity, acceleration, timeStep) {
    return lastVelocity + (acceleration * timeStep);
  }

  function position (lastPosition, lastVelocity, acceleration, timeStep) {
    return lastPosition + lastVelocity * timeStep +
    (0.5 * acceleration * timeStep * timeStep);
  }


  // initialize gyro from gyro.js
  function initGyro() {
    var listYAccelerations = [],
      noise = false,
      lastXA = false;

    gyro.frequency = 100;

    gyro.startTracking(function(o) {
      var a = o.x.toFixed(3),
        t = new Date(),
        timestep = t - lastT;

      if (parseFloat(a) <= 0.1 || parseFloat(a) >= -0.1) {
        a = 0;
      }
      
      lastT = t;
      lastPosition = position(lastPosition, lastVelocity, a,
        timestep);

      lastVelocity = velocity(lastVelocity, a, timestep);

      xA.innerHTML = a;
      xV.innerHTML = lastVelocity;
      xP.innerHTML = lastPosition;
    });
  }

  initGyro();<commit_msg>setting velocity to zero when acceleration is noise<commit_after>// sensorData.js
// retrieving acceleration data
window.onload = function() {
  console.log("loaded");
  var xA = document.getElementById("xA"),
    xV = document.getElementById("xV");
    xP = document.getElementById("xP");

  var lastVelocity = false,
    lastPosition = 0,
    timeStep,
    lastT = new Date();


  function velocity (lastVelocity, acceleration, timeStep) {
    return lastVelocity + (acceleration * timeStep);
  }

  function position (lastPosition, lastVelocity, acceleration, timeStep) {
    return lastPosition + lastVelocity * timeStep +
    (0.5 * acceleration * timeStep * timeStep);
  }


  // initialize gyro from gyro.js
  function initGyro() {
    var listYAccelerations = [],
      noise = false,
      lastXA = false;

    gyro.frequency = 100;

    gyro.startTracking(function(o) {
      var a = o.x.toFixed(3),
        t = new Date(),
        timestep = t - lastT;

      if (parseFloat(a) <= 0.1 || parseFloat(a) >= -0.1) {
        a = 0;
        lastVelocity = 0;
      }

      lastT = t;
      lastPosition = position(lastPosition, lastVelocity, a,
        timestep);

      lastVelocity = velocity(lastVelocity, a, timestep);

      xA.innerHTML = a;
      xV.innerHTML = lastVelocity;
      xP.innerHTML = lastPosition;
    });
  }

  initGyro();
{'fraction_non_alphanumeric': 0.12329803328290469, 'fraction_numerical': 0.009455370650529501, 'mean_word_length': 2.6685159500693483, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4006479', 'n_tokens_mistral': 881, 'n_tokens_neox': 819, 'n_words': 200}