Skip to content

Instantly share code, notes, and snippets.

@criess
Last active November 28, 2017 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save criess/ab4a494b5ec4a99a422f72d61db63b5d to your computer and use it in GitHub Desktop.
Save criess/ab4a494b5ec4a99a422f72d61db63b5d to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rubygems'
require 'active_support/all'
require 'yaml'
require 'i18n'
require 'net/http'
require 'digest/sha1'
# from rails 3.2 framework
class Hash
# Returns a hash that represents the difference between two hashes.
#
# Examples:
#
# {1 => 2}.diff(1 => 2) # => {}
# {1 => 2}.diff(1 => 3) # => {1 => 2}
# {}.diff(1 => 2) # => {1 => 2}
# {1 => 2, 3 => 4}.diff(1 => 2) # => {3 => 4}
def diff(h2)
dup.delete_if { |k, v| h2[k] == v }.merge!(h2.dup.delete_if { |k, v| has_key?(k) })
end
end
require File.join(ENV["HOME"],'workspace', 'onlineantrag-rails', 'lib', 'behaviors', 'geocode_verification.rb')
all = []
hashed = []
# pre-filter data (path in hash and deep attributes)
while( entry = gets ) do
if eval(entry)['tenancy_retail']
all += eval(entry)['tenancy_retail']['lessee_attributes'].map do |i,k|
k.slice('address_street','address_snumber', 'address_city', 'address_zip')
end
else
all << eval(entry).slice('address_street', 'address_snumber', 'address_city', 'address_zip')
end
end
module LoggingOverride
def self.included(klass)
klass.send :alias_method_chain, :logger, :hack
end
def logger_with_hack
@logger ||= SimpleLogger
end
class SimpleLogger
def self.method_missing(name, *args)
puts args.join
end
end
end
Behaviors::GeocodeVerification::Geocoder.send(:include, LoggingOverride)
gc = Behaviors::GeocodeVerification::Geocoder.new({:enable_geocode_verification => true, :service_phone => "0", :debug => true})
good = []
bad_no_results = []
bad_ambigous = []
bad_wrong = []
# we have 5 cases:
# DUPLICATE => user tried multiple times
# GOOD => all fine
# WRONG => only one alternative location was found
# AMBIGOUS => multiple alternative locations were found
# NO_RESULTS => no alternatives at all found
all.each do |entry|
current_digest = Digest::SHA1.hexdigest("#{entry}")
if hashed.include?(current_digest)
puts "DUPLICATE : #{entry}"
else
err = gc.getErrors(entry)
if err.empty?
good << entry
puts "GOOD : #{entry}"
else
# ambigous is considered stronger than wrong
if ( err.values.join(" ").match(/\.geocode_no_results/) )
bad_no_results << entry
puts "NO_RESULTS : #{entry}"
elsif ( err.values.join(" ").match(/\.geocode_ambigous/) )
bad_ambigous << entry
puts "AMBIGOUS : #{entry}"
else
bad_wrong << entry
puts "WRONG : #{entry}"
end
end
hashed << current_digest
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment