<commit_before>(function (global) {
  "use strict";
  var
    doc = global.document, con = global.console, dropbox, locations, current, distance, dateDiv, travelledDiv, leftDiv, rocket,
    total = 384400, km2miles = 0.621371, R = 6371, deg2rad = Math.PI / 180, cityData;

  dropbox = doc.getElementById("dropbox");
  dateDiv = doc.getElementById("date");
  travelledDiv = doc.getElementById("travelled");
  leftDiv = doc.getElementById("left");
  rocket = doc.getElementById("rocket");

  Date.prototype.niceDate = function () {
    var y, m, d;
    y = this.getFullYear().toString();
    m = (this.getMonth() + 1).toString();
    d  = this.getDate().toString();
    return y + "-" + (m[1] ? m : "0" + m[0]) + "-" + (d[1] ? d : "0" + d[0]);
  };

  Number.prototype.formatWithCommas = function () {
    return Math.round(this).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
  };

  // Haversine formula
  function distanceFromLatLng(lat1, lon1, lat2, lon2) {
    var dLat, dLon, a, c;

    dLat = (lat2 - lat1) * deg2rad / 2;
    dLon = (lon2 - lon1) * deg2rad / 2;
    lat1 = lat1 * deg2rad;
    lat2 = lat2 * deg2rad;

    a = Math.sin(dLat) * Math.sin(dLat) + Math.sin(dLon) * Math.sin(dLon) * Math.cos(lat1) * Math.cos(lat2);
    c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));

    return R * c;
  }

  function lazyDistance(lat1, lon1, lat2, lon2) {
    var dLat, dLon;
    dLat = lat2 - lat1;
    dLon = lon2 - lon1;
    if (dLat < 1 && dLat > -1 && dLon < 1 && dLon > -1) {
      // Inside of 1° we can pretty much ignore curves
      // We also only need a comparable value, so no need for Math.sqrt or converting to km
      return dLat * dLat + dLon * dLon;
    } else {
      // Too big to be considered
      return false;
    }
  }

  function citySort(a, b) {
    return (a.distance - b.distance);
  }

  function findCity(lat, lon) {
    var i, tmpCities = [], d;
    for (i = 0; i < cityData.cities.length; i++) {
      d = lazyDistance(lat, lon, cityData.cities[i].[1], cityData.cities[i].[2])
      if (d !== false) {
        tmpCities.push({"city": cityData.cities[i][0], "country": cityData.countries[cityData.cities[i][3]], "distance": d});
      }
    }
    if (tmpCities.length > 0) {
      tmpCities.sort(citySort);
      return tmpCities[0];
    } else {
      return null;
    }
  }

  function travel() {
    var location = locations[current], location1, location2, lat1, lon1, lat2, lon2, time1, time2, perc, left;

    time1 = new Date(parseInt(location.timestampMs, 10));
    time2 = new Date(parseInt(location.timestampMs, 10));

    // putting all locations of one day together
    while (current > 0 && time2.getFullYear() == time1.getFullYear() && time2.getMonth() == time1.getMonth() && time2.getDate() == time1.getDate()) {
      location1 = locations[current];
      if (!!cityData) {
        con.log(findCity(location1.latitudeE7, location2.latitudeE7));
      }
      location2 = locations[current - 1];

      lat1 = location1.latitudeE7 / 10000000;
      lon1 = location1.longitudeE7 / 10000000;
      lat2 = location2.latitudeE7 / 10000000;
      lon2 = location1.longitudeE7 / 10000000;

      distance += distanceFromLatLng(lat1, lon1, lat2, lon2);
      time2 = new Date(parseInt(location2.timestampMs, 10));
      current -= 1;
    }

    perc = distance / total * 100;
    if (perc > 100) { perc = 100; }

    dateDiv.innerHTML = time1.niceDate();

    travelledDiv.style.width = perc + "%";
    leftDiv.style.width = Math.min(100 - perc, 100) + "%";
    leftDiv.style.left = perc + "%";
    rocket.style.left = perc + "%";
    travelledDiv.innerHTML = distance.formatWithCommas() + " km<br>" + (distance * km2miles).formatWithCommas() + " miles";

    left = total - distance;
    if (left < 0) { left = 0; }
    leftDiv.innerHTML = left.formatWithCommas() + " km<br>" + (left * km2miles).formatWithCommas() + " miles";

    if (!travelledDiv.style.paddingRight) {
      if (travelledDiv.offsetWidth > 25) {
        travelledDiv.style.paddingRight = "25px";
      }
    }

    if (current > 0) {
      global.requestAnimationFrame(travel);
    }
  }

  function start() {
    var xhr = new global.XMLHttpRequest();

    xhr.onreadystatechange = function () {
      if (xhr.readyState == 4) {
        if (xhr.status >= 200 && xhr.status <= 304) {
          cities = JSON.parse(xhr.responseText);
        } else {
          con.log("Couldn't fetch city data, no geolocation possible.");
        }
        dropbox.style.display = "none";
        doc.getElementById("instructions").style.display = "none";
        global.requestAnimationFrame(travel);
      }
    };

    xhr.open("GET", "cities.json", true);
    xhr.send();
  }

  function handleFile(file) {
    var reader, data;
    reader = new global.FileReader();

    reader.onload = function (eventObj) {
      data = {};
      try {
        data = JSON.parse(eventObj.target.result);
      } catch (e) {
        dropbox.innerHTML = "Start aborted!<br>Invalid file format.";
        return;
      }<commit_msg>Test geolocation<commit_after>(function (global) {
  "use strict";
  var
    doc = global.document, con = global.console, dropbox, locations, current, distance, dateDiv, travelledDiv, leftDiv, rocket,
    total = 384400, km2miles = 0.621371, R = 6371, deg2rad = Math.PI / 180, cityData;

  dropbox = doc.getElementById("dropbox");
  dateDiv = doc.getElementById("date");
  travelledDiv = doc.getElementById("travelled");
  leftDiv = doc.getElementById("left");
  rocket = doc.getElementById("rocket");

  Date.prototype.niceDate = function () {
    var y, m, d;
    y = this.getFullYear().toString();
    m = (this.getMonth() + 1).toString();
    d  = this.getDate().toString();
    return y + "-" + (m[1] ? m : "0" + m[0]) + "-" + (d[1] ? d : "0" + d[0]);
  };

  Number.prototype.formatWithCommas = function () {
    return Math.round(this).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
  };

  // Haversine formula
  function distanceFromLatLng(lat1, lon1, lat2, lon2) {
    var dLat, dLon, a, c;

    dLat = (lat2 - lat1) * deg2rad / 2;
    dLon = (lon2 - lon1) * deg2rad / 2;
    lat1 = lat1 * deg2rad;
    lat2 = lat2 * deg2rad;

    a = Math.sin(dLat) * Math.sin(dLat) + Math.sin(dLon) * Math.sin(dLon) * Math.cos(lat1) * Math.cos(lat2);
    c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));

    return R * c;
  }

  function lazyDistance(lat1, lon1, lat2, lon2) {
    var dLat, dLon;
    dLat = lat2 - lat1;
    dLon = lon2 - lon1;
    if (dLat < 1 && dLat > -1 && dLon < 1 && dLon > -1) {
      // Inside of 1° we can pretty much ignore curves
      // We also only need a comparable value, so no need for Math.sqrt or converting to km
      return dLat * dLat + dLon * dLon;
    } else {
      // Too big to be considered
      return false;
    }
  }

  function citySort(a, b) {
    return (a.distance - b.distance);
  }

  function findCity(lat, lon) {
    var i, tmpCities = [], d;
    for (i = 0; i < cityData.cities.length; i++) {
      d = lazyDistance(lat, lon, cityData.cities[i][1], cityData.cities[i][2]);
      if (d !== false) {
        tmpCities.push({"city": cityData.cities[i][0], "country": cityData.countries[cityData.cities[i][3]], "distance": d});
      }
    }
    if (tmpCities.length > 0) {
      tmpCities.sort(citySort);
      return tmpCities[0];
    } else {
      return null;
    }
  }

  function travel() {
    var location = locations[current], location1, location2, lat1, lon1, lat2, lon2, time1, time2, perc, left;

    time1 = new Date(parseInt(location.timestampMs, 10));
    time2 = new Date(parseInt(location.timestampMs, 10));

    // putting all locations of one day together
    while (current > 0 && time2.getFullYear() == time1.getFullYear() && time2.getMonth() == time1.getMonth() && time2.getDate() == time1.getDate()) {
      location1 = locations[current];
      if (!!cityData) {
        con.log(findCity(location1.latitudeE7, location2.latitudeE7));
      }
      location2 = locations[current - 1];

      lat1 = location1.latitudeE7 / 10000000;
      lon1 = location1.longitudeE7 / 10000000;
      lat2 = location2.latitudeE7 / 10000000;
      lon2 = location1.longitudeE7 / 10000000;

      distance += distanceFromLatLng(lat1, lon1, lat2, lon2);
      time2 = new Date(parseInt(location2.timestampMs, 10));
      current -= 1;
    }

    perc = distance / total * 100;
    if (perc > 100) { perc = 100; }

    dateDiv.innerHTML = time1.niceDate();

    travelledDiv.style.width = perc + "%";
    leftDiv.style.width = Math.min(100 - perc, 100) + "%";
    leftDiv.style.left = perc + "%";
    rocket.style.left = perc + "%";
    travelledDiv.innerHTML = distance.formatWithCommas() + " km<br>" + (distance * km2miles).formatWithCommas() + " miles";

    left = total - distance;
    if (left < 0) { left = 0; }
    leftDiv.innerHTML = left.formatWithCommas() + " km<br>" + (left * km2miles).formatWithCommas() + " miles";

    if (!travelledDiv.style.paddingRight) {
      if (travelledDiv.offsetWidth > 25) {
        travelledDiv.style.paddingRight = "25px";
      }
    }

    if (current > 0) {
      global.requestAnimationFrame(travel);
    }
  }

  function start() {
    var xhr = new global.XMLHttpRequest();

    xhr.onreadystatechange = function () {
      if (xhr.readyState == 4) {
        if (xhr.status >= 200 && xhr.status <= 304) {
          cityData = JSON.parse(xhr.responseText);
        } else {
          con.log("Couldn't fetch city data, no geolocation possible.");
        }
        dropbox.style.display = "none";
        doc.getElementById("instructions").style.display = "none";
        global.requestAnimationFrame(travel);
      }
    };

    xhr.open("GET", "cities.json", true);
    xhr.send();
  }

  function handleFile(file) {
    var reader, data;
    reader = new global.FileReader();

    reader.onload = function (eventObj) {
      data = {};
      try {
        data = JSON.parse(eventObj.target.result);
      } catch (e) {
        dropbox.innerHTML = "Start aborted!<br>Invalid file format.";
        return;
      }
{'fraction_non_alphanumeric': 0.1595342356687898, 'fraction_numerical': 0.03702229299363057, 'mean_word_length': 2.6755669348939284, 'pattern_counts': {'":': 6, '<': 19, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 8, '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': '3695713', 'n_tokens_mistral': 3717, 'n_tokens_neox': 3460, 'n_words': 783}