dynamodb_geo 0.1.0 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -2
- data/lib/dynamodb_geo.rb +6 -5
- data/lib/dynamodb_geo/version.rb +1 -1
- data/lib/dynamodb_manager.rb +38 -9
- data/lib/store.rb +12 -11
- data/spec/dynamodb_geo_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fbbaf8b8e654469fa6eb8bae4a2f5b82822cef9469cf6748e937946ca885aa26
|
4
|
+
data.tar.gz: 56a1e5719a58a56e7bb4aaad5d4a18eb58103c3aac4bd0ba19d3acb1844a61fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43b1bdb8a511f633f08a7cfd7dd2aebcc9f5910e6a3dff65bd354d8241f5d524ce7a0b959e7f66a894ee05259527434f37d0529fc3a9b5bc6fe0802c3fd07f3d
|
7
|
+
data.tar.gz: 7ce0e309eb35766a074bd5a702eb22156a0685a965a219a52045fd4e8c1f5a6f9244eb1394bbab72e7ab2d7fc28d7b3f9367c34f6e957b6b54946de7196dea85
|
data/README.md
CHANGED
@@ -2,10 +2,12 @@
|
|
2
2
|
## DynamoDB
|
3
3
|
This is an attempt at storing and querying geohash data in DynamoDB.
|
4
4
|
|
5
|
-
We store objects in DynamoDB, when we query, we look for a customizable number of stored items by zooming out exactly one level.
|
5
|
+
We store objects in DynamoDB, when we query, we look for a customizable number of stored items by zooming out exactly one level.
|
6
|
+
We return the objects in an attempt at the closest items first.
|
6
7
|
|
7
8
|
Items are searched as the following.
|
8
|
-
|
9
|
+
|
10
|
+
Given the lat, long we calculate a hash - assume 9x0qz. We go up one level to 9x0q and calculate all neighbouring hashes.
|
9
11
|
|
10
12
|
9x0p 9x0r 9x0x
|
11
13
|
9x0n 9x0q 9x0w => ["9x0q", "9x0r", "9x0x", "9x0w", "9x0t", "9x0m", "9x0j", "9x0n", "9x0p"]
|
data/lib/dynamodb_geo.rb
CHANGED
@@ -2,13 +2,14 @@ require 'dynamodb_manager'
|
|
2
2
|
|
3
3
|
module DynamodbGeo
|
4
4
|
class << self
|
5
|
-
def new(region:, table_name:, access_key_id: nil, secret_access_key: nil, profile_name: 'default')
|
5
|
+
def new(region:, table_name:, access_key_id: nil, secret_access_key: nil, profile_name: 'default', endpoint: nil)
|
6
6
|
DynamodbManager.new(
|
7
|
-
region:
|
8
|
-
access_key_id:
|
7
|
+
region: region,
|
8
|
+
access_key_id: access_key_id,
|
9
9
|
secret_access_key: secret_access_key,
|
10
|
-
profile_name:
|
11
|
-
table_name:
|
10
|
+
profile_name: profile_name,
|
11
|
+
table_name: table_name,
|
12
|
+
endpoint: endpoint
|
12
13
|
)
|
13
14
|
end
|
14
15
|
end
|
data/lib/dynamodb_geo/version.rb
CHANGED
data/lib/dynamodb_manager.rb
CHANGED
@@ -4,7 +4,7 @@ require 'store'
|
|
4
4
|
|
5
5
|
class DynamodbManager
|
6
6
|
attr_accessor :client, :table_name, :hash_key, :range_key, :geohash_key, :geojson, :geohash_index, :hash_key_length, :local_area_size, :max_item_return
|
7
|
-
def initialize(region:, table_name:, access_key_id: nil, secret_access_key: nil, profile_name: 'default')
|
7
|
+
def initialize(region:, table_name:, access_key_id: nil, secret_access_key: nil, profile_name: 'default', endpoint: nil)
|
8
8
|
if access_key_id.nil? && secret_access_key.nil?
|
9
9
|
access_key_id = ENV['AWS_ACCESS_KEY_ID']
|
10
10
|
secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
|
@@ -23,10 +23,18 @@ class DynamodbManager
|
|
23
23
|
@local_area_size = 5
|
24
24
|
@max_item_return = 10
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
if endpoint
|
27
|
+
@client = Aws::DynamoDB::Client.new(
|
28
|
+
region: region,
|
29
|
+
credentials: credentials,
|
30
|
+
endpoint: endpoint
|
31
|
+
)
|
32
|
+
else
|
33
|
+
@client = Aws::DynamoDB::Client.new(
|
34
|
+
region: region,
|
35
|
+
credentials: credentials,
|
36
|
+
)
|
37
|
+
end
|
30
38
|
end
|
31
39
|
|
32
40
|
def table
|
@@ -48,7 +56,7 @@ class DynamodbManager
|
|
48
56
|
phone: store.phone,
|
49
57
|
name: store.name,
|
50
58
|
}
|
51
|
-
put_point(hash, json)
|
59
|
+
put_point(hash, json, store.uuid)
|
52
60
|
end
|
53
61
|
|
54
62
|
def get_stores(lat, long)
|
@@ -61,7 +69,28 @@ class DynamodbManager
|
|
61
69
|
neighbours.each do |neighbour|
|
62
70
|
resp = query(neighbour)
|
63
71
|
resp.items.each do |item|
|
64
|
-
|
72
|
+
latitude = item[@geojson]['latitude']
|
73
|
+
longitude = item[@geojson]['longitude']
|
74
|
+
address = item[@geojson]['address']
|
75
|
+
city = item[@geojson]['city']
|
76
|
+
state = item[@geojson]['state']
|
77
|
+
zip = item[@geojson]['zip']
|
78
|
+
area_code = item[@geojson]['area_code']
|
79
|
+
phone = item[@geojson]['phone']
|
80
|
+
name = item[@geojson]['name']
|
81
|
+
geohash = item[@geohash_key]
|
82
|
+
all_stores << Store.new(
|
83
|
+
latitude: latitude,
|
84
|
+
longitude: longitude,
|
85
|
+
address: address,
|
86
|
+
city: city,
|
87
|
+
state: state,
|
88
|
+
zip: zip,
|
89
|
+
area_code: area_code,
|
90
|
+
phone: phone,
|
91
|
+
name: name,
|
92
|
+
geohash: geohash
|
93
|
+
)
|
65
94
|
end
|
66
95
|
break if all_stores.length >= max_item_return
|
67
96
|
end
|
@@ -89,8 +118,8 @@ class DynamodbManager
|
|
89
118
|
})
|
90
119
|
end
|
91
120
|
|
92
|
-
def put_point(hash, json)
|
93
|
-
uuid
|
121
|
+
def put_point(hash, json, uuid = nil)
|
122
|
+
uuid ||= SecureRandom.uuid
|
94
123
|
|
95
124
|
@client.put_item({
|
96
125
|
table_name: @table_name,
|
data/lib/store.rb
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
class Store
|
2
|
-
attr_accessor :lat, :long, :address, :city, :state, :zip, :area_code, :phone, :name, :geohash
|
2
|
+
attr_accessor :lat, :long, :address, :city, :state, :zip, :area_code, :phone, :name, :geohash, :uuid
|
3
3
|
def initialize(store_data)
|
4
|
-
@lat = store_data[
|
5
|
-
@long = store_data[
|
6
|
-
@address = store_data[
|
7
|
-
@city = store_data[
|
8
|
-
@state = store_data[
|
9
|
-
@zip = store_data[
|
10
|
-
@area_code = store_data[
|
11
|
-
@phone = store_data[
|
12
|
-
@name = store_data[
|
13
|
-
@geohash = store_data[
|
4
|
+
@lat = store_data[:latitude]
|
5
|
+
@long = store_data[:longitude]
|
6
|
+
@address = store_data[:address]
|
7
|
+
@city = store_data[:city]
|
8
|
+
@state = store_data[:state]
|
9
|
+
@zip = store_data[:zip]
|
10
|
+
@area_code = store_data[:area_code]
|
11
|
+
@phone = store_data[:phone]
|
12
|
+
@name = store_data[:name]
|
13
|
+
@geohash = store_data[:geohash] || Geohash.encode(lat, long, 10)
|
14
|
+
@uuid = store_data[:uuid]
|
14
15
|
end
|
15
16
|
end
|
data/spec/dynamodb_geo_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dynamodb_geo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Ahn
|
@@ -127,7 +127,7 @@ requirements: []
|
|
127
127
|
rubygems_version: 3.1.2
|
128
128
|
signing_key:
|
129
129
|
specification_version: 4
|
130
|
-
summary: dynamodb_geo-0.1.
|
130
|
+
summary: dynamodb_geo-0.1.6
|
131
131
|
test_files:
|
132
132
|
- spec/dynamodb_geo_spec.rb
|
133
133
|
- spec/geohash_spec.rb
|