vrfs-774: fixed tests
This commit is contained in:
parent
9f09674d77
commit
e69cd18fe1
|
|
@ -1,3 +1,4 @@
|
||||||
|
require 'csv'
|
||||||
module JamRuby
|
module JamRuby
|
||||||
class MaxMindGeo < ActiveRecord::Base
|
class MaxMindGeo < ActiveRecord::Base
|
||||||
|
|
||||||
|
|
@ -10,12 +11,41 @@ module JamRuby
|
||||||
# startIpNum,endIpNum,country,region,city,postalCode,latitude,longitude,dmaCode,areaCode
|
# startIpNum,endIpNum,country,region,city,postalCode,latitude,longitude,dmaCode,areaCode
|
||||||
|
|
||||||
MaxMindGeo.transaction do
|
MaxMindGeo.transaction do
|
||||||
|
cols = [:startIpNum, :endIpNum, :country, :region, :city, :latitude, :longitude]
|
||||||
MaxMindGeo.delete_all
|
MaxMindGeo.delete_all
|
||||||
File.open(file, 'r:ISO-8859-1') do |io|
|
CSV.foreach(file, :encoding => 'ISO-8859-1') do |startIpNum,endIpNum,country,region,city,postalCode,latitude,longitude,dmaCode,areaCode|
|
||||||
MaxMindGeo.pg_copy_from io, :map => { 'startIpNum' => 'ip_start', 'endIpNum' => 'ip_end', 'country' => 'country', 'region' => 'region', 'city' => 'city', 'latitude' => 'lat', 'longitude' => 'lng'}, :columns => [:startIpNum, :endIpNum, :country, :region, :city, :latitude, :longitude]
|
next if startIpNum == 'startIpNum'
|
||||||
|
mmg = MaxMindGeo.new
|
||||||
|
mmg.ip_start = startIpNum
|
||||||
|
mmg.ip_end = endIpNum
|
||||||
|
mmg.country = MaxMindIsp.strip_quotes(country)
|
||||||
|
mmg.region = MaxMindIsp.strip_quotes(region)
|
||||||
|
mmg.city = MaxMindIsp.strip_quotes(city)
|
||||||
|
mmg.lat = latitude
|
||||||
|
mmg.lng = longitude
|
||||||
|
mmg.save!
|
||||||
end
|
end
|
||||||
|
# File.open(file, 'r:ISO-8859-1') do |io|
|
||||||
|
# MaxMindGeo.pg_copy_from(io, :map => {
|
||||||
|
# 'startIpNum' => 'ip_start',
|
||||||
|
# 'endIpNum' => 'ip_end',
|
||||||
|
# 'country' => 'country',
|
||||||
|
# 'region' => 'region',
|
||||||
|
# 'city' => 'city',
|
||||||
|
# 'latitude' => 'lat',
|
||||||
|
# 'longitude' => 'lng'},
|
||||||
|
# :columns => cols) do |row|
|
||||||
|
# # byebug
|
||||||
|
# row[0] = row[0]
|
||||||
|
# row[1] = row[1]
|
||||||
|
# row[2] = MaxMindIsp.strip_quotes(row[2])
|
||||||
|
# row[3] = MaxMindIsp.strip_quotes(row[3])
|
||||||
|
# row[4] = MaxMindIsp.strip_quotes(row[4])
|
||||||
|
# row[5] = row[5]
|
||||||
|
# row[6] = row[6]
|
||||||
|
# end
|
||||||
|
# end
|
||||||
end
|
end
|
||||||
byebug
|
|
||||||
User.find_each { |usr| usr.update_lat_lng }
|
User.find_each { |usr| usr.update_lat_lng }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,6 @@ module JamRuby
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def self.strip_quotes str
|
def self.strip_quotes str
|
||||||
return nil if str.nil?
|
return nil if str.nil?
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue