<commit_before>angular.module('starter.services', [])
	/**
	 * Geolocation
	 * @param {type} $q
	 * @returns {_L5.Anonym$1}
	 */
	.factory('Geo', function($q) {
		return {
			getLocation: function() {
				var deferred = $q.defer();
				navigator.geolocation.getCurrentPosition(function(position) {
					deferred.resolve(position);
				}, function(error) {
					deferred.reject(error);
				});
        return deferred.promise;
			}
		}
	})
	/**
	 * Locations and weather services
	 */
	.factory('Locations', function($q, $http) {
		var openWeatherBaseUrl = "http://api.openweathermap.org/data/2.5";
    var appId = "***REMOVED***";

		return {
			all: function() {
				var locationsString = window.localStorage['locations'];
				if (locationsString) {
					return angular.fromJson(locationsString);
				}
				return [];
			},
      
			get: function(locationId) {
				var locationsString = window.localStorage['locations'];
				if (locationsString) {
					return angular.fromJson(locationsString)[locationId];
				}

				return {};
			},
      
			save: function(locations) {
				window.localStorage['locations'] = angular.toJson(locations);
			},
      
			// Todo verify location and store location identifier
			newLocation: function(name) {
				// Add a new location
				return {
					name: name,
          id: null
				};
			},
      
      getLastActiveIndex: function() {
        return parseInt(window.localStorage['lastActiveLocation']) || 0;
      },
      
      setLastActiveIndex: function(index) {
        window.localStorage['lastActiveLocation'] = index;
      },      
      
      // Find a location with geo coordinates
      findLocation: function(coords) {
        var deferred = $q.defer();
        var url = openWeatherBaseUrl + "/find";
        $http({
          method: 'GET',
          url: url,
          params: {
            APPID: appId,
            lat: coords.latitude,
            lon: coords.longitude,
            cnt: 4,
            type: 'like',
            mode: "json"
          }}).
          success(function(data, status, headers, config) {
            console.log(data, status);
            var location = {};
            if (data.count > 0) {
              var location = {
                name: data.list[0].name,
                id: data.list[0].id
              };
              deferred.resolve(location);
            } else {
              deferred.reject('Error finding city with given coordinates');
            }
          }).
          error(function(data, status, headers, config) {
            console.log(data, status);
            deferred.reject('Error finding city');
          });

        return deferred.promise;
      },
      <commit_msg>Fix find location service<commit_after>angular.module('starter.services', [])
	/**
	 * Geolocation
	 * @param {type} $q
	 * @returns {_L5.Anonym$1}
	 */
	.factory('Geo', function($q) {
		return {
			getLocation: function() {
				var deferred = $q.defer();
				navigator.geolocation.getCurrentPosition(function(position) {
					deferred.resolve(position);
				}, function(error) {
					deferred.reject(error);
				});
        return deferred.promise;
			}
		}
	})
	/**
	 * Locations and weather services
	 */
	.factory('Locations', function($q, $http) {
		var openWeatherBaseUrl = "http://api.openweathermap.org/data/2.5";
    var appId = "***REMOVED***";

		return {
			all: function() {
				var locationsString = window.localStorage['locations'];
				if (locationsString) {
					return angular.fromJson(locationsString);
				}
				return [];
			},
      
			get: function(locationId) {
				var locationsString = window.localStorage['locations'];
				if (locationsString) {
					return angular.fromJson(locationsString)[locationId];
				}

				return {};
			},
      
			save: function(locations) {
				window.localStorage['locations'] = angular.toJson(locations);
			},
      
			// Todo verify location and store location identifier
			newLocation: function(name) {
				// Add a new location
				return {
					name: name,
          id: null
				};
			},
      
      getLastActiveIndex: function() {
        return parseInt(window.localStorage['lastActiveLocation']) || 0;
      },
      
      setLastActiveIndex: function(index) {
        window.localStorage['lastActiveLocation'] = index;
      },      
      
      // Find a location with geo coordinates
      findLocation: function(coords) {
        var deferred = $q.defer();
        var url = openWeatherBaseUrl + "/find";
        var params = {
          APPID: appId,
          lat: coords.latitude.toFixed(4),
          lon: coords.longitude.toFixed(4),
          //cnt: 4,
          //type: 'like',
          mode: "json"
        };
        console.log(params);
        $http({
          method: 'GET',
          url: url,
          params: params}).
          success(function(data, status, headers, config) {
            console.log(data, status);
            var location = {};
            if (data.count > 0) {
              var location = {
                name: data.list[0].name,
                id: data.list[0].id
              };
              deferred.resolve(location);
            } else {
              deferred.reject('Error finding city with given coordinates');
            }
          }).
          error(function(data, status, headers, config) {
            console.log(data, status);
            deferred.reject('Error finding city');
          });

        return deferred.promise;
      },
      
{'fraction_non_alphanumeric': 0.1323851203501094, 'fraction_numerical': 0.0036469730123997084, 'mean_word_length': 1.9489247311827957, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4289705', 'n_tokens_mistral': 1788, 'n_tokens_neox': 1539, 'n_words': 317}