<commit_before>var Promise         = require('promise');
var request         = require('request');
var config        	= require('../../../config/app');
var Place        	= require('./place-model');

module.exports = function() {
    'use strict';
    
    this.getPlaces = function() {
        return new Promise(function(resolve, reject) {
            Place.find()
                .where('name').ne(null)
                .exec(function(err, data) {
                    if (err) {
                        reject(err);
                    }
                    resolve(data);
                });
        });
    };
    
    this.savePlace = function(data) {
        return new Promise(function(resolve, reject) {
            Place.findOne({ _id: data._id }, function(err, place) {
                if (err) {
                    reject(err);
                }
                if (!place) {
                    if (!data.lat || !data.lon) {
                        reject('missing lat/long coordinates');
                    }
                    place = new Place(data);
                } else {
                    for (var prop in place) {
                        if (data.hasOwnProperty(prop) && data[prop]) {
                            place[prop] = data[prop];
                        }
                    }
                }
                place.save(function(err, res) {
                    if (err) {
                        reject(err);
                    }
                    resolve(res);
                });
            });
        });
    };
    
    this.deletePlace = function(id) {
        return new Promise(function(resolve, reject) {
            Place.remove({ _id: id })
                .exec(function(err) {
                    if (err) {
                        reject(err);
                    }
                    resolve();
                });
        });
    };
    
    this.geocodeLocation = function(locationSearch) {
        return new Promise(function(resolve, reject) {
            console.log('geocoding...');
            var options = {
                uri: 'http://open.mapquestapi.com/geocoding/v1/address?key=' + config.keys.mapquest + '&location=' + locationSearch,
                method: 'GET',
                headers: {
                    'Content-Type': 'application/json'
                }
            };
            request(options, function(err, res, body) {
                if(!body) {
                    reject('request returned empty');
                }
                var data = JSON.parse(body);
                if(data) {
                    console.log('received geocode data');
                    resolve(data.results);
                } else {
                    reject('unexpected results...');
                }
            }).on('error', function(e) {
                    reject(e.message);
            });
        });
    }
};<commit_msg>fix lon vs lng<commit_after>var Promise         = require('promise');
var request         = require('request');
var config        	= require('../../../config/app');
var Place        	= require('./place-model');

module.exports = function() {
    'use strict';
    
    this.getPlaces = function() {
        return new Promise(function(resolve, reject) {
            Place.find()
                .where('name').ne(null)
                .exec(function(err, data) {
                    if (err) {
                        reject(err);
                    }
                    resolve(data);
                });
        });
    };
    
    this.savePlace = function(data) {
        return new Promise(function(resolve, reject) {
            Place.findOne({ _id: data._id }, function(err, place) {
                if (err) {
                    reject(err);
                }
                if (!place) {
                    if (!data.lat || !data.lng) {
                        reject('missing lat/long coordinates');
                    }
                    place = new Place(data);
                } else {
                    for (var prop in place) {
                        if (data.hasOwnProperty(prop) && data[prop]) {
                            place[prop] = data[prop];
                        }
                    }
                }
                place.save(function(err, res) {
                    if (err) {
                        reject(err);
                    }
                    resolve(res);
                });
            });
        });
    };
    
    this.deletePlace = function(id) {
        return new Promise(function(resolve, reject) {
            Place.remove({ _id: id })
                .exec(function(err) {
                    if (err) {
                        reject(err);
                    }
                    resolve();
                });
        });
    };
    
    this.geocodeLocation = function(locationSearch) {
        return new Promise(function(resolve, reject) {
            console.log('geocoding...');
            var options = {
                uri: 'http://open.mapquestapi.com/geocoding/v1/address?key=' + config.keys.mapquest + '&location=' + locationSearch,
                method: 'GET',
                headers: {
                    'Content-Type': 'application/json'
                }
            };
            request(options, function(err, res, body) {
                if(!body) {
                    reject('request returned empty');
                }
                var data = JSON.parse(body);
                if(data) {
                    console.log('received geocode data');
                    resolve(data.results);
                } else {
                    reject('unexpected results...');
                }
            }).on('error', function(e) {
                    reject(e.message);
            });
        });
    }
};

{'fraction_non_alphanumeric': 0.12517193947730398, 'fraction_numerical': 0.000343878954607978, 'mean_word_length': 0.9698611581442601, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5547551', 'n_tokens_mistral': 1457, 'n_tokens_neox': 1358, 'n_words': 257}