<commit_before>var map
  , markerPanel
  , latitudeSelect
  , longitudeSelect
  , config
  , alert
  , textarea;

$(document).ready(function() {
  latSelect = $('.latitude');
  lngSelect = $('.longitude');

  config = $('.config');
  alert = $('.alert');

  textarea = $('textarea');

  initMap();

  $('.panel-title').on('click', function(ev) {
    $(this).find('.glyphicon').toggleClass('glyphicon-chevron-up glyphicon-chevron-down');
    $('.panel-body').toggle();

    return false;
  });

  $('button[type="submit"]').on('click', function(ev) {
    parseCSV();
    
    return false;
  });

  $('button[type="config"]').on('click', function(ev) {
    toggleConfig(false, true);
    
    return false;
  });

  $('button[type="clear"]').on('click', function(ev) {
    markerPanel.clearLayers();
    
    toggleConfig(true, true);
    textarea.val('');
    
    latSelect.html('');
    lngSelect.html('');
    
    return false;
  });

  textarea.on('input propertychange', function(ev) {
    parseCSV();
  });
});

function initMap() {
  map = L.mapbox.map('map').setView([45.5594408, -73.7118666], 11);
  map.addLayer(L.mapbox.tileLayer('dinoz.gan1bagi'));

  markerPanel = new L.LayerGroup();
  map.addLayer(markerPanel);
}

function parseCSV() {
  var csv = textarea.val()
    , rows = csv.split('\n')
    , latLng;

  if (rows.length && rows[0].split(',').length > 1) {
    setOptions(rows);
    findIndexes(rows);

    var latIndex = latSelect.val() || -1
      , lngIndex = lngSelect.val() || -1;

    if (latIndex != -1 && lngIndex != -1) {
      toggleConfig(true, true);
      
      $('.panel-title').click();

      var icon = L.divIcon({ className: 'loc', iconSize: null })
        , bounds = L.latLngBounds([])
        , pos;

      markerPanel.clearLayers();

      rows.forEach(function(item) {
        latLng = item.split(',');

        try {
          pos = new L.LatLng(latLng[latIndex], latLng[lngIndex]);
          bounds.extend(pos);

          L.marker(pos, { icon: icon }).addTo(markerPanel);
        } catch (err) {
          // Invalid lat/lng pair most likely cause by the header row or invalid user config
        }
      });

      map.fitBounds(bounds);
    } else {
      toggleConfig(false, false);
    }
  }
}

function setOptions(rows) {
  var options = '';

  if (rows && rows.length) {
    rows[0].split(',').forEach(function(item, index) {
      options += '<option value="' + index + '">' + item + '</option>';
    });
  }  

  latSelect.html(options);
  lngSelect.html(options);
}

function findIndexes(rows) {
  var lngIndex = findLngIndex(rows)
    , latIndex = -1;

  if (lngIndex != -1) {
    latIndex = findLatIndex(rows, lngIndex);
  }

  latSelect.val(latIndex);
  lngSelect.val(lngIndex);
}<commit_msg>Allow user to type lat/lng<commit_after>var map
  , markerPanel
  , latitudeSelect
  , longitudeSelect
  , config
  , alert
  , textarea;

$(document).ready(function() {
  latSelect = $('.latitude');
  lngSelect = $('.longitude');

  config = $('.config');
  alert = $('.alert');

  textarea = $('textarea');

  initMap();

  $('.panel-title').on('click', function(ev) {
    $(this).find('.glyphicon').toggleClass('glyphicon-chevron-up glyphicon-chevron-down');
    $('.panel-body').toggle();

    return false;
  });

  $('button[type="submit"]').on('click', function(ev) {
    parseCSV();
    
    return false;
  });

  $('button[type="config"]').on('click', function(ev) {
    toggleConfig(false, true);
    
    return false;
  });

  $('button[type="clear"]').on('click', function(ev) {
    markerPanel.clearLayers();
    
    toggleConfig(true, true);
    textarea.val('');
    
    latSelect.html('');
    lngSelect.html('');
    
    return false;
  });

  textarea.on('input propertychange', function(ev) {
    latSelect.html('');
    lngSelect.html('');

    parseCSV();
  });
});

function initMap() {
  map = L.mapbox.map('map').setView([45.5594408, -73.7118666], 11);
  map.addLayer(L.mapbox.tileLayer('dinoz.gan1bagi'));

  markerPanel = new L.LayerGroup();
  map.addLayer(markerPanel);
}

function parseCSV() {
  var csv = textarea.val()
    , rows = csv.split('\n')
    , latLng;

  if (rows.length && rows[0].split(',').length > 1) {
    setOptions(rows);
    findIndexes(rows);

    var latIndex = latSelect.val() || -1
      , lngIndex = lngSelect.val() || -1;

    if (latIndex != -1 && lngIndex != -1) {
      toggleConfig(true, true);
      
      var icon = L.divIcon({ className: 'loc', iconSize: null })
        , bounds = L.latLngBounds([])
        , pos;

      markerPanel.clearLayers();

      rows.forEach(function(item) {
        latLng = item.split(',');

        try {
          pos = new L.LatLng(latLng[latIndex], latLng[lngIndex]);
          bounds.extend(pos);

          L.marker(pos, { icon: icon }).addTo(markerPanel);
        } catch (err) {
          // Invalid lat/lng pair most likely cause by the header row or invalid user config
        }
      });

      map.fitBounds(bounds);
    } else {
      toggleConfig(false, false);
    }
  }
}

function setOptions(rows) {
  var options = '<option value="-1"></options>';

  if (!latSelect.html() || !lngSelect.html()) {
    if (rows && rows.length) {
      rows[0].split(',').forEach(function(item, index) {
        options += '<option value="' + index + '">' + item + '</option>';
      });
    }  

    latSelect.html(options);
    lngSelect.html(options);
  }
}

function findIndexes(rows) {
  if (rows.length && (latSelect.val() == -1 || lngSelect.val() == -1)) {
    var lngIndex = findLngIndex(rows)
      , latIndex = -1;

    if (lngIndex != -1) {
      latIndex = findLatIndex(rows, lngIndex);
    }

    if (rows[0].split(',').length == 2 && latIndex == -1 && lngIndex == -1) {
      latIndex = 0;
      lngIndex = 1;
    }

    latSelect.val(latIndex);
    lngSelect.val(lngIndex);
  }
}
{'fraction_non_alphanumeric': 0.19356494951223688, 'fraction_numerical': 0.011809002224884476, 'mean_word_length': 2.7389635316698655, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '7503855', 'n_tokens_mistral': 2107, 'n_tokens_neox': 1989, 'n_words': 363}