whos_using_what 0.2.5 → 0.2.6

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.
@@ -6,7 +6,8 @@ require "rest-client"
6
6
 
7
7
  class GeoTagger
8
8
 
9
- def initialize
9
+ def initialize log
10
+ @log = log
10
11
  @mongo_client = MongoHelper.get_mongo_connection
11
12
  @companies_coll = @mongo_client['companies']
12
13
  @coords_coll = @mongo_client['coordinates']
@@ -38,89 +39,95 @@ class GeoTagger
38
39
 
39
40
  end
40
41
 
42
+ def insert_new_zip_entry zip_code
41
43
 
42
- def load_geolocations_into_db
44
+ if (zip_acceptance_predicate (zip_code))
43
45
 
44
- @companies_coll.find().to_a.each do |company|
46
+ begin
47
+ #todo figure how to do this now that we are using instance variables instead of class variables
48
+ process_zip_closure = lambda {
45
49
 
46
- if !company
47
- next
48
- end
50
+ resp_map = @locations_client.api_get_google_location_data zip_code
49
51
 
52
+ doc = {}
50
53
 
51
- keys_arr = ['locations', 'values']
52
- locations = MapDataExtractionUtil.safe_extract_helper keys_arr, company, :nil, nil
53
-
54
- if !locations
55
- next
56
- end
57
- locations.each do |location|
58
54
 
59
- zip_code = location['address']['postalCode']
55
+ doc[:zip] = zip_code
60
56
 
61
- #strip off anything past 5 characters, as we only want main part of zip code
62
- if !zip_code || zip_code.size < 5
63
- next
64
- end
57
+ coords = @locations_client.get_coords_from_google_location_resp_helper resp_map
58
+ if coords[0] && coords[1]
59
+ doc[:loc] = {"lon" => coords[0], "lat" => coords[1]}
60
+ end
65
61
 
66
- zip_code = zip_code[0...5]
67
62
 
68
- if (zip_acceptance_predicate (zip_code))
63
+ keys_arr = ["AddressDetails", "Country", "AdministrativeArea", "Locality", "LocalityName"]
64
+ MapDataExtractionUtil.safe_extract_helper keys_arr, resp_map, :city, doc
69
65
 
66
+ keys_arr = ["AddressDetails", "Country", "AdministrativeArea", "AdministrativeAreaName"]
67
+ MapDataExtractionUtil.safe_extract_helper keys_arr, resp_map, :state, doc
70
68
 
71
- begin
72
- #todo figure how to do this now that we are using instance variables instead of class variables
73
- process_zip_closure = lambda {
69
+ keys_arr = ["AddressDetails", "Country", "CountryNameCode"]
70
+ MapDataExtractionUtil.safe_extract_helper keys_arr, resp_map, :country, doc
74
71
 
75
- resp_map = @locations_client.api_get_google_location_data zip_code
76
72
 
77
- doc = {}
73
+ if (doc.size > 1 && doc[:country] == "US")
74
+ coll = @coords_coll.find(zip: zip_code).to_a
75
+ end
78
76
 
77
+ if coll && coll.size < 1
79
78
 
80
- doc[:zip] = zip_code
81
79
 
82
- coords = @locations_client.get_coords_from_google_location_resp_helper resp_map
83
- if coords[0] && coords[1]
84
- doc[:loc] = {"lon" => coords[0], "lat" => coords[1]}
85
- end
80
+ @coords_coll.insert(doc)
86
81
 
82
+ end
83
+ }
87
84
 
88
- keys_arr = ["AddressDetails", "Country", "AdministrativeArea", "Locality", "LocalityName"]
89
- MapDataExtractionUtil.safe_extract_helper keys_arr, resp_map, :city, doc
85
+ process_zip_closure.call
86
+ rescue Exception => e
87
+ puts e.message
88
+ puts e.backtrace
90
89
 
91
- keys_arr = ["AddressDetails", "Country", "AdministrativeArea", "AdministrativeAreaName"]
92
- MapDataExtractionUtil.safe_extract_helper keys_arr, resp_map, :state, doc
90
+ end
91
+ end
93
92
 
94
- keys_arr = ["AddressDetails", "Country", "CountryNameCode"]
95
- MapDataExtractionUtil.safe_extract_helper keys_arr, resp_map, :country, doc
93
+ end
96
94
 
97
95
 
98
- if (doc.size > 1 && doc[:country] == "US")
99
- coll = @coords_coll.find(zip: zip_code).to_a
100
- end
96
+ def load_geolocations_into_db
101
97
 
102
- if coll && coll.size < 1
98
+ @companies_coll.find().to_a.each do |company|
103
99
 
100
+ if !company
101
+ next
102
+ end
104
103
 
105
- @coords_coll.insert(doc)
106
104
 
107
- end
108
- }
105
+ keys_arr = ['locations', 'values']
106
+ locations = MapDataExtractionUtil.safe_extract_helper keys_arr, company, :nil, nil
109
107
 
108
+ if !locations
109
+ next
110
+ end
111
+ locations.each do |location|
110
112
 
111
- process_zip_closure.call
112
- rescue Exception => e
113
- puts e.message
114
- puts e.backtrace
113
+ zip_code = location['address']['postalCode']
115
114
 
116
- end
115
+ #strip off anything past 5 characters, as we only want main part of zip code
116
+ if !zip_code || zip_code.size < 5
117
+ next
117
118
  end
119
+
120
+ zip_code = zip_code[0...5]
121
+
122
+ insert_new_zip_entry zip_code
118
123
  end
119
124
  end
120
125
  end
121
126
 
122
127
  def update_companies_with_latitude_longitude
123
128
 
129
+ @log.info "beginning updating of companies with latitude and longitude data"
130
+
124
131
  @companies_coll.find().to_a.each do |company|
125
132
 
126
133
 
@@ -1,12 +1,13 @@
1
1
  class CompaniesSearcher
2
2
 
3
- def initialize
3
+ #geo_tagger = instance of GeoTagger
4
+ def initialize geo_tagger
4
5
 
5
6
  @mongo_client = MongoHelper.get_mongo_connection
6
7
  @companies_coll = @mongo_client['companies']
7
8
  @coords_coll = @mongo_client['coordinates']
8
9
 
9
- @geo_tagger = GeoTagger.new
10
+ @geo_tagger = geo_tagger
10
11
 
11
12
  end
12
13
 
@@ -18,14 +19,11 @@ class CompaniesSearcher
18
19
  end
19
20
 
20
21
  def zip_code_search zip_code
22
+
21
23
  zip_doc = @coords_coll.find_one({:zip => zip_code})
22
24
  if zip_doc == nil
23
25
 
24
- #todo consider making a method in GeoTagger class to do this instead of using closure directly here
25
- #todo need to figure out how to call this from other class
26
- closure = @geo_tagger.process_zip_closure zip_code
27
-
28
- closure.call
26
+ @geo_tagger.insert_new_zip_entry zip_code
29
27
 
30
28
  end
31
29
  zip_doc = @coords_coll.find_one({:zip => zip_code})
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whos_using_what
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: