<commit_before>var svg, projection;



var getData = function (callback) {
  console.log('got in ajax request');
  $.get('/api/events/', function (data) {
    callback(data);
  });
};

// Get Google Reverse Geocode API data - passes latLong for Google API lookup
// https://developers.google.com/maps/documentation/geocoding/intro?csw=1#ReverseGeocoding
var getZipcode = function (latLong, callback) {
  console.log('Got the Google Zipcode data');

  // Build URL string for query
  var googleURL = '//maps.googleapis.com/maps/api/geocode/json?latlng=' 
                  + latLong
                  + '&key=<KEY>';

  $.get(googleURL , function (data) {
    console.log(data);
    console.log(data.results[7]["long_name"]);
    callback(data);
  });
};



// Calculates min and max of crime data set for use in quantize
var getMaxMin = function (data) {
  var resultArray = [];
  var dataMax = _.max(data, function(item) {
    return item['count'];
  });
  var dataMin = _.min(data, function(item) {
    return item['count'];
  });
  resultArray.push(dataMin);
  resultArray.push(dataMax);
  return resultArray;
};


// Generates a range of 9 values within the provided domain.
// Function used to generated CSS class values, 0-8.
// Values correspond to a range of blues in CSS file (see CSS file)
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! CHANGE THE DOMAIN HARDCODE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/*var quantize = d3.scale.quantize()
    .domain([162, 622])
    .range(d3.range(9).map(function(i) { return "q" + i + "-9"; }));
    */

// Append zipcode to each record
// Uses Google API
/*var appendZipcode = function(data) {

  // Iterate over each record in the data
  _.each(data, function(record) {

    // Get lat & long from data
    var latLong = record['Location'];
    console.log(latLong);

    // Call Google API with record's lat and long
    getZipcode(latLong, function (zipcode) {

      console.log(zipcode);
      data['zipcode'] = zipcode;
      console.log(data);
    });
  });
};

// Sum each zipcode count by each record
var getZipcodeCount = function (data) {
  var zipcodeCount = _.countBy(data, function(record) {
    return record['zipcode'];
  });
};
*/




var renderPoints = function (params) {
  getData(function (data) {
      var coord;
      console.log(svg);
      console.log(projection);
      // add circles to svg
      data = JSON.parse(data);
      svg.selectAll("circle")
      .data(data).enter()
      .append("circle")
      .attr("cx", function (d) {
        coord = [d.X, d.Y];
        return projection(coord)[0]; 
      })
      .attr("cy", function (d) { 
        coord = [d.X, d.Y];
        return projection(coord)[1]; 
      })
      // .attr("r", "2px")

      $('svg path').hover(function() {
        $("#details").text($(this).data("id") + " : " + $(this).data("name"));
      });
      animatePoints();
  }, params);
};

var animatePoints = function() {
  console.log(svg);
  console.log(projection);
  svg.selectAll("circle")
  .attr("r", "0px")
  .attr("stroke", "red")
  .transition(500)
  .delay(function(d) {
    var time = d.Time.split(":");
    return (time[0] * 1000) + ((time[1] / 60) * 1000);
  })
  .ease("cubic-in-out")
  .attr("r", "1px")
  .attr("stroke", "red")
  .transition()
  .delay(function(d) {
    var time = d.Time.split(":");
    return ((time[0] * 1000) + ((time[1] / 60) * 1000) + 1000);
  })
  .ease("cubic-in-out")
  .attr("r", "0px");
};

// // Renders Heat Map - this is rendered in place of standard map
// var renderHeatMap = function (params) {



//   getData(function(data) {
//     // Get zipcode for each entry and append to dataset
//     getZipcode()
//     appendZipcode()
//     // Run summing function on zipcode data<commit_msg>Call to Google API works. Need to parse data now.<commit_after>var svg, projection;



var getData = function (callback) {
  console.log('got in ajax request');
  $.get('/api/events/', function (data) {
    callback(data);
  });
};

// Get Google Reverse Geocode API data - passes latLong for Google API lookup
// https://developers.google.com/maps/documentation/geocoding/intro?csw=1#ReverseGeocoding
var getZipcode = function (latLong, callback) {
  console.log('Got the Google Zipcode data');

  // Build URL string for query
  var googleURL = 'https://maps.googleapis.com/maps/api/geocode/json?latlng=' 
                  + latLong
                  + '&key=<KEY>';

  $.get(googleURL , function (data) {
    console.log('inside google url get')
    console.log(data);
    console.log(data.results[7]["long_name"]);

    callback(data);
  });
};

getZipcode('37.7702797662699, -122.433521628095', function(data) {
  console.log(data);
});



// Calculates min and max of crime data set for use in quantize
// var getMaxMin = function (data) {
//   var resultArray = [];
//   var dataMax = _.max(data, function(item) {
//     return item['count'];
//   });
//   var dataMin = _.min(data, function(item) {
//     return item['count'];
//   });
//   resultArray.push(dataMin);
//   resultArray.push(dataMax);
//   return resultArray;
// };


// Generates a range of 9 values within the provided domain.
// Function used to generated CSS class values, 0-8.
// Values correspond to a range of blues in CSS file (see CSS file)
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! CHANGE THE DOMAIN HARDCODE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/*var quantize = d3.scale.quantize()
    .domain([162, 622])
    .range(d3.range(9).map(function(i) { return "q" + i + "-9"; }));
    */

// Append zipcode to each record
// Uses Google API
/*var appendZipcode = function(data) {

  // Iterate over each record in the data
  _.each(data, function(record) {

    // Get lat & long from data
    var latLong = record['Location'];
    console.log(latLong);

    // Call Google API with record's lat and long
    getZipcode(latLong, function (zipcode) {

      console.log(zipcode);
      data['zipcode'] = zipcode;
      console.log(data);
    });
  });
};

// Sum each zipcode count by each record
var getZipcodeCount = function (data) {
  var zipcodeCount = _.countBy(data, function(record) {
    return record['zipcode'];
  });
};
*/




var renderPoints = function (params) {
  getData(function (data) {
      var coord;
      // console.log(svg);
      // console.log(projection);
      // add circles to svg
      data = JSON.parse(data);
      svg.selectAll("circle")
      .data(data).enter()
      .append("circle")
      .attr("cx", function (d) {
        coord = [d.X, d.Y];
        return projection(coord)[0]; 
      })
      .attr("cy", function (d) { 
        coord = [d.X, d.Y];
        return projection(coord)[1]; 
      })
      // .attr("r", "2px")

      $('svg path').hover(function() {
        $("#details").text($(this).data("id") + " : " + $(this).data("name"));
      });
      animatePoints();
  }, params);
};

var animatePoints = function() {
  // console.log(svg);
  // console.log(projection);
  svg.selectAll("circle")
  .attr("r", "0px")
  .attr("stroke", "red")
  .transition(500)
  .delay(function(d) {
    var time = d.Time.split(":");
    return (time[0] * 1000) + ((time[1] / 60) * 1000);
  })
  .ease("cubic-in-out")
  .attr("r", "1px")
  .attr("stroke", "red")
  .transition()
  .delay(function(d) {
    var time = d.Time.split(":");
    return ((time[0] * 1000) + ((time[1] / 60) * 1000) + 1000);
  })
  .ease("cubic-in-out")
  .attr("r", "0px");
};

// // Renders Heat Map - this is rendered in place of standard map
// var renderHeatMap = function (params) {



//   getData(function(data) {
//     // Get zipcode for each entry and append to dataset
//     getZipcode()
//     appendZipcode()
//     // Run summing function on zipcode data
{'fraction_non_alphanumeric': 0.18945998698763825, 'fraction_numerical': 0.017436564736499675, 'mean_word_length': 2.7993079584775087, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 3, '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': '875348', 'n_tokens_mistral': 2696, 'n_tokens_neox': 2509, 'n_words': 638}