us_geo 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -0
- data/VERSION +1 -1
- data/db/migrate/20251029215800_add_locale_name_to_zctas.rb +6 -0
- data/explorer_app/Gemfile +3 -3
- data/explorer_app/app/helpers/application_helper.rb +1 -1
- data/lib/tasks/us_geo/us_geo.rake +13 -9
- data/lib/us_geo/base_record.rb +11 -3
- data/lib/us_geo/county.rb +1 -1
- data/lib/us_geo/county_subdivision.rb +1 -1
- data/lib/us_geo/division.rb +1 -1
- data/lib/us_geo/place.rb +2 -2
- data/lib/us_geo/state.rb +2 -2
- data/lib/us_geo/urban_area.rb +1 -1
- data/lib/us_geo/zcta.rb +4 -5
- data/us_geo.gemspec +8 -0
- metadata +22 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: dceb63343a54560e873aa526e7be7e3990936674596c7983eb579a9921bea7bf
|
|
4
|
+
data.tar.gz: d2ccf2fd72f5363d77c29e6f39f288f2b9d9b569ea75dddd1ae5030615381994
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: df0c5cf5216e6eb926d6ffda006c003d7661790c4c3c10ee41c00a63342bc6ce2fb3e15fe081f5465c144c1fd06d28131d55af7b8273e1d89ec09d5f5cd5c4a9
|
|
7
|
+
data.tar.gz: 24e36f6a2af2c4b73853d8ab17a557c16faa04e8bf6e058f166defe1ac5dbfdd90cfe2ff7d8b828b9d8e8f34cbcfe51a3123d16e3004ba36239048bba45e012e
|
data/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,22 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## 2.2.0
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- Added places with `U6` FIPS classification. This adds more places in rural areas where not all settlements were previously included in the data set because they were not classified as places by the Census Bureau. These are places that are not incorporated and do not have many businesses or services, but are still recognized places where people live. These places do not have any demographic data associated with them since they are not included in the Census population estimates.
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
|
|
15
|
+
- Updated data set with 2023 population estimates from the Census Bureau.
|
|
16
|
+
|
|
17
|
+
## 2.1.1
|
|
18
|
+
|
|
19
|
+
### Fixed
|
|
20
|
+
|
|
21
|
+
- Made `belongs_to` associations on models optional so that you don't need to import the full data set in order to have valid records.
|
|
22
|
+
|
|
7
23
|
## 2.1.0
|
|
8
24
|
|
|
9
25
|
### Changed
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.
|
|
1
|
+
2.2.0
|
data/explorer_app/Gemfile
CHANGED
|
@@ -4,13 +4,13 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
|
|
4
4
|
gemspec path: "../"
|
|
5
5
|
|
|
6
6
|
# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
|
|
7
|
-
gem "rails", "~>
|
|
7
|
+
gem "rails", "~> 8.1.2", ">= 8.1.2"
|
|
8
8
|
|
|
9
9
|
# Use sqlite3 as the database for Active Record
|
|
10
|
-
gem "sqlite3", "~>
|
|
10
|
+
gem "sqlite3", "~> 2.9"
|
|
11
11
|
|
|
12
12
|
# Use the Puma web server [https://github.com/puma/puma]
|
|
13
|
-
gem "puma", "~>
|
|
13
|
+
gem "puma", "~> 7.1"
|
|
14
14
|
|
|
15
15
|
# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
|
|
16
16
|
# gem "kredis"
|
|
@@ -42,7 +42,7 @@ module ApplicationHelper
|
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
def overlap_percentage(entity, other_entity, association)
|
|
45
|
-
return nil unless entity && other_entity && entity.total_area > 0
|
|
45
|
+
return nil unless entity && other_entity && entity.total_area.to_f > 0
|
|
46
46
|
|
|
47
47
|
belongs_to = other_entity.class.base_class.to_s.demodulize.underscore
|
|
48
48
|
overlap = entity.send(association).detect { |r| r.send(belongs_to) == other_entity }
|
|
@@ -24,24 +24,28 @@ namespace :us_geo do
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
klasses.each do |name, klass|
|
|
27
|
-
desc
|
|
27
|
+
desc <<~DOC
|
|
28
|
+
Import data for #{klass}. Set US_GEO_BASE_DATA_URI to override the data source location.
|
|
29
|
+
DOC
|
|
28
30
|
task name => :environment do
|
|
29
31
|
t = Time.now
|
|
30
32
|
|
|
31
|
-
klass.load!
|
|
32
|
-
puts "Loaded #{
|
|
33
|
+
imported_count, removed_count = klass.load!
|
|
34
|
+
puts "Loaded #{imported_count} rows into #{klass.table_name} in #{(Time.now - t).round(1)}s"
|
|
33
35
|
|
|
34
|
-
removed_count = klass.removed.count
|
|
35
36
|
if removed_count > 0
|
|
36
37
|
puts " #{removed_count} previously imported records in #{klass.table_name} no longer exist in the current data source"
|
|
37
38
|
end
|
|
38
39
|
end
|
|
40
|
+
end
|
|
39
41
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
desc <<~DOC
|
|
43
|
+
Import data for all USGeo models". Set US_GEO_BASE_DATA_URI to override the data source location.
|
|
44
|
+
The default data location is https://raw.githubusercontent.com/bdurand/us_geo/master/data/2020_dist
|
|
45
|
+
DOC
|
|
46
|
+
task all: :environment do
|
|
47
|
+
klasses.each_key do |name|
|
|
48
|
+
Rake::Task["us_geo:import:#{name}"].invoke
|
|
45
49
|
end
|
|
46
50
|
end
|
|
47
51
|
|
data/lib/us_geo/base_record.rb
CHANGED
|
@@ -37,11 +37,19 @@ module USGeo
|
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
# Mark the status of any records not updated in the block as being no longer imported.
|
|
40
|
+
#
|
|
41
|
+
# @return [Array<Integer>] Count of the number of records imported and the number of records removed
|
|
40
42
|
def import!(&block)
|
|
41
43
|
start_time = Time.at(Time.now.to_i.floor)
|
|
44
|
+
|
|
42
45
|
yield
|
|
43
|
-
|
|
44
|
-
where("updated_at
|
|
46
|
+
|
|
47
|
+
imported_count = where("updated_at >= ?", start_time).count
|
|
48
|
+
raise LoadError.new("No data found") if imported_count == 0
|
|
49
|
+
|
|
50
|
+
removed_count = where("updated_at < ?", start_time).imported.update_all(status: STATUS_REMOVED)
|
|
51
|
+
|
|
52
|
+
[imported_count, removed_count]
|
|
45
53
|
end
|
|
46
54
|
|
|
47
55
|
def data_uri(path)
|
|
@@ -60,7 +68,7 @@ module USGeo
|
|
|
60
68
|
require "csv"
|
|
61
69
|
|
|
62
70
|
file = if location.include?(":")
|
|
63
|
-
URI.parse(location).open(read_timeout:
|
|
71
|
+
URI.parse(location).open(read_timeout: 10, open_timeout: 5)
|
|
64
72
|
else
|
|
65
73
|
File.open(location)
|
|
66
74
|
end
|
data/lib/us_geo/county.rb
CHANGED
|
@@ -12,7 +12,7 @@ module USGeo
|
|
|
12
12
|
|
|
13
13
|
belongs_to :core_based_statistical_area, foreign_key: :cbsa_geoid, optional: true, inverse_of: :counties
|
|
14
14
|
belongs_to :metropolitan_division, foreign_key: :metropolitan_division_geoid, optional: true, inverse_of: :counties
|
|
15
|
-
belongs_to :state, foreign_key: :state_code, inverse_of: :counties
|
|
15
|
+
belongs_to :state, foreign_key: :state_code, optional: true, inverse_of: :counties
|
|
16
16
|
|
|
17
17
|
has_many :subdivisions, -> { not_removed }, foreign_key: :county_geoid, inverse_of: :county, class_name: "USGeo::CountySubdivision"
|
|
18
18
|
|
|
@@ -8,7 +8,7 @@ module USGeo
|
|
|
8
8
|
|
|
9
9
|
self.primary_key = "geoid"
|
|
10
10
|
|
|
11
|
-
belongs_to :county, foreign_key: :county_geoid, inverse_of: :subdivisions
|
|
11
|
+
belongs_to :county, foreign_key: :county_geoid, optional: true, inverse_of: :subdivisions
|
|
12
12
|
|
|
13
13
|
has_many :zcta_county_subdivisions, -> { not_removed }, foreign_key: :county_subdivision_geoid, inverse_of: :county_subdivision, dependent: :destroy
|
|
14
14
|
has_many :zctas, -> { not_removed }, through: :zcta_county_subdivisions
|
data/lib/us_geo/division.rb
CHANGED
|
@@ -6,7 +6,7 @@ module USGeo
|
|
|
6
6
|
include Population
|
|
7
7
|
include Area
|
|
8
8
|
|
|
9
|
-
belongs_to :region, inverse_of: :divisions
|
|
9
|
+
belongs_to :region, optional: true, inverse_of: :divisions
|
|
10
10
|
has_many :states, -> { not_removed }, inverse_of: :division
|
|
11
11
|
|
|
12
12
|
validates :name, presence: true, length: {maximum: 30}, uniqueness: true
|
data/lib/us_geo/place.rb
CHANGED
|
@@ -26,7 +26,7 @@ module USGeo
|
|
|
26
26
|
|
|
27
27
|
# !@method primary_county
|
|
28
28
|
# @return [County] County that contains most of the place.
|
|
29
|
-
belongs_to :primary_county, foreign_key: :primary_county_geoid, class_name: "USGeo::County"
|
|
29
|
+
belongs_to :primary_county, foreign_key: :primary_county_geoid, optional: true, class_name: "USGeo::County"
|
|
30
30
|
|
|
31
31
|
# !@method urban_area
|
|
32
32
|
# @return [UrbanArea] Urban area that the place is a part of.
|
|
@@ -34,7 +34,7 @@ module USGeo
|
|
|
34
34
|
|
|
35
35
|
# !@method state
|
|
36
36
|
# @return [State] State that the place is in.
|
|
37
|
-
belongs_to :state, foreign_key: :state_code, inverse_of: :places
|
|
37
|
+
belongs_to :state, foreign_key: :state_code, optional: true, inverse_of: :places
|
|
38
38
|
|
|
39
39
|
validates :geoid, length: {is: 7}
|
|
40
40
|
validates :state_code, length: {is: 2}
|
data/lib/us_geo/state.rb
CHANGED
|
@@ -13,8 +13,8 @@ module USGeo
|
|
|
13
13
|
self.primary_key = "code"
|
|
14
14
|
self.inheritance_column = :_type_disabled
|
|
15
15
|
|
|
16
|
-
belongs_to :region, optional:
|
|
17
|
-
belongs_to :division, optional:
|
|
16
|
+
belongs_to :region, optional: true, inverse_of: :states
|
|
17
|
+
belongs_to :division, optional: true, inverse_of: :states
|
|
18
18
|
|
|
19
19
|
has_many :counties, -> { not_removed }, foreign_key: :state_code, inverse_of: :state
|
|
20
20
|
has_many :places, -> { not_removed }, foreign_key: :state_code, inverse_of: :state
|
data/lib/us_geo/urban_area.rb
CHANGED
|
@@ -19,7 +19,7 @@ module USGeo
|
|
|
19
19
|
|
|
20
20
|
# !@method primary_county
|
|
21
21
|
# @return [USGeo::County] Primary county that contains most of the urban area.
|
|
22
|
-
belongs_to :primary_county, foreign_key: :primary_county_geoid, class_name: "USGeo::County"
|
|
22
|
+
belongs_to :primary_county, foreign_key: :primary_county_geoid, optional: true, class_name: "USGeo::County"
|
|
23
23
|
|
|
24
24
|
# !@method urban_area_county_subdivisions
|
|
25
25
|
# @return [ActiveRecord::Relation<USGeo::UrbanAreaCountySubdivision>] County subdivision to urban area mapping.
|
data/lib/us_geo/zcta.rb
CHANGED
|
@@ -22,7 +22,6 @@ module USGeo
|
|
|
22
22
|
# This scope will search for ZCTA's via the ZCTAMappings table. This is useful
|
|
23
23
|
# when you have a retired ZIP code and want to find the current ZCTA for that ZIP code.
|
|
24
24
|
#
|
|
25
|
-
# @param zipcode [String] ZIP code to search for.
|
|
26
25
|
# @return [ActiveRecord::Relation] ZCTA's matching the given ZIP code.
|
|
27
26
|
scope :for_zipcode, ->(zipcode) { left_outer_joins(:zcta_mappings).where(ZctaMapping.table_name => {zipcode: zipcode}).or(left_outer_joins(:zcta_mappings).where(zipcode: zipcode)).distinct }
|
|
28
27
|
|
|
@@ -36,7 +35,7 @@ module USGeo
|
|
|
36
35
|
|
|
37
36
|
# @!method primary_county
|
|
38
37
|
# @return [USGeo::County] County that contains most of the ZCTA's land area.
|
|
39
|
-
belongs_to :primary_county, foreign_key: :primary_county_geoid, class_name: "USGeo::County"
|
|
38
|
+
belongs_to :primary_county, foreign_key: :primary_county_geoid, optional: true, class_name: "USGeo::County"
|
|
40
39
|
|
|
41
40
|
# @!method zcta_urban_areas
|
|
42
41
|
# @return [ActiveRecord::Relation] ZCTA to urban area mappings.
|
|
@@ -48,7 +47,7 @@ module USGeo
|
|
|
48
47
|
|
|
49
48
|
# @!method primary_urban_area
|
|
50
49
|
# @return [USGeo::UrbanArea] Urban area that contains most of the ZCTA's land area.
|
|
51
|
-
belongs_to :primary_urban_area, foreign_key: :primary_urban_area_geoid, class_name: "USGeo::UrbanArea"
|
|
50
|
+
belongs_to :primary_urban_area, foreign_key: :primary_urban_area_geoid, optional: true, class_name: "USGeo::UrbanArea"
|
|
52
51
|
|
|
53
52
|
# @!method zcta_county_subdivisions
|
|
54
53
|
# @return [ActiveRecord::Relation] ZCTA to county subdivision mappings.
|
|
@@ -60,7 +59,7 @@ module USGeo
|
|
|
60
59
|
|
|
61
60
|
# @!method primary_county_subdivision
|
|
62
61
|
# @return [USGeo::CountySubdivision] County subdivision that contains most of the ZCTA's land area.
|
|
63
|
-
belongs_to :primary_county_subdivision, foreign_key: :primary_county_subdivision_geoid, class_name: "USGeo::CountySubdivision"
|
|
62
|
+
belongs_to :primary_county_subdivision, foreign_key: :primary_county_subdivision_geoid, optional: true, class_name: "USGeo::CountySubdivision"
|
|
64
63
|
|
|
65
64
|
# @!method zcta_places
|
|
66
65
|
# @return [ActiveRecord::Relation] ZCTA to place mappings.
|
|
@@ -72,7 +71,7 @@ module USGeo
|
|
|
72
71
|
|
|
73
72
|
# @!method primary_place
|
|
74
73
|
# @return [USGeo::Place] Place that contains most of the ZCTA's land area.
|
|
75
|
-
belongs_to :primary_place, foreign_key: :primary_place_geoid, class_name: "USGeo::Place"
|
|
74
|
+
belongs_to :primary_place, foreign_key: :primary_place_geoid, optional: true, class_name: "USGeo::Place"
|
|
76
75
|
|
|
77
76
|
# @!method zcta_mappings
|
|
78
77
|
# @return [ActiveRecord::Relation] 2010 ZCTA to current ZCTA mappings.
|
data/us_geo.gemspec
CHANGED
|
@@ -8,10 +8,17 @@ Gem::Specification.new do |spec|
|
|
|
8
8
|
spec.homepage = "https://github.com/bdurand/us_geo"
|
|
9
9
|
spec.license = "MIT"
|
|
10
10
|
|
|
11
|
+
spec.metadata = {
|
|
12
|
+
"homepage_uri" => spec.homepage,
|
|
13
|
+
"source_code_uri" => spec.homepage,
|
|
14
|
+
"changelog_uri" => "#{spec.homepage}/blob/main/CHANGELOG.md"
|
|
15
|
+
}
|
|
16
|
+
|
|
11
17
|
# Specify which files should be added to the gem when it is released.
|
|
12
18
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
13
19
|
ignore_files = %w[
|
|
14
20
|
.
|
|
21
|
+
AGENTS.md
|
|
15
22
|
Appraisals
|
|
16
23
|
Gemfile
|
|
17
24
|
Gemfile.lock
|
|
@@ -29,6 +36,7 @@ Gem::Specification.new do |spec|
|
|
|
29
36
|
spec.require_paths = ["lib"]
|
|
30
37
|
|
|
31
38
|
spec.add_dependency "activerecord", ">= 5.2"
|
|
39
|
+
spec.add_dependency "csv"
|
|
32
40
|
|
|
33
41
|
spec.add_development_dependency "bundler"
|
|
34
42
|
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: us_geo
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Brian Durand
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: activerecord
|
|
@@ -24,6 +23,20 @@ dependencies:
|
|
|
24
23
|
- - ">="
|
|
25
24
|
- !ruby/object:Gem::Version
|
|
26
25
|
version: '5.2'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: csv
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0'
|
|
27
40
|
- !ruby/object:Gem::Dependency
|
|
28
41
|
name: bundler
|
|
29
42
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -38,7 +51,6 @@ dependencies:
|
|
|
38
51
|
- - ">="
|
|
39
52
|
- !ruby/object:Gem::Version
|
|
40
53
|
version: '0'
|
|
41
|
-
description:
|
|
42
54
|
email:
|
|
43
55
|
- bbdurand@gmail.com
|
|
44
56
|
executables: []
|
|
@@ -84,6 +96,7 @@ files:
|
|
|
84
96
|
- db/migrate/20230417000600_add_additional_time_zone_name_to_counties.rb
|
|
85
97
|
- db/migrate/20230426000100_add_index_on_zctas_geoids.rb
|
|
86
98
|
- db/migrate/20230620000100_fix_short_names.rb
|
|
99
|
+
- db/migrate/20251029215800_add_locale_name_to_zctas.rb
|
|
87
100
|
- db/schema.rb
|
|
88
101
|
- explorer_app/.gitattributes
|
|
89
102
|
- explorer_app/.gitignore
|
|
@@ -203,8 +216,10 @@ files:
|
|
|
203
216
|
homepage: https://github.com/bdurand/us_geo
|
|
204
217
|
licenses:
|
|
205
218
|
- MIT
|
|
206
|
-
metadata:
|
|
207
|
-
|
|
219
|
+
metadata:
|
|
220
|
+
homepage_uri: https://github.com/bdurand/us_geo
|
|
221
|
+
source_code_uri: https://github.com/bdurand/us_geo
|
|
222
|
+
changelog_uri: https://github.com/bdurand/us_geo/blob/main/CHANGELOG.md
|
|
208
223
|
rdoc_options: []
|
|
209
224
|
require_paths:
|
|
210
225
|
- lib
|
|
@@ -219,8 +234,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
219
234
|
- !ruby/object:Gem::Version
|
|
220
235
|
version: '0'
|
|
221
236
|
requirements: []
|
|
222
|
-
rubygems_version:
|
|
223
|
-
signing_key:
|
|
237
|
+
rubygems_version: 4.0.3
|
|
224
238
|
specification_version: 4
|
|
225
239
|
summary: Collection of geographic data for the United States for use with ActiveRecord
|
|
226
240
|
test_files: []
|