Skip to content

Commit 30e3a2f

Browse files
authored
fix(dashboard): Switches map to use different geocoder, reenables map (#224)
* fix(dashboard): Switches map to use different geocoder, reenables map * fix(dashboard): Fixes map test * fix(dashboard): Simplifies New York for map test * fix(dashboard): Fixes Hound issues
1 parent c119c9a commit 30e3a2f

File tree

4 files changed

+19
-17
lines changed

4 files changed

+19
-17
lines changed

app/controllers/manage/dashboard_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def index
66
end
77

88
def map_data
9-
@schools = School.where("questionnaire_count", 1..Float::INFINITY).select([:city, :state, :questionnaire_count])
9+
@schools = School.where("questionnaire_count", 1..Float::INFINITY).select([:name, :address, :city, :state, :questionnaire_count])
1010
end
1111

1212
def todays_activity_data

app/views/manage/dashboard/index.html.haml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@
1111

1212
= render "layouts/manage/page_title", title: "Dashboard"
1313

14-
-#
15-
.row
16-
.col
17-
#map
18-
:javascript
19-
$('#map').initMap();
14+
.row
15+
.col
16+
#map
17+
:javascript
18+
$('#map').initMap();
2019

2120
.row
2221
.col-7

app/views/manage/dashboard/map_data.tsv.erb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,22 @@ redo_limit = 10
99
if school.fips_code.blank?
1010
next if school.city.blank? || school.state.blank?
1111

12-
resp = HTTParty.get("https://maps.googleapis.com/maps/api/geocode/json?address=#{CGI.escape(school.city)}+#{CGI.escape(school.state)}&sensor=true")
13-
results = resp.parsed_response["results"][0]
14-
if results.blank?
12+
resp = HTTParty.get("https://geocoding.geo.census.gov/geocoder/locations/address?street=#{CGI.escape(school.address)}&city=#{CGI.escape(school.city)}&state=#{CGI.escape(school.state)}&benchmark=Public_AR_Current&format=json")
13+
result = resp.parsed_response["result"]
14+
if result.blank?
1515
if redo_count >= redo_limit
16-
raise 'Exceeded maximum number of retries: No results from Google Maps API.'
16+
raise 'Exceeded maximum number of retries: No results from Census.gov.'
1717
end
1818
redo_count += 1
1919
redo
2020
end
2121
redo_count = 0
2222

23-
lat = results["geometry"]["location"]["lat"]
24-
lng = results["geometry"]["location"]["lng"]
23+
addressMatches = result["addressMatches"]
24+
next if addressMatches.blank?
25+
26+
lat = result["addressMatches"][0]["coordinates"]["x"]
27+
lng = result["addressMatches"][0]["coordinates"]["y"]
2528
next if lat.blank? || lng.blank?
2629

2730
resp = HTTParty.get("https://geo.fcc.gov/api/census/area?lat=#{lat}&lon=#{lng}&format=json")

test/controllers/manage/dashboard_controller_test.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ class Manage::DashboardControllerTest < ActionController::TestCase
4545
FactoryBot.create_list(:questionnaire, 1, school_id: school2.id, acc_status: status)
4646
end
4747

48-
stub_request(:get, "https://maps.googleapis.com/maps/api/geocode/json?address=Rochester%20NY&sensor=true").
49-
to_return(status: 200, body: '{"results":[{"geometry":{"location":{"lat": 100, "lng": 100}}}]}', headers: {'Content-Type' => 'application/json; charset=UTF-8'})
50-
stub_request(:get, "https://geo.fcc.gov/api/census/area?format=json&lat=100&lon=100").
51-
to_return(status: 200, body: '{"results":[{"country_fips":1234}]}', headers: {'Content-Type' => 'application/json; charset=UTF-8'})
48+
stub_request(:get, "https://geocoding.geo.census.gov/geocoder/locations/address?street=123+Fake+Street&city=Rochester&state=NY&benchmark=Public_AR_Current&format=json")
49+
.to_return(status: 200, body: '{ "result":{ "addressMatches":[{ "coordinates":{ "x": 100, "y": 100 } }] } }', headers: { 'Content-Type' => 'application/json; charset=UTF-8' })
50+
stub_request(:get, "https://geo.fcc.gov/api/census/area?format=json&lat=100&lon=100")
51+
.to_return(status: 200, body: '{ "results":[{ "country_fips":1234 }] }', headers: { 'Content-Type' => 'application/json; charset=UTF-8' })
5252

5353
paths = [
5454
:todays_activity_data,

0 commit comments

Comments
 (0)