From cc18eb1eff490688fb297c849cb404927a680f33 Mon Sep 17 00:00:00 2001 From: Bryan Tanifum Date: Thu, 16 May 2024 13:44:27 -0400 Subject: [PATCH] Pulling in missing files from the HZ-API Cutover branch --- app/models/hubzone_util.rb | 30 +++++++++++++++++++++++++++++- app/models/us_county_assertion.rb | 23 +++++++++++++++++++++++ app/models/us_tract_assertion.rb | 22 ++++++++++++++++++++++ 3 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 app/models/us_county_assertion.rb create mode 100644 app/models/us_tract_assertion.rb diff --git a/app/models/hubzone_util.rb b/app/models/hubzone_util.rb index fef6e40..b05b016 100644 --- a/app/models/hubzone_util.rb +++ b/app/models/hubzone_util.rb @@ -101,7 +101,35 @@ def append_other_information(results) results[:other_information][:alerts][:likely_qda_designations] = likely_qda_designations if likely_qda_designations.present? # get congressional district - results[:other_information][:congressional_district] = congressional_district_assertion location || nil + #results[:other_information][:congressional_district] = congressional_district_assertion location || nil + + congressional_district = {} + %w[CensusCounty CensusTract CongressionalDistrict DistrictOffice].each do |assertion_type| + puts "\n==congressional_district=0" + hz_assertion = "#{assertion_type}Assertion".constantize + hz_v = hz_assertion.assertion location + puts "\n==congressional_district=1" + # puts defined(hz_v) + puts hz_v[0] + puts hz_v.class + puts hz_v.length + #results[:other_information][:congressional_district] += hz_assertion.assertion location + if hz_v.length>0 + puts "\n==congressional_district=3" + congressional_district = congressional_district.merge( hz_v[0] ) + end + end + puts "\n==congressional_district=" + + puts congressional_district + if congressional_district.length>0 + results[:other_information][:congressional_district] = [congressional_district] + else + results[:other_information][:congressional_district] = congressional_district_assertion location || nil + end + + + end # query the likley_qda view and append results diff --git a/app/models/us_county_assertion.rb b/app/models/us_county_assertion.rb new file mode 100644 index 0000000..0e52c61 --- /dev/null +++ b/app/models/us_county_assertion.rb @@ -0,0 +1,23 @@ + +# Allows for assertion of a location against the likely_qda HubZone layer +class UsCountyAssertion + extend AssertionHelper + + class << self + def assertion(location) + congressional_districts = [] + assertion_by_type('data.tl_2021_us_county', location).each do |cd| + puts "\n== query result US-county" + puts cd + cd['hz_type'] = 'us_county' + cd['tract_fips'] = cd['countyfp'] + cd['county'] =cd['namelsadco'] + cd['state'] = cd['state_name'] + cd['expires'] =nil + congressional_districts.push(cd) + end + congressional_districts + end + end + end + \ No newline at end of file diff --git a/app/models/us_tract_assertion.rb b/app/models/us_tract_assertion.rb new file mode 100644 index 0000000..cde9baf --- /dev/null +++ b/app/models/us_tract_assertion.rb @@ -0,0 +1,22 @@ + +# Allows for assertion of a location against the likely_qda HubZone layer +class UsTractAssertion + extend AssertionHelper + + class << self + def assertion(location) + congressional_districts = [] + assertion_by_type('data.tl_2021_us_tract', location).each do |cd| + puts "\n== query result US-Tract" + puts cd + cd['hz_type'] = 'us_tract' + cd['tract_fips'] = cd['countyfp'] + cd['county'] =cd['namelsadco'] + cd['state'] = cd['state_name'] + cd['expires'] =nil + congressional_districts.push(cd) + end + congressional_districts + end + end +end