Last active
June 15, 2016 19:07
-
-
Save ornerymoose/c4a45540304706e78191894dfe6b2539 to your computer and use it in GitHub Desktop.
on line 41, you can see the first two parameters are hardcoded. If I try to use .zip on cust_lat and cust_long in the File.open() block, there's no error but the values are completely wrong. What is the correct way to get cust_lat and cust_long into the block without hardcoding? NOTE: line 43 works as is.
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' | |
#read existing fiber latitudes from CSV | |
fib_lat = CSV.read("fib_lat.csv") | |
#read existing fiber longitudes from CSV | |
fib_long = CSV.read("fib_long.csv") | |
#read potential customer latitudes from CSV | |
cust_lat = CSV.read("cust_lat.csv") | |
#read potential customer longitudes from CSV | |
cust_long = CSV.read("cust_long.csv") | |
#get latitudes for potential customers, store in c_lat array | |
c_lat = [] | |
cust_lat.each do |c| | |
c_lat << c | |
end | |
#get longitudes for potential customers, store in c_long array | |
c_long = [] | |
cust_long.each do |c| | |
c_long << c | |
end | |
#get latitudes for existing fiber, store in lat array | |
lat = [] | |
fib_lat.each do |f| | |
lat << f | |
end | |
#get longitudes for existing fiber, store in long array | |
long = [] | |
fib_long.each do |f| | |
long << f | |
end | |
#create a file named distance-ouput.csv, iteratate through lat long arrays at same time using zip | |
File.open('distance-output.csv', 'w') do |csv_object| | |
lat.zip(long).each do |lat_locs,long_locs| | |
csv_object << Haversine.distance(28.59569, -81.21464, lat_locs.pop.to_f, long_locs.pop.to_f).to_feet | |
csv_object << "\n" | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment