Fix the geocoder_test script

Fix the geocoder_test script by using the new config injection
capabilities.
pull/4484/head
Rafa de la Torre 9 years ago
parent 76faf52563
commit 5bb13c2c74

@ -1,6 +1,7 @@
#!/usr/bin/env ruby
require 'yaml'
require File.expand_path('../../services/geocoder/lib/geocoder.rb', __FILE__)
require 'tmpdir'
require_relative '../services/geocoder/lib/hires_geocoder_factory'
TIMEOUT = 300 # seconds before raising a timeout error
@ -9,25 +10,25 @@ def usage
end
environment = ARGV[0]
non_batch = ARGV[1] == 'non-batch'
non_batch = (ARGV[1] == 'non-batch')
usage unless environment
def load_config(environment)
config_file_hash = YAML.load_file(File.expand_path('../../config/app_config.yml', __FILE__))
config_file_hash[environment]["geocoder"].inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
config_file_hash[environment]["geocoder"]
rescue => e
raise "Missing or inaccessible config for environment #{environment} in config/app_config.yml: #{e.message}"
end
config = load_config(environment)
geocoder = CartoDB::Geocoder.new(config.merge(
input_file: File.expand_path('../../services/geocoder/spec/fixtures/nokia_input.csv', __FILE__),
force_batch: !non_batch
))
CartoDB::GeocoderConfig.instance.set config.merge(force_batch: !non_batch)
input_file = File.expand_path('../../services/geocoder/spec/fixtures/nokia_input.csv', __FILE__)
working_dir = Dir.mktmpdir
geocoder = CartoDB::HiresGeocoderFactory.get(input_file, working_dir)
puts "Runing #{(non_batch ? 'non batch' : 'batch')} geocoder..."
start = Time.now
geocoder.upload
geocoder.run
finish = Time.now
until geocoder.status == 'completed' do
finish = Time.now
@ -47,4 +48,5 @@ position = [response[4].to_f, response[5].to_f]
distance = Math.sqrt(expected_position.zip(position).map { |x| (x[1] - x[0])**2 }.reduce(:+))
raise "Geocoder FAILURE: wrong geocoded position #{position}, expected #{expected_position}, distance: #{distance}" if distance > 0.04
FileUtils.rm_f working_dir
puts "\e[32mGeocoder OK #{(finish - start)} secs\e[0m"

Loading…
Cancel
Save