<commit_before>/*
This view shows the details of the possible routes from origin to destination
*/

var React = require('react');

var ListView = React.createClass({
  propTypes: {
    currentRoute: React.PropTypes.object.isRequired,
    updateResults: React.PropTypes.func.isRequired
  },
  defaultOptions: {
    fourSquare_url: "https://api.foursquare.com/v2/venues/explore?client_id=LFDSJGGT42FEYM4KFGYR2ETFQZDEMTAVN0KQ0NHBLUXJU4UB&client_secret=YVKQEEBYGFUAMSNFRFEB1MJAEYRXHVBWOL35KFA51ITJBWEE&radius=5000&v=20150902",
    foodCategory_url: "&categoryId=4d4b7105d754a06374d81259",
    radius_url: "&radius=5000",
    limit_url: "&limit=10"
  },
  // NOTE: nextProps should equal a currentRoute polyLine
  // We should only render when a route which has .results property has been passed in
  shouldComponentUpdate (nextProps, nextState){
    var currentRoute = nextProps.currentRoute;
    var wayPoints = currentRoute.wayPoints;

    if(wayPoints.length > 0){ // only continue if waypoints have been set
      if(currentRoute.results){ // render the results if they have been obtained
        return true;
      }else{ // query for new results only if currentRoute doesn't have them yet
        this.queryFourSquare(wayPoints);
        return false;
      } //if
    }else{  //don't render anything
      return false;
    } //if
  },
  //queries fourSquare api to get new results.
  //save results to the current route and updates the parent (mapView)
  //re-render results onto the page by updating state variable.
  queryFourSquare (wayPoints){
    var results = {}; //test against duplicates
    var component = this;

    for(var i=1; i<wayPoints.length; i++){
      var point = wayPoints[i];
      var ll = "&ll="+point.G+","+point.K;
      var {fourSquare_url, foodCategory_url, radius_url, limit_url} = this.defaultOptions;
      $.ajax({
        url: fourSquare_url+ll+foodCategory_url+radius_url+limit_url,
        method: "GET",
        success: function(data){
          console.log("TEST: responses = ", data);
          var venues = data.response.groups[0].items;

          // loops through venues and adds them to results object and also removes duplicates by only saving the duplicate venue with the smallest distance property
          for (var i = 0; i < venues.length; i++) {
            var venue = venues[i].venue; 
            if (!results[venue.id]) { // if
                results[venue.id] = venue;
            } else {
              if (results[venue.id].distance > venue.distance) {
                results[venue.id] = venue;
              }
            } //if
          } //for

          var resultsArray = [];
          for (var id in results) {
            resultsArray.push(results[id]);
          }
          component.props.updateResults(resultsArray);

        }, //success()
        error: function(error){
          console.log("TEST -------> fourSquare error, error=", error);

        }
        // dataType: dataType
      }); //ajax()
<commit_msg>(feat) get featurePhoto from FourSquare for all venues<commit_after>/*
This view shows the details of the possible routes from origin to destination
*/

var React = require('react');

var ListView = React.createClass({
  propTypes: {
    currentRoute: React.PropTypes.object.isRequired,
    updateResults: React.PropTypes.func.isRequired
  },
  defaultOptions: {
    fourSquare_url: "https://api.foursquare.com/v2/venues/explore?client_id=LFDSJGGT42FEYM4KFGYR2ETFQZDEMTAVN0KQ0NHBLUXJU4UB&client_secret=YVKQEEBYGFUAMSNFRFEB1MJAEYRXHVBWOL35KFA51ITJBWEE&radius=5000&v=20150902",
    foodCategory_url: "&categoryId=4d4b7105d754a06374d81259",
    radius_url: "&radius=5000",
    limit_url: "&limit=10",
    photos_url: "&venuePhotos=1"

  },
  // NOTE: nextProps should equal a currentRoute polyLine
  // We should only render when a route which has .results property has been passed in
  shouldComponentUpdate (nextProps, nextState){
    var currentRoute = nextProps.currentRoute;
    var wayPoints = currentRoute.wayPoints;

    if(wayPoints.length > 0){ // only continue if waypoints have been set
      if(currentRoute.results){ // render the results if they have been obtained
        return true;
      }else{ // query for new results only if currentRoute doesn't have them yet
        this.queryFourSquare(wayPoints);
        return false;
      } //if
    }else{  //don't render anything
      return false;
    } //if
  },
  //queries fourSquare api to get new results.
  //save results to the current route and updates the parent (mapView)
  //re-render results onto the page by updating state variable.
  queryFourSquare (wayPoints){
    var results = {}; //test against duplicates
    var component = this;

    for(var i=1; i<wayPoints.length; i++){
      var point = wayPoints[i];
      var ll = "&ll="+point.G+","+point.K;
      var {fourSquare_url, foodCategory_url, radius_url, limit_url, photos_url} = this.defaultOptions;
      $.ajax({
        url: fourSquare_url+ll+foodCategory_url+radius_url+limit_url+photos_url,
        method: "GET",
        success: function(data){
          console.log("TEST: responses = ", data);
          var venues = data.response.groups[0].items;

          // loops through venues and adds them to results object and also removes duplicates by only saving the duplicate venue with the smallest distance property
          for (var i = 0; i < venues.length; i++) {
            var venue = venues[i].venue; 
            if (!results[venue.id]) { // if
                results[venue.id] = venue;
            } else {
              if (results[venue.id].distance > venue.distance) {
                results[venue.id] = venue;
              }
            } //if
          } //for

          var resultsArray = [];
          for (var id in results) {
            resultsArray.push(results[id]);
          }
          component.props.updateResults(resultsArray);

        }, //success()
        error: function(error){
          console.log("TEST -------> fourSquare error, error=", error);

        }
        // dataType: dataType
      }); //ajax()

{'fraction_non_alphanumeric': 0.10948545125760316, 'fraction_numerical': 0.017918790070688806, 'mean_word_length': 2.638755980861244, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 2, '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': '6849563', 'n_tokens_mistral': 1897, 'n_tokens_neox': 1776, 'n_words': 492}