mirror of
https://github.com/System-End/theseus.git
synced 2026-04-19 16:38:18 +00:00
fallback to known city/state on nx usps facility xlsx entry
This commit is contained in:
parent
d40051675f
commit
4f5111a00c
3 changed files with 24 additions and 6 deletions
|
|
@ -60,7 +60,7 @@ class Public::UpdateMapDataJob < ApplicationJob
|
|||
hydrated = event.hydrated
|
||||
locale_key = hydrated.scan_locale_key
|
||||
if locale_key.present?
|
||||
coords = geocode_usps_facility(locale_key)
|
||||
coords = geocode_usps_facility(locale_key, event)
|
||||
coordinates << coords if coords
|
||||
end
|
||||
rescue => e
|
||||
|
|
@ -105,8 +105,8 @@ class Public::UpdateMapDataJob < ApplicationJob
|
|||
}
|
||||
end
|
||||
|
||||
def geocode_usps_facility(locale_key)
|
||||
result = GeocodingService::USPSFacilities.coords_for_locale_key(locale_key)
|
||||
def geocode_usps_facility(locale_key, event)
|
||||
result = GeocodingService::USPSFacilities.coords_for_locale_key(locale_key, event)
|
||||
return nil unless result
|
||||
|
||||
{
|
||||
|
|
|
|||
|
|
@ -48,6 +48,8 @@ module GeocodingService
|
|||
end
|
||||
|
||||
def hackclub_geocode(params)
|
||||
return nil if params.nil?
|
||||
|
||||
Rails.logger.info "Hack Club Geocoding: #{params}"
|
||||
|
||||
address_components = []
|
||||
|
|
|
|||
|
|
@ -8,11 +8,27 @@ module GeocodingService
|
|||
},
|
||||
}
|
||||
|
||||
def coords_for_locale_key(locale_key)
|
||||
def coords_for_locale_key(locale_key, event = nil)
|
||||
SPECIAL_CASES[locale_key] ||
|
||||
Rails.cache.fetch("geocode_usps_facility_#{locale_key}", expires_in: 1.day) do
|
||||
GeocodingService.first_hit(address_for_locale_key(locale_key)) ||
|
||||
GeocodingService.first_hit(address_for_locale_key(locale_key).slice(:city, :state, :postalcode, :country))
|
||||
address = address_for_locale_key(locale_key)
|
||||
if address
|
||||
GeocodingService.first_hit(address) ||
|
||||
GeocodingService.first_hit(address.slice(:city, :state, :postalcode, :country))
|
||||
elsif event
|
||||
# Fallback to event scan facility data when USPS facility lookup fails
|
||||
facility = event.scan_facility
|
||||
fallback_address = {
|
||||
city: facility[:city],
|
||||
state: facility[:state],
|
||||
postalcode: facility[:zip],
|
||||
country: "US",
|
||||
}
|
||||
Rails.logger.warn "USPS facility not found for locale_key #{locale_key}, falling back to scan facility data: #{fallback_address}"
|
||||
GeocodingService.first_hit(fallback_address)
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue