ns_geo 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Rakefile +2 -0
- data/app/services/ns_geo/geo_location_importer.rb +40 -14
- data/db/migrate/{20170415162318_create_ns_geo_geo_locations.rb → 20170416102432_create_ns_geo_geo_locations.rb} +0 -0
- data/lib/ns_geo/version.rb +1 -1
- data/lib/tasks/ns_geo_tasks.rake +6 -5
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3636b3ee4c21974d245b13cde8fa5446c74cab54
|
|
4
|
+
data.tar.gz: 39a51317ae161152243d13fe40c16fca8875ae56
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ec130768b9e77ea9e45f8645fb9c4d60e89c273b82fbbdf2a4fe628efda1105a764fbf5eb8c6a7a68820ce0f63880a88b7f74c80be9612698731bab2ee8ee959
|
|
7
|
+
data.tar.gz: dcc6e233a8d8539fc81366780d4fc100bd0a0db9fc2ed091e289c0b76452161b59d2e0188ee7c93f3ca3d39932a76711368233d5d6d9fb6d3e27b6fe108a9683
|
data/Rakefile
CHANGED
|
@@ -1,23 +1,49 @@
|
|
|
1
1
|
module NsGeo
|
|
2
2
|
class GeoLocationImporter
|
|
3
|
+
require 'csv'
|
|
4
|
+
|
|
3
5
|
def self.import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
+
total = get_count
|
|
7
|
+
t1 = Time.now
|
|
8
|
+
result = read_csv_file
|
|
9
|
+
t2 = Time.now
|
|
10
|
+
delta = t2 - t1
|
|
11
|
+
puts('GeoLocation Import Report:')
|
|
12
|
+
puts("Locations are imported in: #{delta} seconds.")
|
|
13
|
+
puts("Total records: #{total}")
|
|
14
|
+
puts("Saved records: #{result[:saved]}")
|
|
15
|
+
puts("Discarded records: #{result[:discarded]}")
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def self.get_count
|
|
19
|
+
CSV.foreach(NsGeo.csv_location, :headers => true).count
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.read_csv_file
|
|
23
|
+
result = {saved: 0, discarded: 0}
|
|
6
24
|
CSV.foreach(NsGeo.csv_location, :headers => true) do |row|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
geo_location[:mystery_value] = row[6]
|
|
15
|
-
geo_location.save
|
|
16
|
-
count = count + 1
|
|
17
|
-
if count % 100 == 0
|
|
18
|
-
return
|
|
25
|
+
if save(row)
|
|
26
|
+
result[:saved] = result[:saved] + 1
|
|
27
|
+
else
|
|
28
|
+
result[:discarded] = result[:discarded] + 1
|
|
29
|
+
end
|
|
30
|
+
if result[:saved] == 1000
|
|
31
|
+
return result
|
|
19
32
|
end
|
|
20
33
|
end
|
|
34
|
+
result
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def self.save(row)
|
|
38
|
+
geo_location = NsGeo::GeoLocation.new
|
|
39
|
+
geo_location[:ip_address] = row[0]
|
|
40
|
+
geo_location[:country_code] = row[1]
|
|
41
|
+
geo_location[:country] = row[2]
|
|
42
|
+
geo_location[:city] = row[3]
|
|
43
|
+
geo_location[:latitude] = row[4]
|
|
44
|
+
geo_location[:longitude] = row[5]
|
|
45
|
+
geo_location[:mystery_value] = row[6]
|
|
46
|
+
geo_location.save
|
|
21
47
|
end
|
|
22
48
|
end
|
|
23
49
|
end
|
|
File without changes
|
data/lib/ns_geo/version.rb
CHANGED
data/lib/tasks/ns_geo_tasks.rake
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
namespace :ns_geo do
|
|
2
|
+
desc "Imports geo location data from csv file to the database"
|
|
3
|
+
task import_locations: :environment do
|
|
4
|
+
NsGeo::GeoLocationImporter.import
|
|
5
|
+
end
|
|
6
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ns_geo
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- EnesKorukcu
|
|
@@ -56,7 +56,7 @@ files:
|
|
|
56
56
|
- app/models/ns_geo/geo_location.rb
|
|
57
57
|
- app/services/ns_geo/geo_location_importer.rb
|
|
58
58
|
- config/routes.rb
|
|
59
|
-
- db/migrate/
|
|
59
|
+
- db/migrate/20170416102432_create_ns_geo_geo_locations.rb
|
|
60
60
|
- lib/ns_geo.rb
|
|
61
61
|
- lib/ns_geo/engine.rb
|
|
62
62
|
- lib/ns_geo/version.rb
|