us_geo 2.0.1 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 73084a715b73e960f52bf49b61e83d9bf68814a95a5ba9a6c702e721f9fe4c14
4
- data.tar.gz: 3e525d12df7a407afdfd67116a1f54f8c17de9def115a433fb0678b215267eff
3
+ metadata.gz: 55d616e1859588fe10360c02f03f54425dd22131491d2dd3eed1562ed82a7db9
4
+ data.tar.gz: 42d5621571038484a7f54da077af404f1261da7d7b98de8b011a2daf3435dd4c
5
5
  SHA512:
6
- metadata.gz: 4a2c90967678930d21c7c3560d785a4fb8551f71cf017f1e9a8ef975f637bb215b3ef90376140a67cdbd6740f1ae4206407f7da25ef027804d8b788a525c73b8
7
- data.tar.gz: e1ec086a0af3dff1ad76af089caa510af3175f2b82f5afa6489752bd562dbb6662cc374cd6b55a0ec6392f3e289318c93387b2a6b9b0b684fe15e2422a2955e5
6
+ metadata.gz: 7f76c7eab9424153ea5872cdebd31baafd19987cefb13ad84f954d4f6822d4210267dbfd6b2b73a20e488d68c02dc947cc9bfcdd9c9dff156020a46efc2cf48b
7
+ data.tar.gz: e3ebb26c9f666a072bf1d727bbe86873332288d698cee70999f22434077a46ada1e92b28a361330c317d2cd7c7c82c9a2583f3c9e3ff75d6ae5dc5edd8cd604a
data/CHANGELOG.md CHANGED
@@ -4,6 +4,18 @@ 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.0.3
8
+
9
+ ### Added
10
+
11
+ - Added methods to calculate housing density.
12
+
13
+ ## 2.0.2
14
+
15
+ ### Fixed
16
+
17
+ - Migrations that update existing data are now compatible with Rails versions prior to 7.0.
18
+
7
19
  ## 2.0.1
8
20
 
9
21
  ### Added
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.1
1
+ 2.0.3
@@ -6,10 +6,12 @@ class AddShortNameToCoreBasedStatisticalAreas < ActiveRecord::Migration[5.0]
6
6
 
7
7
  add_column :us_geo_core_based_statistical_areas, :short_name, :string, null: true
8
8
 
9
+ update_sql = "UPDATE us_geo_core_based_statistical_areas SET short_name = ? WHERE geoid = ?"
10
+
9
11
  select_all("SELECT geoid, name FROM us_geo_core_based_statistical_areas").each do |row|
10
12
  city, state = row["name"].split(", ", 2)
11
13
  short_name = "#{city.split("-").first}, #{state.split("-").first}"
12
- update("UPDATE us_geo_core_based_statistical_areas SET short_name = ? WHERE geoid = ?", nil, [short_name, row["geoid"]])
14
+ update ActiveRecord::Base.sanitize_sql([update_sql, short_name, row["geoid"]])
13
15
  end
14
16
 
15
17
  change_column_null :us_geo_core_based_statistical_areas, :short_name, false
@@ -6,10 +6,12 @@ class AddShortNameToCombinedStatisticalAreas < ActiveRecord::Migration[5.0]
6
6
 
7
7
  add_column :us_geo_combined_statistical_areas, :short_name, :string, null: true
8
8
 
9
+ update_sql = "UPDATE us_geo_combined_statistical_areas SET short_name = ? WHERE geoid = ?"
10
+
9
11
  select_all("SELECT geoid, name FROM us_geo_combined_statistical_areas").each do |row|
10
12
  city, state = row["name"].split(", ", 2)
11
13
  short_name = "#{city.split("-").first}, #{state.split("-").first}"
12
- update("UPDATE us_geo_combined_statistical_areas SET short_name = ? WHERE geoid = ?", nil, [short_name, row["geoid"]])
14
+ update ActiveRecord::Base.sanitize_sql([update_sql, short_name, row["geoid"]])
13
15
  end
14
16
 
15
17
  change_column_null :us_geo_combined_statistical_areas, :short_name, false
@@ -13,8 +13,10 @@ class AddUniqueNameIndexToCountySubdivisions < ActiveRecord::Migration[5.0]
13
13
  AND t1.name = t2.name
14
14
  SQL
15
15
 
16
+ update_sql = "UPDATE us_geo_county_subdivisions SET name = ? WHERE geoid = ?"
17
+
16
18
  select_all(duplicates_sql).each do |row|
17
- update("UPDATE us_geo_county_subdivisions SET name = ? WHERE geoid = ?", nil, ["#{row["name"]} (duplicate)", row["geoid"]])
19
+ update ActiveRecord::Base.sanitize_sql([update_sql, "#{row["name"]} (duplicate)", row["geoid"]])
18
20
  end
19
21
 
20
22
  add_index :us_geo_county_subdivisions, [:name, :county_geoid], unique: true, name: "index_us_geo_county_subdivisions_on_unique_name"
@@ -25,8 +25,7 @@ module ApplicationHelper
25
25
  render "shared/demographics_cells", entity: entity, round_area: round_area
26
26
  end
27
27
 
28
- def population_density(entity)
29
- density = entity.population_density
28
+ def density(density)
30
29
  return nil unless density
31
30
 
32
31
  round = if density < 1
@@ -48,12 +48,16 @@
48
48
  </tr>
49
49
  <tr>
50
50
  <th>Population Density</th>
51
- <td><%= population_density(@county) %></td>
51
+ <td><%= density(@county.population_density) %></td>
52
52
  </tr>
53
53
  <tr>
54
54
  <th>Housing Units</th>
55
55
  <td><%= formatted_number(@county.housing_units) %></td>
56
56
  </tr>
57
+ <tr>
58
+ <th>Housing Density</th>
59
+ <td><%= density(@county.housing_density) %></td>
60
+ </tr>
57
61
  <tr>
58
62
  <th>Land Area (mi<sup>2</sup>)</th>
59
63
  <td><%= formatted_number(@county.land_area, round: 0) %></td>
@@ -48,12 +48,16 @@
48
48
  </tr>
49
49
  <tr>
50
50
  <th>Population Density</th>
51
- <td><%= population_density(@county_subdivision) %></td>
51
+ <td><%= density(@county_subdivision.population_density) %></td>
52
52
  </tr>
53
53
  <tr>
54
54
  <th>Housing Units</th>
55
55
  <td><%= formatted_number(@county_subdivision.housing_units) %></td>
56
56
  </tr>
57
+ <tr>
58
+ <th>Housing Density</th>
59
+ <td><%= density(@county_subdivision.housing_density) %></td>
60
+ </tr>
57
61
  <tr>
58
62
  <th>Land Area (mi<sup>2</sup>)</th>
59
63
  <td><%= formatted_number(@county_subdivision.land_area, round: 0) %></td>
@@ -56,12 +56,16 @@
56
56
  </tr>
57
57
  <tr>
58
58
  <th>Population Density</th>
59
- <td><%= population_density(@place) %></td>
59
+ <td><%= density(@place.population_density) %></td>
60
60
  </tr>
61
61
  <tr>
62
62
  <th>Housing Units</th>
63
63
  <td><%= formatted_number(@place.housing_units) %></td>
64
64
  </tr>
65
+ <tr>
66
+ <th>Housing Density</th>
67
+ <td><%= density(@place.housing_density) %></td>
68
+ </tr>
65
69
  <tr>
66
70
  <th>Land Area (mi<sup>2</sup>)</th>
67
71
  <td><%= formatted_number(@place.land_area, round: 0) %></td>
@@ -1,5 +1,6 @@
1
1
  <%= content_tag(:td, (entity.population ? formatted_number(entity.population) : "-"), class: "text-end", data: {sort: entity.population.to_i}) %>
2
- <%= content_tag(:td, population_density(entity), class: "text-end", data: {sort: entity.population_density.to_f}) %>
2
+ <%= content_tag(:td, density(entity.population_density), class: "text-end", data: {sort: entity.population_density.to_f}) %>
3
3
  <%= content_tag(:td, (entity.housing_units ? formatted_number(entity.housing_units) : "-"), class: "text-end", data: {sort: entity.housing_units.to_i}) %>
4
+ <%= content_tag(:td, density(entity.housing_density), class: "text-end", data: {sort: entity.housing_density.to_f}) %>
4
5
  <%= content_tag(:td, (entity.land_area ? formatted_number(entity.land_area, round: round_area) : "-"), class: "text-end", data: {sort: entity.land_area.to_i}) %>
5
6
  <%= content_tag(:td, (entity.water_area ? formatted_number(entity.water_area, round: round_area) : "-"), class: "text-end", data: {sort: entity.water_area.to_i}) %>
@@ -1,5 +1,6 @@
1
1
  <th class="text-end">Population</th>
2
2
  <th class="text-end">Population Density</th>
3
3
  <th class="text-end">Housing Units</th>
4
+ <th class="text-end">Housing Density</th>
4
5
  <th class="text-end">Land Area</th>
5
6
  <th class="text-end">Water Area</th>
@@ -54,12 +54,16 @@
54
54
  </tr>
55
55
  <tr>
56
56
  <th>Population Density</th>
57
- <td><%= population_density(@zcta) %></td>
57
+ <td><%= density(@zcta.population_density) %></td>
58
58
  </tr>
59
59
  <tr>
60
60
  <th>Housing Units</th>
61
61
  <td><%= formatted_number(@zcta.housing_units) %></td>
62
62
  </tr>
63
+ <tr>
64
+ <th>Housing Density</th>
65
+ <td><%= density(@zcta.housing_density) %></td>
66
+ </tr>
63
67
  <tr>
64
68
  <th>Land Area (mi<sup>2</sup>)</th>
65
69
  <td><%= formatted_number(@zcta.land_area, round: 0) %></td>
@@ -22,5 +22,19 @@ module USGeo
22
22
  def population_density_km
23
23
  population.to_f / land_area_km if population && land_area.to_f > 0
24
24
  end
25
+
26
+ # Housing units per square mile.
27
+ #
28
+ # @return [Float, nil]
29
+ def housing_density
30
+ housing_units.to_f / land_area if housing_units && land_area.to_f > 0
31
+ end
32
+
33
+ # Housing units per square kilometer.
34
+ #
35
+ # @return [Float, nil]
36
+ def housing_density_km
37
+ housing_units.to_f / land_area_km if housing_units && land_area.to_f > 0
38
+ end
25
39
  end
26
40
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: us_geo
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Durand
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-27 00:00:00.000000000 Z
11
+ date: 2023-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord