Sha256: 0fd014814955a7e0e9cabb1c2448d7606b117ff426ba06d1f88e0db0ede562d2

Contents?: true

Size: 1.11 KB

Versions: 2

Compression:

Stored size: 1.11 KB

Contents

<% cache(cache_key_for_questionnaires) do %>
<%= "id\tapps" %>
<%
counties = {}
amount = 1
@schools.each do |school|
  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?
      redo
    end

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

    resp = HTTParty.get("https://geo.fcc.gov/api/census/area?lat=#{lat}&lon=#{lng}&format=json")
    results = resp.parsed_response["results"]
    next if results.blank?

    fips = results[0]["county_fips"]
    next if fips.blank?

    Fips.create(fips_code: fips, city: school.city, state: school.state)
  else
    fips = school.fips_code.fips_code
  end

  counties[fips] ||= 0
  counties[fips] += amount * school.questionnaire_count
end

output = ""
counties.each do |county, value|
  output += "#{county}\t#{value}\n"
end %>
<%= output %>
<% end %>

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hackathon_manager-0.7.1 app/views/manage/dashboard/map_data.tsv.erb
hackathon_manager-0.7.0 app/views/manage/dashboard/map_data.tsv.erb