<commit_before>angular.module('multi.Controller', ['bolt.profile'])

.controller('MultiController', function($window, $scope, Multi){
  $scope.session = $window.localStorage;
  
  Multi.addUserGeoFire();

  $scope.cancelSearch = function() {
    Multi.cancelSearch();
  }

})

.factory('Multi', function($location, $interval, Profile) {
  var firebaseRef = new Firebase("https://insane-bolt.firebaseio.com/");
  var geoFire = new GeoFire(firebaseRef);
  var currentUser;
  var userPosition;
  var stop;

  var search = function(geoQuery) {
    console.log('searching...');
    var users = [];
    var onKeyEnteredRegistration = geoQuery.on("key_entered", function(key, location, distance) {
      if (key !== currentUser._id) {
        console.log("found match, stop search")
        console.log("user id of new user", key);
        console.log("id of current user", currentUser._id);
        geoFire.remove(key).then(function() {});
        $interval.cancel(stop);
      }
    });
  }

  var generateQuery = function() {
    console.log('generate query');
    var geoQuery = geoFire.query({
      center: [userPosition.coords.latitude, userPosition.coords.longitude],
      // radius should eventually be reduced
      radius: 1000
    });

    stop = $interval(function() {
      search(geoQuery)}
      , 2000);
  }

  var addUserGeoFire = function(){
    // This line obtains the user's location, can get rid of this if this info is stored
    navigator.geolocation.getCurrentPosition(function(position) {
      // Retrieves the user, should be able to access this from session
      Profile.getUser().then(function(user) {
        currentUser = user.data;
        userPosition = position;
        // addUserGeoFire (this entire function) should start here if the user id and position are accessible
        // from session
        geoFire.set(user.data._id, [position.coords.latitude, position.coords.longitude]).then(function() {
          console.log("Provided key has been added to GeoFire");
          generateQuery();
          }, function(error) {
            console.log("Error: " + error);
          });
        });
      }, function(err) {
        console.error(err);
    });
  };
<commit_msg>Use different geofire database for debugging<commit_after>angular.module('multi.Controller', ['bolt.profile'])

.controller('MultiController', function($window, $scope, Multi){
  $scope.session = $window.localStorage;
  
  Multi.addUserGeoFire();

  $scope.cancelSearch = function() {
    Multi.cancelSearch();
  }

})

.factory('Multi', function($location, $interval, Profile) {
  var firebaseRef = new Firebase("https://glowing-fire-8101.firebaseio.com/");
  var geoFire = new GeoFire(firebaseRef);
  var currentUser;
  var userPosition;
  var stop;

  var search = function(geoQuery) {
    console.log('searching');
    var onKeyEnteredRegistration = geoQuery.on("key_entered", function(key, location, distance) {
      if (key !== currentUser._id) {
        console.log("found match, stop search")
        console.log("user id of new user", key);
        console.log("id of current user", currentUser._id);
        $interval.cancel(stop);
        return;
      }
    });
  }

  var generateQuery = function() {
    console.log('generate query');
    var geoQuery = geoFire.query({
      center: [userPosition.coords.latitude, userPosition.coords.longitude],
      // radius should eventually be reduced
      radius: 1000
    });

    stop = $interval(function() {
      search(geoQuery)}
      , 2000);
  }

  var addUserGeoFire = function(){
    // This line obtains the user's location, can get rid of this if this info is stored
    navigator.geolocation.getCurrentPosition(function(position) {
      // Retrieves the user, should be able to access this from session
      Profile.getUser().then(function(user) {
        currentUser = user.data;
        userPosition = position;
        // addUserGeoFire (this entire function) should start here if the user id and position are accessible
        // from session
        geoFire.set(user.data._id, [userPosition.coords.latitude, userPosition.coords.longitude]).then(function() {
          console.log("Provided key has been added to GeoFire");
          generateQuery();
          }, function(error) {
            console.log("Error: " + error);
          });
        });
      }, function(err) {
        console.error(err);
    });
  };

{'fraction_non_alphanumeric': 0.13127413127413126, 'fraction_numerical': 0.0045423574835339545, 'mean_word_length': 2.9568733153638815, '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': '7647199', 'n_tokens_mistral': 1296, 'n_tokens_neox': 1245, 'n_words': 309}