<commit_before>angular.module('cleaver.services', ['firebase'])

// this factory handles requests between the client and server
.factory('Rec', function($http, $location, $firebase) {
  var data = {restaurants: []};

  var setupFirebase = function(uniqueID) {
    var fb = new Firebase('https://cleaverapp.firebaseio.com/sessions');

    var ref = fb.child(uniqueID + '/categoryVetoes');
    data.categoryVetoes = $firebase(ref).$asObject();

    ref = fb.child(uniqueID + '/restaurantVetoes');
    data.restaurantVetoes = $firebase(ref).$asObject();
  };

  var calculateScore = function(restaurant) {
    // Secret sauce!
    var weightedReviews = Math.log(restaurant.review_count)/Math.log(10);
    var weightedStars = Math.pow(restaurant.rating, 1.5);

    return -(weightedReviews * weightedStars);
  };

  var getExistingSession = function(uniqueID) {
    return $http({
      method: 'GET',
      url: '/' + uniqueID
    }).success(function(resp) {
      data.id = uniqueID;
      data.restaurants = resp.businesses;

      for (var key in data.restaurants) {
        data.restaurants[key].distance = calculateDistance(resp.data.yelpData.region.center.longitude,resp.data.yelpData.region.center.latitude,data.restaurants[key].location.coordinate.longitude, data.restaurants[key].location.coordinate. latitude)
      }

      setupFirebase(data.id);
    }).error(function(err) {
      $location.path('/');
    });
  };

  var postLocation = function(location) {
    return $http({
      method: 'POST',
      url: '/location',
      data: { location: location }
    }).then(function(resp) {
      data.id = resp.data.uniqueID;
      data.restaurants = resp.data.yelpData.businesses;

      console.log(resp.data.yelpData)

      for (var key in data.restaurants) {
        data.restaurants[key].distance = calculateDistance(resp.data.yelpData.region.center.longitude,resp.data.yelpData.region.center.latitude,data.restaurants[key].location.coordinate.longitude, data.restaurants[key].location.coordinate. latitude)
      }

      setupFirebase(data.id);
      $location.path('/' + data.id);
    });
  };

  var vetoRestaurant = function(restaurantID) {
    data.restaurantVetoes[restaurantID] = true;
    data.restaurantVetoes.$save();
  };

  var vetoCategory = function(category) {
    data.categoryVetoes[category] = true;
    data.categoryVetoes.$save();
  };

  var calculateDistance = function(lon1, lat1, lon2, lat2){<commit_msg>removed console logs<commit_after>angular.module('cleaver.services', ['firebase'])

// this factory handles requests between the client and server
.factory('Rec', function($http, $location, $firebase) {
  var data = {restaurants: []};

  var setupFirebase = function(uniqueID) {
    var fb = new Firebase('https://cleaverapp.firebaseio.com/sessions');

    var ref = fb.child(uniqueID + '/categoryVetoes');
    data.categoryVetoes = $firebase(ref).$asObject();

    ref = fb.child(uniqueID + '/restaurantVetoes');
    data.restaurantVetoes = $firebase(ref).$asObject();
  };

  var calculateScore = function(restaurant) {
    // Secret sauce!
    var weightedReviews = Math.log(restaurant.review_count)/Math.log(10);
    var weightedStars = Math.pow(restaurant.rating, 1.5);

    return -(weightedReviews * weightedStars);
  };

  var getExistingSession = function(uniqueID) {
    return $http({
      method: 'GET',
      url: '/' + uniqueID
    }).success(function(resp) {
      data.id = uniqueID;
      data.restaurants = resp.businesses;

      for (var key in data.restaurants) {
        data.restaurants[key].distance = calculateDistance(resp.data.yelpData.region.center.longitude,resp.data.yelpData.region.center.latitude,data.restaurants[key].location.coordinate.longitude, data.restaurants[key].location.coordinate. latitude)
      }

      setupFirebase(data.id);
    }).error(function(err) {
      $location.path('/');
    });
  };

  var postLocation = function(location) {
    return $http({
      method: 'POST',
      url: '/location',
      data: { location: location }
    }).then(function(resp) {
      data.id = resp.data.uniqueID;
      data.restaurants = resp.data.yelpData.businesses;


      for (var key in data.restaurants) {
        data.restaurants[key].distance = calculateDistance(resp.data.yelpData.region.center.longitude,resp.data.yelpData.region.center.latitude,data.restaurants[key].location.coordinate.longitude, data.restaurants[key].location.coordinate. latitude)
      }

      setupFirebase(data.id);
      $location.path('/' + data.id);
    });
  };

  var vetoRestaurant = function(restaurantID) {
    data.restaurantVetoes[restaurantID] = true;
    data.restaurantVetoes.$save();
  };

  var vetoCategory = function(category) {
    data.categoryVetoes[category] = true;
    data.categoryVetoes.$save();
  };

  var calculateDistance = function(lon1, lat1, lon2, lat2){
{'fraction_non_alphanumeric': 0.14527096641252835, 'fraction_numerical': 0.00329692973418504, 'mean_word_length': 3.6184586108468126, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '784562', 'n_tokens_mistral': 1624, 'n_tokens_neox': 1523, 'n_words': 250}