Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/manage/dashboard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def index
end

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

def todays_activity_data
Expand Down
11 changes: 5 additions & 6 deletions app/views/manage/dashboard/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@

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

-#
.row
.col
#map
:javascript
$('#map').initMap();
.row
.col
#map
:javascript
$('#map').initMap();

.row
.col-7
Expand Down
15 changes: 9 additions & 6 deletions app/views/manage/dashboard/map_data.tsv.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,22 @@ redo_limit = 10
if school.fips_code.blank?
next if school.city.blank? || school.state.blank?

resp = HTTParty.get("https://maps.googleapis.com/maps/api/geocode/json?address=#{CGI.escape(school.city)}+#{CGI.escape(school.state)}&sensor=true")
results = resp.parsed_response["results"][0]
if results.blank?
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")
result = resp.parsed_response["result"]
if result.blank?
if redo_count >= redo_limit
raise 'Exceeded maximum number of retries: No results from Google Maps API.'
raise 'Exceeded maximum number of retries: No results from Census.gov.'
end
redo_count += 1
redo
end
redo_count = 0

lat = results["geometry"]["location"]["lat"]
lng = results["geometry"]["location"]["lng"]
addressMatches = result["addressMatches"]
next if addressMatches.blank?

lat = result["addressMatches"][0]["coordinates"]["x"]
lng = result["addressMatches"][0]["coordinates"]["y"]
next if lat.blank? || lng.blank?

resp = HTTParty.get("https://geo.fcc.gov/api/census/area?lat=#{lat}&lon=#{lng}&format=json")
Expand Down
8 changes: 4 additions & 4 deletions test/controllers/manage/dashboard_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ class Manage::DashboardControllerTest < ActionController::TestCase
FactoryBot.create_list(:questionnaire, 1, school_id: school2.id, acc_status: status)
end

stub_request(:get, "https://maps.googleapis.com/maps/api/geocode/json?address=Rochester%20NY&sensor=true").
to_return(status: 200, body: '{"results":[{"geometry":{"location":{"lat": 100, "lng": 100}}}]}', headers: {'Content-Type' => 'application/json; charset=UTF-8'})
stub_request(:get, "https://geo.fcc.gov/api/census/area?format=json&lat=100&lon=100").
to_return(status: 200, body: '{"results":[{"country_fips":1234}]}', headers: {'Content-Type' => 'application/json; charset=UTF-8'})
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")
.to_return(status: 200, body: '{ "result":{ "addressMatches":[{ "coordinates":{ "x": 100, "y": 100 } }] } }', headers: { 'Content-Type' => 'application/json; charset=UTF-8' })
stub_request(:get, "https://geo.fcc.gov/api/census/area?format=json&lat=100&lon=100")
.to_return(status: 200, body: '{ "results":[{ "country_fips":1234 }] }', headers: { 'Content-Type' => 'application/json; charset=UTF-8' })

paths = [
:todays_activity_data,
Expand Down