wolf_core 1.1.27 → 1.1.29
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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 88268f4f9a3b3ba94896745e3f19ff7c0d4efd6181b76df3a0e4abfa274ec553
|
|
4
|
+
data.tar.gz: 0abf44fc4a560d04120bcdaee48565fa415ecc3045cd6b650fc4dc1c21587d83
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3f74d13d8600fde7c88cc4f63f236c4458d3fac2d96a5c50571ac81a755f54b332cb4e68c0a81f979d1d4faf9bf5b5555e95c9dc4e21d95ba39c7ac4b58c0feb
|
|
7
|
+
data.tar.gz: 3f1a16a199da3c74271a0ffe277e6475a007ef67a15007fbfb75d7395dd843482ee3ea6f9ed1fe15cb7ce1be217dff9e7f3bf71a656bffb8986c31d0c3ca0564
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "geocoder"
|
|
4
|
+
require_relative "../utils/logging_utils"
|
|
5
|
+
|
|
6
|
+
module WolfCore
|
|
7
|
+
class GeoLocationDataSource
|
|
8
|
+
include WolfCore::LoggingUtils
|
|
9
|
+
|
|
10
|
+
def initialize
|
|
11
|
+
api_key = ENV["GOOGLE_MAPS_API_KEY"]
|
|
12
|
+
if api_key.nil? || api_key.empty?
|
|
13
|
+
raise ArgumentError, "GOOGLE_MAPS_API_KEY environment variable must be configured"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
Geocoder.configure(
|
|
17
|
+
lookup: :google,
|
|
18
|
+
api_key: api_key
|
|
19
|
+
)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def get_address_coordinates(address_string)
|
|
23
|
+
results = Geocoder.search(address_string)
|
|
24
|
+
return nil if results.empty?
|
|
25
|
+
|
|
26
|
+
result = results.first
|
|
27
|
+
{ latitude: result.latitude, longitude: result.longitude }
|
|
28
|
+
rescue StandardError => e
|
|
29
|
+
log_geocoding_error(address_string, e)
|
|
30
|
+
nil
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def calculate_distance(coord1, coord2)
|
|
34
|
+
lat1, lon1 = coord1[:latitude], coord1[:longitude]
|
|
35
|
+
lat2, lon2 = coord2[:latitude], coord2[:longitude]
|
|
36
|
+
|
|
37
|
+
earth_radius_meters = 6_371_000
|
|
38
|
+
|
|
39
|
+
lat1_rad = lat1 * Math::PI / 180
|
|
40
|
+
lat2_rad = lat2 * Math::PI / 180
|
|
41
|
+
delta_lat = (lat2 - lat1) * Math::PI / 180
|
|
42
|
+
delta_lon = (lon2 - lon1) * Math::PI / 180
|
|
43
|
+
|
|
44
|
+
a = Math.sin(delta_lat / 2)**2 +
|
|
45
|
+
Math.cos(lat1_rad) * Math.cos(lat2_rad) * Math.sin(delta_lon / 2)**2
|
|
46
|
+
c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a))
|
|
47
|
+
|
|
48
|
+
earth_radius_meters * c
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
private
|
|
52
|
+
|
|
53
|
+
def log_geocoding_error(address_string, error)
|
|
54
|
+
log_object("Geocoding error for address: #{address_string}", error: error.message)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -145,5 +145,70 @@ module WolfCore
|
|
|
145
145
|
{ first_name: name, last_name: lastname }
|
|
146
146
|
end
|
|
147
147
|
|
|
148
|
+
def jaro_winkler_similarity(string1, string2)
|
|
149
|
+
str1 = string1.to_s.strip.downcase
|
|
150
|
+
str2 = string2.to_s.strip.downcase
|
|
151
|
+
|
|
152
|
+
return 1.0 if str1 == str2
|
|
153
|
+
return 0.0 if str1.empty? || str2.empty?
|
|
154
|
+
|
|
155
|
+
max_len = [str1.length, str2.length].max
|
|
156
|
+
match_distance = [(max_len / 2) - 1, 0].max
|
|
157
|
+
|
|
158
|
+
str1_matches = Array.new(str1.length, false)
|
|
159
|
+
str2_matches = Array.new(str2.length, false)
|
|
160
|
+
|
|
161
|
+
matches = 0
|
|
162
|
+
|
|
163
|
+
str1.each_char.with_index do |char, i|
|
|
164
|
+
start = [i - match_distance, 0].max
|
|
165
|
+
finish = [i + match_distance + 1, str2.length].min
|
|
166
|
+
|
|
167
|
+
(start...finish).each do |j|
|
|
168
|
+
next if str2_matches[j]
|
|
169
|
+
next unless str2[j] == char
|
|
170
|
+
|
|
171
|
+
str1_matches[i] = true
|
|
172
|
+
str2_matches[j] = true
|
|
173
|
+
matches += 1
|
|
174
|
+
break
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
return 0.0 if matches.zero?
|
|
179
|
+
|
|
180
|
+
transpositions = 0
|
|
181
|
+
j = 0
|
|
182
|
+
|
|
183
|
+
str1.each_char.with_index do |char, i|
|
|
184
|
+
next unless str1_matches[i]
|
|
185
|
+
|
|
186
|
+
j += 1 while j < str2.length && !str2_matches[j]
|
|
187
|
+
break if j >= str2.length
|
|
188
|
+
|
|
189
|
+
transpositions += 1 if str2[j] != char
|
|
190
|
+
j += 1
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
transpositions /= 2.0
|
|
194
|
+
|
|
195
|
+
jaro = (
|
|
196
|
+
(matches / str1.length.to_f) +
|
|
197
|
+
(matches / str2.length.to_f) +
|
|
198
|
+
((matches - transpositions) / matches)
|
|
199
|
+
) / 3.0
|
|
200
|
+
|
|
201
|
+
prefix_length = 0
|
|
202
|
+
max_prefix = 4
|
|
203
|
+
while prefix_length < max_prefix &&
|
|
204
|
+
prefix_length < str1.length &&
|
|
205
|
+
prefix_length < str2.length &&
|
|
206
|
+
str1[prefix_length] == str2[prefix_length]
|
|
207
|
+
prefix_length += 1
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
jaro + (prefix_length * 0.1 * (1 - jaro))
|
|
211
|
+
end
|
|
212
|
+
|
|
148
213
|
end
|
|
149
214
|
end
|
data/lib/wolf_core/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: wolf_core
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.1.
|
|
4
|
+
version: 1.1.29
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Javier Roncallo
|
|
@@ -121,6 +121,20 @@ dependencies:
|
|
|
121
121
|
- - ">="
|
|
122
122
|
- !ruby/object:Gem::Version
|
|
123
123
|
version: '0'
|
|
124
|
+
- !ruby/object:Gem::Dependency
|
|
125
|
+
name: geocoder
|
|
126
|
+
requirement: !ruby/object:Gem::Requirement
|
|
127
|
+
requirements:
|
|
128
|
+
- - ">="
|
|
129
|
+
- !ruby/object:Gem::Version
|
|
130
|
+
version: '0'
|
|
131
|
+
type: :runtime
|
|
132
|
+
prerelease: false
|
|
133
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
134
|
+
requirements:
|
|
135
|
+
- - ">="
|
|
136
|
+
- !ruby/object:Gem::Version
|
|
137
|
+
version: '0'
|
|
124
138
|
description: Repository to store shared code among Ruby projects.
|
|
125
139
|
email:
|
|
126
140
|
- jroncallo96@gmail.com
|
|
@@ -153,6 +167,7 @@ files:
|
|
|
153
167
|
- lib/wolf_core/infrastructure/application_repository.rb
|
|
154
168
|
- lib/wolf_core/infrastructure/application_serializer.rb
|
|
155
169
|
- lib/wolf_core/infrastructure/fkm_operations.rb
|
|
170
|
+
- lib/wolf_core/infrastructure/geo_location_data_source.rb
|
|
156
171
|
- lib/wolf_core/infrastructure/http_data_source.rb
|
|
157
172
|
- lib/wolf_core/infrastructure/http_operations.rb
|
|
158
173
|
- lib/wolf_core/infrastructure/in_memory_storage_data_source.rb
|