<commit_before>var $ = require('jquery-node-browserify');

var config = require('./config');
var Matching = require('./matching');

var radius = 100;
var mapRoute = null;
var markers = [];

function init() {
  setLocalPoints(null);

  map = L.map('map');
  map.on('load', setInitMap);
  marker = L.marker([config.defaultConfig.latitude, config.defaultConfig.longitude]).addTo(map);
  map.setView([config.defaultConfig.latitude, config.defaultConfig.longitude], config.defaultConfig.zoom);
  L.tileLayer(config.cloudmade.url, {
    attribution: config.cloudmade.attribution
  }).addTo(map);

  map.on('click', matching);
  $('.undo-btn').bind('click', undoDrawRoute);
}

function matching(e) {
  var m = L.marker([e.latlng.lat, e.latlng.lng]).addTo(map);
  markers.push(m);
  $.ajax({
    type: 'POST',
    url: 'http://172.16.31.10:8080/query/nearby',
    data: {
      lng: e.latlng.lng,
      lat: e.latlng.lat,
      radius: radius
    }
  }).done(function(data) {
    if (data.length) {
      var localPoints = getLocalPoints();
      var matching = new Matching();
      var points = matching.getCandidatePoints(e.latlng.lng, e.latlng.lat, localPoints, data);
      setLocalPoints(points);
      var routes = findRoute(points);
      drawRoute(routes);
    }
  });
}

function drawRoute(routes) {
  if (mapRoute) map.removeLayer(mapRoute);

  var routePoints = [];
  for (var i = 0; i < routes.length; i++) {
    var point = {
      lat: routes[i].latitude,
      lon: routes[i].longitude
    };
    routePoints.push(point);
  }
  if (routePoints.length >= 2) {
    mapRoute = L.polyline(routePoints).addTo(map);
  }
}

function undoDrawRoute() {
  var routeLength = mapRoute.getLatLngs().length;
  mapRoute.spliceLatLngs(routeLength-1, 1);

  var points = getLocalPoints();
  points.pop();
  setLocalPoints(points);

  var m = markers.pop();
  map.removeLayer(m);
}

function findRoute(points) {
  var cPoints = points[points.length - 1];
  var point = cPoints[0];
  var routes = [];
  for (var i = 1; i < cPoints.length; i++) {
    var _point = cPoints[i];
    if (_point.probability > point.probability) point = _point;<commit_msg>if map route length = 0<commit_after>var $ = require('jquery-node-browserify');

var config = require('./config');
var Matching = require('./matching');

var radius = 100;
var mapRoute = null;
var markers = [];

function init() {
  setLocalPoints(null);

  map = L.map('map');
  map.on('load', setInitMap);
  marker = L.marker([config.defaultConfig.latitude, config.defaultConfig.longitude]).addTo(map);
  map.setView([config.defaultConfig.latitude, config.defaultConfig.longitude], config.defaultConfig.zoom);
  L.tileLayer(config.cloudmade.url, {
    attribution: config.cloudmade.attribution
  }).addTo(map);

  map.on('click', matching);
  $('.undo-btn').bind('click', undoDrawRoute);
}

function matching(e) {
  var m = L.marker([e.latlng.lat, e.latlng.lng]).addTo(map);
  markers.push(m);
  $.ajax({
    type: 'POST',
    url: 'http://172.16.31.10:8080/query/nearby',
    data: {
      lng: e.latlng.lng,
      lat: e.latlng.lat,
      radius: radius
    }
  }).done(function(data) {
    if (data.length) {
      var localPoints = getLocalPoints();
      var matching = new Matching();
      var points = matching.getCandidatePoints(e.latlng.lng, e.latlng.lat, localPoints, data);
      setLocalPoints(points);
      var routes = findRoute(points);
      drawRoute(routes);
    }
  });
}

function drawRoute(routes) {
  if (mapRoute) map.removeLayer(mapRoute);

  var routePoints = [];
  for (var i = 0; i < routes.length; i++) {
    var point = {
      lat: routes[i].latitude,
      lon: routes[i].longitude
    };
    routePoints.push(point);
  }
  if (routePoints.length >= 2) {
    mapRoute = L.polyline(routePoints).addTo(map);
  }
}

function undoDrawRoute() {
  if(mapRoute) var routeLength = mapRoute.getLatLngs().length;
  if(routeLength) {
    mapRoute.spliceLatLngs(routeLength-1, 1);

    var points = getLocalPoints();
    points.pop();
    setLocalPoints(points);

    var m = markers.pop();
    map.removeLayer(m);
  }
}

function findRoute(points) {
  var cPoints = points[points.length - 1];
  var point = cPoints[0];
  var routes = [];
  for (var i = 1; i < cPoints.length; i++) {
    var _point = cPoints[i];
    if (_point.probability > point.probability) point = _point;
{'fraction_non_alphanumeric': 0.1648605026516025, 'fraction_numerical': 0.010836984090385058, 'mean_word_length': 3.481404958677686, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '3671722', 'n_tokens_mistral': 1561, 'n_tokens_neox': 1508, 'n_words': 295}