eaternet 1.0.4 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Guardfile +1 -1
- data/README.md +6 -5
- data/lib/eaternet.rb +5 -0
- data/lib/eaternet/agencies/austin.rb +105 -0
- data/lib/eaternet/agencies/nyc.rb +1 -9
- data/lib/eaternet/lives_1_0/adapter.rb +2 -2
- data/lib/eaternet/lives_1_0/csv_parser.rb +6 -0
- data/lib/eaternet/socrata.rb +7 -0
- data/lib/eaternet/version.rb +1 -1
- data/test/eaternet/agencies/austin_test.rb +82 -0
- data/test/fixtures/austin.csv +56 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c5fc04785f93aff0b3300b78b1b66b4b1dca9e7
|
4
|
+
data.tar.gz: 6fc295109586d5d5e9a04376d692c1ffa172fd46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41310f9717ff94054e7bc171857bac46d218737a8c0429473958542b98a4dcbaff8b1f0535ca14aaf883a22e951f3718d4e61c879852a3c4398f738c07fdc394
|
7
|
+
data.tar.gz: 15d68d3206700ced17e5df1cf37a5f386cce7136d21f7ec8184c9f44a91cc14fd20676241cd95a086e5ca623c99bb579543024c38fe805574b891b9f73d44aa6
|
data/Guardfile
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
## Uncomment to clear the screen before every task
|
8
8
|
clearing :on
|
9
|
-
guard :minitest do
|
9
|
+
guard :minitest, all_after_pass: true do
|
10
10
|
watch(%r{^test/(.*)_test\.rb$})
|
11
11
|
watch(%r{^lib/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" }
|
12
12
|
watch(%r{^test/test_helper\.rb$}) { 'test' }
|
data/README.md
CHANGED
@@ -16,12 +16,13 @@ information daily on our website.
|
|
16
16
|
|
17
17
|
## Available Adapters
|
18
18
|
|
19
|
-
| Area
|
20
|
-
|
21
|
-
|
|
22
|
-
|
|
19
|
+
| Area | Agency | Ruby Class | Notes |
|
20
|
+
|--------------------|--------------------------------------|------------|-----------|
|
21
|
+
| Austin, TX | City of Austin | `Austin` | [Development has started](https://github.com/eaternet/adapters-ruby/pull/43) |
|
22
|
+
| Las Vegas | Southern Nevada Health District | [`Snhd`](https://github.com/eaternet/adapters-ruby/blob/master/lib/eaternet/agencies/snhd.rb) | Needs refactoring and docs |
|
23
|
+
| New York City | City of New York Health Department | [`Nyc`](https://github.com/eaternet/adapters-ruby/blob/master/lib/eaternet/agencies/nyc.rb) | [Dataset wiki page](https://github.com/eaternet/adapters/wiki/Agency:-New-York-City) |
|
23
24
|
| Portland, OR, USA | Multnomah Couty Environmental Health | [`Multco`](https://github.com/eaternet/adapters-ruby/blob/master/lib/eaternet/agencies/multco.rb) | Deprecated. Needs to be updated to use the Accela API |
|
24
|
-
| San Francisco
|
25
|
+
| San Francisco | City of San Francisco | [`Sf`](https://github.com/eaternet/adapters-ruby/blob/master/lib/eaternet/agencies/sf.rb) | Needs docs |
|
25
26
|
|
26
27
|
|
27
28
|
## Usage
|
data/lib/eaternet.rb
CHANGED
@@ -2,16 +2,21 @@ require 'eaternet/agencies/multco'
|
|
2
2
|
require 'eaternet/agencies/nyc'
|
3
3
|
require 'eaternet/agencies/sf'
|
4
4
|
require 'eaternet/agencies/snhd'
|
5
|
+
require 'eaternet/agencies/austin'
|
5
6
|
|
6
7
|
module Eaternet
|
7
8
|
# Make the actual adapters easily available
|
8
9
|
# to the application-level as:
|
9
10
|
#
|
11
|
+
# * `Eaternet::Austin` — Austin, TX
|
10
12
|
# * `Eaternet::Nyc` – New York City
|
11
13
|
# * `Eaternet::Sf` - San Francisco
|
12
14
|
# * `Eaternet::Snhd` — Las Vegas area
|
13
15
|
# * `Eaternet::Multco` — Portland area, Oregon, USA
|
14
16
|
include Eaternet::Agencies
|
17
|
+
|
18
|
+
class UnsupportedError < StandardError
|
19
|
+
end
|
15
20
|
end
|
16
21
|
|
17
22
|
Zip.warn_invalid_date = false if ENV['RUBYZIP_NO_WARN_INVALID_DATE']
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'eaternet/socrata'
|
2
|
+
|
3
|
+
module Eaternet
|
4
|
+
module Agencies
|
5
|
+
|
6
|
+
# @see https://data.austintexas.gov/dataset/Restaurant-Inspection-Scores/ecmv-9xxi
|
7
|
+
class Austin < Eaternet::Lives_1_0::Adapter
|
8
|
+
include Eaternet::Loggable
|
9
|
+
include Eaternet::Lives_1_0::CsvParser
|
10
|
+
|
11
|
+
# Create an Austin data-source, ready for querying.
|
12
|
+
#
|
13
|
+
# @example
|
14
|
+
# austin = Eaternet::Austin.new
|
15
|
+
#
|
16
|
+
# @param [String] csv_path for unit testing
|
17
|
+
def initialize(csv_path: nil)
|
18
|
+
@table_file = csv_path
|
19
|
+
end
|
20
|
+
|
21
|
+
# @example Print the number of restaurants in the city.
|
22
|
+
# puts austin.businesses.count
|
23
|
+
#
|
24
|
+
# @return [Enumerable<Business>]
|
25
|
+
def businesses
|
26
|
+
map_csv { |row| try_to_create(:business, from_csv_row: row) }
|
27
|
+
.uniq
|
28
|
+
.compact
|
29
|
+
end
|
30
|
+
|
31
|
+
def inspections
|
32
|
+
map_csv { |row| try_to_create(:inspection, from_csv_row: row) }
|
33
|
+
.compact
|
34
|
+
end
|
35
|
+
|
36
|
+
def violations
|
37
|
+
raise Eaternet::UnsupportedError.new(
|
38
|
+
'The city of Austin does not publish violation data'
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
def legends
|
43
|
+
raise Eaternet::UnsupportedError.new(
|
44
|
+
'The city of Austin does not assign letter grades'
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
48
|
+
def feed_info
|
49
|
+
Eaternet::Lives_1_0::FeedInfo.new do |fi|
|
50
|
+
fi.feed_date = Date.today
|
51
|
+
fi.feed_version = '1.0'
|
52
|
+
fi.municipality_name = 'Austin'
|
53
|
+
fi.municipality_url = 'http://www.austintexas.gov/department/health'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
def inspection(row)
|
60
|
+
Eaternet::Lives_1_0::Inspection.new do |i|
|
61
|
+
i.business_id = row['Facility ID']
|
62
|
+
i.date = Date.strptime(row['Inspection Date'], '%m/%d/%Y')
|
63
|
+
i.score = row['Score'].to_i
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def business(row)
|
68
|
+
Eaternet::Lives_1_0::Business.new do |b|
|
69
|
+
fail ArgumentError, 'No address found' if row['Address'].nil?
|
70
|
+
|
71
|
+
# Address is a multi-line, multi-value cell
|
72
|
+
address_lines = row['Address'].split("\n")
|
73
|
+
address = address_lines.first
|
74
|
+
city = address_lines[1].split(',').first
|
75
|
+
|
76
|
+
b.business_id = row['Facility ID']
|
77
|
+
b.name = row['Restaurant Name']
|
78
|
+
b.address = address
|
79
|
+
b.city = city
|
80
|
+
b.postal_code = row['Zip Code']
|
81
|
+
b.state = 'TX'
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
def table_file
|
88
|
+
@table_file ||= Austin.download_via_url
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.download_via_url
|
92
|
+
Eaternet::Util.download_and_cache(source: csv_url, dest: Tempfile.new('austin'))
|
93
|
+
end
|
94
|
+
|
95
|
+
def self.csv_url
|
96
|
+
Eaternet::Socrata.csv_url domain: 'data.austintexas.gov', dataset: 'ecmv-9xxi'
|
97
|
+
end
|
98
|
+
|
99
|
+
def adapter_name
|
100
|
+
'Austin'
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -192,12 +192,6 @@ module Eaternet
|
|
192
192
|
end
|
193
193
|
end
|
194
194
|
|
195
|
-
def map_csv(&row_handler)
|
196
|
-
CSV.new(File.open(table_file, encoding: 'utf-8'), headers: true)
|
197
|
-
.lazy
|
198
|
-
.map { |row| row_handler.call(row) }
|
199
|
-
end
|
200
|
-
|
201
195
|
def table_file
|
202
196
|
@table_file ||= Nyc.download_via_url
|
203
197
|
end
|
@@ -209,9 +203,7 @@ module Eaternet
|
|
209
203
|
end
|
210
204
|
|
211
205
|
def self.csv_url
|
212
|
-
domain
|
213
|
-
dataset = 'xx67-kt59'
|
214
|
-
"https://#{domain}/api/views/#{dataset}/rows.csv?accessType=DOWNLOAD"
|
206
|
+
Eaternet::Socrata.csv_url domain: 'data.cityofnewyork.us', dataset: 'xx67-kt59'
|
215
207
|
end
|
216
208
|
|
217
209
|
def adapter_name
|
@@ -11,7 +11,7 @@ module Eaternet
|
|
11
11
|
# @required Yes
|
12
12
|
# @return [Enumerable<Business>]
|
13
13
|
def businesses
|
14
|
-
fail 'Override
|
14
|
+
fail 'Override Adapter#businesses to return an Enumerable of Business'
|
15
15
|
end
|
16
16
|
|
17
17
|
# @example Compute the average inspection score for SomeCity.
|
@@ -26,7 +26,7 @@ module Eaternet
|
|
26
26
|
# @required Yes
|
27
27
|
# @return [Enumerable<Inspection>]
|
28
28
|
def inspections
|
29
|
-
fail 'Override
|
29
|
+
fail 'Override Adapter#inspections to return an Enumerable of Inspection'
|
30
30
|
end
|
31
31
|
|
32
32
|
# @required No
|
@@ -14,6 +14,12 @@ module Eaternet
|
|
14
14
|
csv_map(csv) { |row| try_to_create to_type, from_csv_row: row }
|
15
15
|
end
|
16
16
|
|
17
|
+
def map_csv(&row_handler)
|
18
|
+
CSV.new(File.open(table_file, encoding: 'utf-8'), headers: true)
|
19
|
+
.lazy
|
20
|
+
.map { |row| row_handler.call(row) }
|
21
|
+
end
|
22
|
+
|
17
23
|
def csv_map(filename, &block)
|
18
24
|
csv_rows(filename).lazy.map { |row| block.call(row) }
|
19
25
|
end
|
data/lib/eaternet/version.rb
CHANGED
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
require 'eaternet'
|
4
|
+
require 'eaternet/lives_1_0'
|
5
|
+
|
6
|
+
AUSTIN_CSV = 'test/fixtures/austin.csv'
|
7
|
+
|
8
|
+
class AustinAdapterTest < Minitest::Test
|
9
|
+
@@agency = Eaternet::Austin.new(csv_path: AUSTIN_CSV)
|
10
|
+
|
11
|
+
#
|
12
|
+
# Businesses
|
13
|
+
#
|
14
|
+
|
15
|
+
def test_businesses_returns_an_enumerator_of_business
|
16
|
+
assert enumerable_of? Eaternet::Lives_1_0::Business, @@agency.businesses
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_businesses_returns_lives_attributes
|
20
|
+
b = @@agency.businesses.first
|
21
|
+
assert_equal '2801033', b.business_id
|
22
|
+
assert_equal '15th Street Cafe', b.name
|
23
|
+
assert_equal '303 W 15TH ST', b.address
|
24
|
+
assert_equal 'AUSTIN', b.city
|
25
|
+
assert_equal '78701', b.postal_code
|
26
|
+
assert_equal 'TX', b.state
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_businesses_returns_correct_city
|
30
|
+
b = @@agency.businesses.to_a[2]
|
31
|
+
assert_equal 'BUDA', b.city
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_businesses_returns_unique_rows
|
35
|
+
assert_equal 3, @@agency.businesses.to_a.size
|
36
|
+
end
|
37
|
+
|
38
|
+
#
|
39
|
+
# Inspections
|
40
|
+
#
|
41
|
+
|
42
|
+
def test_inspections_returns_an_enumerable_of_inspection
|
43
|
+
assert enumerable_of? Eaternet::Lives_1_0::Inspection, @@agency.inspections
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_inspections_returns_correct_attributes
|
47
|
+
i = @@agency.inspections.first
|
48
|
+
assert_equal '2801033', i.business_id
|
49
|
+
assert_equal Date.new(2015, 5, 13), i.date
|
50
|
+
assert_equal 97, i.score
|
51
|
+
end
|
52
|
+
|
53
|
+
#
|
54
|
+
# Violations
|
55
|
+
#
|
56
|
+
|
57
|
+
def test_violations_raises_an_unsupported_error
|
58
|
+
assert_raises(Eaternet::UnsupportedError) { @@agency.violations }
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_violations_raises_an_error_with_a_message
|
62
|
+
begin
|
63
|
+
@@agency.violations
|
64
|
+
rescue => e
|
65
|
+
assert_match /does not/, e.to_s
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
# #
|
71
|
+
# # metadata
|
72
|
+
# #
|
73
|
+
#
|
74
|
+
def test_implements_feed_info
|
75
|
+
assert_instance_of Eaternet::Lives_1_0::FeedInfo, @@agency.feed_info
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_legends_raises_an_unsupported_error
|
79
|
+
assert_raises(Eaternet::UnsupportedError) { @@agency.legends }
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
Restaurant Name,Zip Code,Inspection Date,Score,Address,Facility ID,Process Description
|
2
|
+
15th Street Cafe,78701,05/13/2015,97,"303 W 15TH ST
|
3
|
+
AUSTIN, TX 78701
|
4
|
+
(30.277553492000038, -97.74209889799994)",2801033,Routine Inspection
|
5
|
+
15th Street Cafe,78701,05/22/2013,91,"303 W 15TH ST
|
6
|
+
AUSTIN, TX 78701
|
7
|
+
(30.277553492000038, -97.74209889799994)",2801033,Routine Inspection
|
8
|
+
15th Street Cafe,78701,06/18/2014,97,"303 W 15TH ST
|
9
|
+
AUSTIN, TX 78701
|
10
|
+
(30.277553492000038, -97.74209889799994)",2801033,Routine Inspection
|
11
|
+
15th Street Cafe,78701,12/02/2014,93,"303 W 15TH ST
|
12
|
+
AUSTIN, TX 78701
|
13
|
+
(30.277553492000038, -97.74209889799994)",2801033,Routine Inspection
|
14
|
+
15th Street Cafe,78701,09/13/2012,93,"303 W 15TH ST
|
15
|
+
AUSTIN, TX 78701
|
16
|
+
(30.277553492000038, -97.74209889799994)",2801033,Routine Inspection
|
17
|
+
15th Street Cafe,78701,12/05/2013,97,"303 W 15TH ST
|
18
|
+
AUSTIN, TX 78701
|
19
|
+
(30.277553492000038, -97.74209889799994)",2801033,Routine Inspection
|
20
|
+
1st Food Mart,78704,02/09/2015,94,"1410 S 1ST ST
|
21
|
+
AUSTIN, TX 78704
|
22
|
+
(30.25030317900007, -97.75485926699997)",10677646,Routine Inspection
|
23
|
+
1st Food Mart,78704,02/14/2013,97,"1410 S 1ST ST
|
24
|
+
AUSTIN, TX 78704
|
25
|
+
(30.25030317900007, -97.75485926699997)",10677646,Routine Inspection
|
26
|
+
1st Food Mart,78704,07/26/2012,97,"1410 S 1ST ST
|
27
|
+
AUSTIN, TX 78704
|
28
|
+
(30.25030317900007, -97.75485926699997)",10677646,Routine Inspection
|
29
|
+
1st Food Mart,78704,01/16/2014,90,"1410 S 1ST ST
|
30
|
+
AUSTIN, TX 78704
|
31
|
+
(30.25030317900007, -97.75485926699997)",10677646,Routine Inspection
|
32
|
+
1st Food Mart,78704,06/17/2013,100,"1410 S 1ST ST
|
33
|
+
AUSTIN, TX 78704
|
34
|
+
(30.25030317900007, -97.75485926699997)",10677646,Routine Inspection
|
35
|
+
1st Food Mart,78704,07/29/2014,90,"1410 S 1ST ST
|
36
|
+
AUSTIN, TX 78704
|
37
|
+
(30.25030317900007, -97.75485926699997)",10677646,Routine Inspection
|
38
|
+
Austin Recovery,78610,06/05/2015,100,"13207 WRIGHT ROAD
|
39
|
+
BUDA, TX 78610
|
40
|
+
(30.084734110000056, -97.75172505999996)",10774078,Routine Inspection
|
41
|
+
Austin Recovery,78610,10/09/2014,95,"13207 WRIGHT ROAD
|
42
|
+
BUDA, TX 78610
|
43
|
+
(30.084734110000056, -97.75172505999996)",10774078,Routine Inspection
|
44
|
+
Austin Recovery,78610,09/13/2013,96,"13207 WRIGHT ROAD
|
45
|
+
BUDA, TX 78610
|
46
|
+
(30.084734110000056, -97.75172505999996)",10774078,Routine Inspection
|
47
|
+
Austin Recovery,78610,05/01/2014,97,"13207 WRIGHT ROAD
|
48
|
+
BUDA, TX 78610
|
49
|
+
(30.084734110000056, -97.75172505999996)",10774078,Routine Inspection
|
50
|
+
Austin Recovery,78610,02/13/2015,100,"13207 WRIGHT ROAD
|
51
|
+
BUDA, TX 78610
|
52
|
+
(30.084734110000056, -97.75172505999996)",10774078,Routine Inspection
|
53
|
+
Austin Recovery,78610,02/27/2013,92,"13207 WRIGHT ROAD
|
54
|
+
BUDA, TX 78610
|
55
|
+
(30.084734110000056, -97.75172505999996)",10774078,Routine Inspection
|
56
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eaternet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robb Shecter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -239,6 +239,7 @@ files:
|
|
239
239
|
- Rakefile
|
240
240
|
- eaternet.gemspec
|
241
241
|
- lib/eaternet.rb
|
242
|
+
- lib/eaternet/agencies/austin.rb
|
242
243
|
- lib/eaternet/agencies/multco.rb
|
243
244
|
- lib/eaternet/agencies/multco_lib/misc.rb
|
244
245
|
- lib/eaternet/agencies/nyc.rb
|
@@ -257,10 +258,12 @@ files:
|
|
257
258
|
- lib/eaternet/lives_1_0/violation.rb
|
258
259
|
- lib/eaternet/loggable.rb
|
259
260
|
- lib/eaternet/prototype.rb
|
261
|
+
- lib/eaternet/socrata.rb
|
260
262
|
- lib/eaternet/util.rb
|
261
263
|
- lib/eaternet/validated_object.rb
|
262
264
|
- lib/eaternet/version.rb
|
263
265
|
- lib/ext/enumerator.rb
|
266
|
+
- test/eaternet/agencies/austin_test.rb
|
264
267
|
- test/eaternet/agencies/multco_test.rb
|
265
268
|
- test/eaternet/agencies/nyc_test.rb
|
266
269
|
- test/eaternet/agencies/sf_test.rb
|
@@ -274,6 +277,7 @@ files:
|
|
274
277
|
- test/eaternet/loggable_test.rb
|
275
278
|
- test/eaternet/util_test.rb
|
276
279
|
- test/ext/enumerator_test.rb
|
280
|
+
- test/fixtures/austin.csv
|
277
281
|
- test/fixtures/nyc.csv
|
278
282
|
- test/script.rb
|
279
283
|
- test/test_helper.rb
|
@@ -302,6 +306,7 @@ signing_key:
|
|
302
306
|
specification_version: 4
|
303
307
|
summary: Regional adapters for restaurant health scores
|
304
308
|
test_files:
|
309
|
+
- test/eaternet/agencies/austin_test.rb
|
305
310
|
- test/eaternet/agencies/multco_test.rb
|
306
311
|
- test/eaternet/agencies/nyc_test.rb
|
307
312
|
- test/eaternet/agencies/sf_test.rb
|
@@ -315,6 +320,7 @@ test_files:
|
|
315
320
|
- test/eaternet/loggable_test.rb
|
316
321
|
- test/eaternet/util_test.rb
|
317
322
|
- test/ext/enumerator_test.rb
|
323
|
+
- test/fixtures/austin.csv
|
318
324
|
- test/fixtures/nyc.csv
|
319
325
|
- test/script.rb
|
320
326
|
- test/test_helper.rb
|