Skip to content

Instantly share code, notes, and snippets.

@ornerymoose
Created March 13, 2018 18:01
Show Gist options
  • Save ornerymoose/6e33351a4b61e07e6fe19b1b5725057d to your computer and use it in GitHub Desktop.
Save ornerymoose/6e33351a4b61e07e6fe19b1b5725057d to your computer and use it in GitHub Desktop.
fiber has 171k rows, customers has 21k rows
require 'csv'
require 'haversine'
fiber = CSV.read("fiber/all_florida_fiber.csv", {headers: true}).first(3)
customers = CSV.read("prospect_customers_geocoded.csv", {headers: true, encoding: 'ISO-8859-1'}).first(3)
hh = Hash.new { |hsh,key| hsh[key] = [] }
#for each customer, loop through all the fiber coords
customers.each do |customer|
fiber.each do |fib|
hh[customer["cid"]].push Haversine.distance(customer["Latitude"].to_f, customer["Longitude"].to_f, fib["lat"].to_f, fib["long"].to_f).to_feet.round(2)
end
end
vals = hh.map { |k, v| v.min }
CSV.open("hash_output.csv", "wb") {|csv| vals.each {|elem| csv << [elem]} }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment