Created
March 13, 2018 18:01
-
-
Save ornerymoose/6e33351a4b61e07e6fe19b1b5725057d to your computer and use it in GitHub Desktop.
fiber has 171k rows, customers has 21k rows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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