earth 0.5.0 → 0.5.2

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.
Files changed (173) hide show
  1. data/Gemfile +4 -5
  2. data/README.markdown +0 -8
  3. data/Rakefile +14 -10
  4. data/bin/earth_tester.rb +12 -12
  5. data/earth.gemspec +2 -1
  6. data/features/automobile_make_fleet_year.feature +9 -19
  7. data/features/automobile_make_model_year.feature +4 -4
  8. data/features/support/env.rb +11 -7
  9. data/features/support/imports/automobile_make_fleet_year_bad.csv +1 -1
  10. data/features/support/imports/automobile_make_fleet_year_good.csv +1 -1
  11. data/features/support/imports/automobile_make_model_year_bad.csv +1 -1
  12. data/features/support/imports/automobile_make_model_year_good.csv +1 -1
  13. data/lib/earth/air/aircraft/data_miner.rb +63 -15
  14. data/lib/earth/air/aircraft.rb +0 -11
  15. data/lib/earth/air/aircraft_class/data_miner.rb +0 -13
  16. data/lib/earth/air/aircraft_class.rb +12 -3
  17. data/lib/earth/air/aircraft_fuel_use_equation/data_miner.rb +0 -13
  18. data/lib/earth/air/aircraft_fuel_use_equation.rb +12 -3
  19. data/lib/earth/air/airline/data_miner.rb +0 -7
  20. data/lib/earth/air/airline.rb +6 -3
  21. data/lib/earth/air/airport/data_miner.rb +5 -14
  22. data/lib/earth/air/airport.rb +9 -7
  23. data/lib/earth/air/bts_aircraft/data_miner.rb +0 -5
  24. data/lib/earth/air/bts_aircraft.rb +3 -3
  25. data/lib/earth/air/data_miner.rb +2 -3
  26. data/lib/earth/air/flight_distance_class/data_miner.rb +0 -6
  27. data/lib/earth/air/flight_distance_class.rb +4 -3
  28. data/lib/earth/air/flight_seat_class/data_miner.rb +0 -7
  29. data/lib/earth/air/flight_seat_class.rb +6 -3
  30. data/lib/earth/air/flight_segment/data_miner.rb +30 -112
  31. data/lib/earth/air/flight_segment.rb +47 -13
  32. data/lib/earth/air.rb +2 -1
  33. data/lib/earth/automobile/automobile_fuel/data_miner.rb +1 -25
  34. data/lib/earth/automobile/automobile_fuel.rb +24 -8
  35. data/lib/earth/automobile/automobile_make/data_miner.rb +3 -16
  36. data/lib/earth/automobile/automobile_make.rb +5 -3
  37. data/lib/earth/automobile/automobile_make_fleet_year/data_miner.rb +16 -30
  38. data/lib/earth/automobile/automobile_make_fleet_year.rb +10 -7
  39. data/lib/earth/automobile/automobile_make_model/data_miner.rb +1 -11
  40. data/lib/earth/automobile/automobile_make_model.rb +9 -7
  41. data/lib/earth/automobile/automobile_make_model_year/data_miner.rb +4 -17
  42. data/lib/earth/automobile/automobile_make_model_year.rb +11 -6
  43. data/lib/earth/automobile/automobile_make_model_year_variant/data_miner.rb +37 -65
  44. data/lib/earth/automobile/automobile_make_model_year_variant.rb +36 -6
  45. data/lib/earth/automobile/automobile_make_year/data_miner.rb +3 -15
  46. data/lib/earth/automobile/automobile_make_year.rb +8 -7
  47. data/lib/earth/automobile/automobile_size_class/data_miner.rb +0 -15
  48. data/lib/earth/automobile/automobile_size_class.rb +13 -2
  49. data/lib/earth/automobile/automobile_size_class_year/data_miner.rb +0 -11
  50. data/lib/earth/automobile/automobile_size_class_year.rb +10 -3
  51. data/lib/earth/automobile/automobile_type_fuel_age/data_miner.rb +0 -12
  52. data/lib/earth/automobile/automobile_type_fuel_age.rb +10 -2
  53. data/lib/earth/automobile/automobile_type_fuel_control/data_miner.rb +0 -11
  54. data/lib/earth/automobile/automobile_type_fuel_control.rb +9 -3
  55. data/lib/earth/automobile/automobile_type_fuel_year/data_miner.rb +1 -17
  56. data/lib/earth/automobile/automobile_type_fuel_year.rb +14 -6
  57. data/lib/earth/automobile/automobile_type_fuel_year_age/data_miner.rb +0 -13
  58. data/lib/earth/automobile/automobile_type_fuel_year_age.rb +12 -7
  59. data/lib/earth/automobile/automobile_type_fuel_year_control/data_miner.rb +0 -11
  60. data/lib/earth/automobile/automobile_type_fuel_year_control.rb +9 -6
  61. data/lib/earth/automobile/automobile_type_year/data_miner.rb +0 -10
  62. data/lib/earth/automobile/automobile_type_year.rb +9 -3
  63. data/lib/earth/bus/bus_class/data_miner.rb +0 -29
  64. data/lib/earth/bus/bus_class.rb +27 -2
  65. data/lib/earth/bus/bus_fuel/data_miner.rb +1 -16
  66. data/lib/earth/bus/bus_fuel.rb +15 -8
  67. data/lib/earth/bus/bus_fuel_control/data_miner.rb +0 -10
  68. data/lib/earth/bus/bus_fuel_control.rb +8 -3
  69. data/lib/earth/bus/bus_fuel_year_control/data_miner.rb +1 -10
  70. data/lib/earth/bus/bus_fuel_year_control.rb +8 -7
  71. data/lib/earth/bus/data_miner.rb +2 -0
  72. data/lib/earth/bus.rb +2 -0
  73. data/lib/earth/computation/computation_carrier/data_miner.rb +0 -5
  74. data/lib/earth/computation/computation_carrier.rb +3 -2
  75. data/lib/earth/computation/computation_carrier_instance_class/data_miner.rb +0 -8
  76. data/lib/earth/computation/computation_carrier_instance_class.rb +6 -6
  77. data/lib/earth/computation/computation_carrier_region/data_miner.rb +0 -7
  78. data/lib/earth/computation/computation_carrier_region.rb +6 -7
  79. data/lib/earth/computation/data_miner.rb +2 -0
  80. data/lib/earth/computation.rb +2 -0
  81. data/lib/earth/diet/diet_class/data_miner.rb +0 -16
  82. data/lib/earth/diet/diet_class.rb +16 -4
  83. data/lib/earth/diet/food_group/data_miner.rb +0 -9
  84. data/lib/earth/diet/food_group.rb +7 -2
  85. data/lib/earth/fuel/fuel/data_miner.rb +0 -16
  86. data/lib/earth/fuel/fuel.rb +14 -2
  87. data/lib/earth/fuel/fuel_price/data_miner.rb +0 -6
  88. data/lib/earth/fuel/fuel_price.rb +4 -6
  89. data/lib/earth/fuel/fuel_type/data_miner.rb +0 -14
  90. data/lib/earth/fuel/fuel_type.rb +14 -4
  91. data/lib/earth/fuel/fuel_year/data_miner.rb +0 -16
  92. data/lib/earth/fuel/fuel_year.rb +14 -2
  93. data/lib/earth/fuel/greenhouse_gas/data_miner.rb +0 -9
  94. data/lib/earth/fuel/greenhouse_gas.rb +10 -5
  95. data/lib/earth/hospitality/lodging_class/data_miner.rb +0 -12
  96. data/lib/earth/hospitality/lodging_class.rb +10 -2
  97. data/lib/earth/industry/data_miner.rb +0 -0
  98. data/lib/earth/industry/industry.rb +3 -10
  99. data/lib/earth/industry/industry_product.rb +6 -13
  100. data/lib/earth/industry/industry_product_line.rb +5 -12
  101. data/lib/earth/industry/industry_sector.rb +5 -12
  102. data/lib/earth/industry/merchant.rb +4 -11
  103. data/lib/earth/industry/merchant_category.rb +3 -10
  104. data/lib/earth/industry/merchant_category_industry.rb +5 -12
  105. data/lib/earth/industry/product_line.rb +5 -12
  106. data/lib/earth/industry/product_line_industry_product.rb +5 -12
  107. data/lib/earth/industry/sector.rb +5 -12
  108. data/lib/earth/locality/census_division/data_miner.rb +0 -23
  109. data/lib/earth/locality/census_division.rb +21 -6
  110. data/lib/earth/locality/census_region/data_miner.rb +0 -5
  111. data/lib/earth/locality/census_region.rb +3 -2
  112. data/lib/earth/locality/climate_division/data_miner.rb +0 -7
  113. data/lib/earth/locality/climate_division.rb +5 -7
  114. data/lib/earth/locality/country/data_miner.rb +16 -29
  115. data/lib/earth/locality/country.rb +15 -4
  116. data/lib/earth/locality/data_miner.rb +3 -0
  117. data/lib/earth/locality/egrid_region/data_miner.rb +0 -5
  118. data/lib/earth/locality/egrid_region.rb +5 -8
  119. data/lib/earth/locality/egrid_subregion/data_miner.rb +1 -20
  120. data/lib/earth/locality/egrid_subregion.rb +17 -6
  121. data/lib/earth/locality/petroleum_administration_for_defense_district/data_miner.rb +4 -13
  122. data/lib/earth/locality/petroleum_administration_for_defense_district.rb +8 -4
  123. data/lib/earth/locality/state/data_miner.rb +0 -8
  124. data/lib/earth/locality/state.rb +6 -7
  125. data/lib/earth/locality/urbanity/data_miner.rb +0 -4
  126. data/lib/earth/locality/urbanity.rb +2 -2
  127. data/lib/earth/locality/zip_code/data_miner.rb +0 -10
  128. data/lib/earth/locality/zip_code.rb +8 -6
  129. data/lib/earth/locality.rb +3 -0
  130. data/lib/earth/pet/breed/data_miner.rb +0 -7
  131. data/lib/earth/pet/breed.rb +5 -6
  132. data/lib/earth/pet/breed_gender/data_miner.rb +0 -8
  133. data/lib/earth/pet/breed_gender.rb +6 -6
  134. data/lib/earth/pet/gender/data_miner.rb +0 -3
  135. data/lib/earth/pet/gender.rb +2 -2
  136. data/lib/earth/pet/species/data_miner.rb +0 -17
  137. data/lib/earth/pet/species.rb +17 -4
  138. data/lib/earth/rail/rail_class/data_miner.rb +0 -14
  139. data/lib/earth/rail/rail_class.rb +12 -3
  140. data/lib/earth/residence/air_conditioner_use/data_miner.rb +0 -6
  141. data/lib/earth/residence/air_conditioner_use.rb +5 -3
  142. data/lib/earth/residence/clothes_machine_use/data_miner.rb +0 -6
  143. data/lib/earth/residence/clothes_machine_use.rb +4 -2
  144. data/lib/earth/residence/data_miner.rb +2 -0
  145. data/lib/earth/residence/dishwasher_use/data_miner.rb +0 -6
  146. data/lib/earth/residence/dishwasher_use.rb +5 -3
  147. data/lib/earth/residence/residence_appliance/data_miner.rb +0 -6
  148. data/lib/earth/residence/residence_appliance.rb +4 -2
  149. data/lib/earth/residence/residence_class/data_miner.rb +0 -4
  150. data/lib/earth/residence/residence_class.rb +2 -2
  151. data/lib/earth/residence/residence_fuel_price/data_miner.rb +0 -14
  152. data/lib/earth/residence/residence_fuel_price.rb +12 -7
  153. data/lib/earth/residence/residence_fuel_type/data_miner.rb +0 -8
  154. data/lib/earth/residence/residence_fuel_type.rb +6 -2
  155. data/lib/earth/residence/residential_energy_consumption_survey_response/data_miner.rb +0 -94
  156. data/lib/earth/residence/residential_energy_consumption_survey_response.rb +92 -6
  157. data/lib/earth/residence.rb +2 -0
  158. data/lib/earth/shipping/carrier/data_miner.rb +0 -10
  159. data/lib/earth/shipping/carrier.rb +8 -2
  160. data/lib/earth/shipping/carrier_mode/data_miner.rb +0 -10
  161. data/lib/earth/shipping/carrier_mode.rb +9 -3
  162. data/lib/earth/shipping/shipment_mode/data_miner.rb +0 -7
  163. data/lib/earth/shipping/shipment_mode.rb +5 -2
  164. data/lib/earth/version.rb +1 -1
  165. data/lib/earth.rb +92 -84
  166. data/spec/earth/air/aircraft_spec.rb +1 -1
  167. data/spec/earth_spec.rb +15 -15
  168. data/spec/spec_helper.rb +12 -9
  169. metadata +175 -171
  170. data/lib/earth/active_record_ext.rb +0 -9
  171. data/lib/earth/air/aircraft_manufacturer/data_miner.rb +0 -21
  172. data/lib/earth/air/aircraft_manufacturer.rb +0 -7
  173. data/lib/earth/base.rb +0 -7
@@ -1,7 +1,15 @@
1
1
  class LodgingClass < ActiveRecord::Base
2
2
  set_primary_key :name
3
3
 
4
- data_miner do
5
- tap "Brighter Planet's lodging class data", Earth.taps_server
4
+ create_table do
5
+ string 'name'
6
+ float 'electricity_intensity'
7
+ string 'electricity_intensity_units'
8
+ float 'natural_gas_intensity'
9
+ string 'natural_gas_intensity_units'
10
+ float 'fuel_oil_intensity'
11
+ string 'fuel_oil_intensity_units'
12
+ float 'district_heat_intensity'
13
+ string 'district_heat_intensity_units'
6
14
  end
7
15
  end
File without changes
@@ -1,5 +1,4 @@
1
1
  class Industry < ActiveRecord::Base
2
- extend Earth::Base
3
2
  set_primary_key :naics_code
4
3
 
5
4
  has_many :merchant_category_industries, :foreign_key => 'naics_code'
@@ -10,15 +9,9 @@ class Industry < ActiveRecord::Base
10
9
  has_many :industry_sectors, :foreign_key => 'naics_code'
11
10
  has_many :sectors, :through => :industry_sectors
12
11
 
13
- def self.schema_definition
14
- lambda do
15
- string 'naics_code'
16
- string 'description'
17
- end
18
- end
19
-
20
- data_miner do
21
- Industry.define_schema(self)
12
+ create_table do
13
+ string 'naics_code'
14
+ string 'description'
22
15
  end
23
16
 
24
17
  def trade_industry?
@@ -1,22 +1,15 @@
1
1
  class IndustryProduct < ActiveRecord::Base
2
- extend Earth::Base
3
2
  set_primary_key :naics_product_code
4
3
 
5
4
  has_many :product_line_industry_products, :foreign_key => 'naics_product_code'
6
5
 
7
6
  belongs_to :industry, :foreign_key => 'naics_code'
8
7
 
9
- def self.schema_definition
10
- lambda do
11
- string 'naics_product_code'
12
- string 'description'
13
- float 'value'
14
- string 'value_units'
15
- string 'naics_code'
16
- end
17
- end
18
-
19
- data_miner do
20
- IndustryProduct.define_schema(self)
8
+ create_table do
9
+ string 'naics_product_code'
10
+ string 'description'
11
+ float 'value'
12
+ string 'value_units'
13
+ string 'naics_code'
21
14
  end
22
15
  end
@@ -1,20 +1,13 @@
1
1
  class IndustryProductLine < ActiveRecord::Base
2
- extend Earth::Base
3
2
  set_primary_key :row_hash
4
3
 
5
4
  belongs_to :industry, :foreign_key => 'naics_code'
6
5
  belongs_to :product_line, :foreign_key => 'ps_code'
7
6
 
8
- def self.schema_definition
9
- lambda do
10
- string 'row_hash'
11
- string 'naics_code'
12
- float 'ratio'
13
- string 'ps_code'
14
- end
15
- end
16
-
17
- data_miner do
18
- IndustryProductLine.define_schema(self)
7
+ create_table do
8
+ string 'row_hash'
9
+ string 'naics_code'
10
+ float 'ratio'
11
+ string 'ps_code'
19
12
  end
20
13
  end
@@ -1,20 +1,13 @@
1
1
  class IndustrySector < ActiveRecord::Base
2
- extend Earth::Base
3
2
  set_primary_key :row_hash
4
3
 
5
4
  belongs_to :industry, :foreign_key => 'naics_code'
6
5
  belongs_to :sector, :foreign_key => 'io_code'
7
6
 
8
- def self.schema_definition
9
- lambda do
10
- string 'row_hash'
11
- string 'naics_code'
12
- float 'ratio'
13
- string 'io_code'
14
- end
15
- end
16
-
17
- data_miner do
18
- IndustrySector.define_schema(self)
7
+ create_table do
8
+ string 'row_hash'
9
+ string 'naics_code'
10
+ float 'ratio'
11
+ string 'io_code'
19
12
  end
20
13
  end
@@ -1,18 +1,11 @@
1
1
  class Merchant < ActiveRecord::Base
2
- extend Earth::Base
3
2
  set_primary_key :id
4
3
 
5
4
  belongs_to :merchant_category, :foreign_key => 'mcc'
6
5
 
7
- def self.schema_definition
8
- lambda do
9
- string 'id'
10
- string 'name'
11
- string 'mcc'
12
- end
13
- end
14
-
15
- data_miner do
16
- Merchant.define_schema(self)
6
+ create_table do
7
+ string 'id'
8
+ string 'name'
9
+ string 'mcc'
17
10
  end
18
11
  end
@@ -1,5 +1,4 @@
1
1
  class MerchantCategory < ActiveRecord::Base
2
- extend Earth::Base
3
2
  set_primary_key :mcc
4
3
 
5
4
  has_many :merchant_category_industries, :foreign_key => 'mcc'
@@ -9,14 +8,8 @@ class MerchantCategory < ActiveRecord::Base
9
8
  description
10
9
  end
11
10
 
12
- def self.schema_definition
13
- lambda do
14
- string 'mcc'
15
- string 'description'
16
- end
17
- end
18
-
19
- data_miner do
20
- MerchantCategory.define_schema(self)
11
+ create_table do
12
+ string 'mcc'
13
+ string 'description'
21
14
  end
22
15
  end
@@ -1,20 +1,13 @@
1
1
  class MerchantCategoryIndustry < ActiveRecord::Base
2
- extend Earth::Base
3
2
  set_primary_key :row_hash
4
3
 
5
4
  belongs_to :merchant_category, :foreign_key => 'mcc'
6
5
  belongs_to :industry, :foreign_key => 'naics_code'
7
6
 
8
- def self.schema_definition
9
- lambda do
10
- string 'row_hash'
11
- string 'mcc'
12
- float 'ratio'
13
- string 'naics_code'
14
- end
15
- end
16
-
17
- data_miner do
18
- MerchantCategoryIndustry.define_schema(self)
7
+ create_table do
8
+ string 'row_hash'
9
+ string 'mcc'
10
+ float 'ratio'
11
+ string 'naics_code'
19
12
  end
20
13
  end
@@ -1,5 +1,4 @@
1
1
  class ProductLine < ActiveRecord::Base
2
- extend Earth::Base
3
2
  set_primary_key :ps_code
4
3
 
5
4
  has_many :industry_product_lines, :foreign_key => 'ps_code'
@@ -7,16 +6,10 @@ class ProductLine < ActiveRecord::Base
7
6
  has_many :product_line_industry_products, :foreign_key => 'ps_code'
8
7
  has_many :industry_products, :through => :product_line_industry_products
9
8
 
10
- def self.schema_definition
11
- lambda do
12
- string 'ps_code'
13
- string 'description'
14
- string 'broadline' # FIXME TODO do we need this?
15
- string 'parent' # FIXME TODO do we need this?
16
- end
17
- end
18
-
19
- data_miner do
20
- ProductLine.define_schema(self)
9
+ create_table do
10
+ string 'ps_code'
11
+ string 'description'
12
+ string 'broadline' # FIXME TODO do we need this?
13
+ string 'parent' # FIXME TODO do we need this?
21
14
  end
22
15
  end
@@ -1,20 +1,13 @@
1
1
  class ProductLineIndustryProduct < ActiveRecord::Base
2
- extend Earth::Base
3
2
  set_primary_key :row_hash
4
3
 
5
4
  belongs_to :product_line, :foreign_key => 'ps_code'
6
5
  belongs_to :industry_product, :foreign_key => 'naics_product_code'
7
6
 
8
- def self.schema_definition
9
- lambda do
10
- string 'row_hash'
11
- string 'ps_code'
12
- float 'ratio'
13
- string 'naics_product_code'
14
- end
15
- end
16
-
17
- data_miner do
18
- ProductLineIndustryProduct.define_schema(self)
7
+ create_table do
8
+ string 'row_hash'
9
+ string 'ps_code'
10
+ float 'ratio'
11
+ string 'naics_product_code'
19
12
  end
20
13
  end
@@ -1,19 +1,12 @@
1
1
  class Sector < ActiveRecord::Base
2
- extend Earth::Base
3
2
  set_primary_key :io_code
4
3
 
5
4
  has_many :industry_sectors, :foreign_key => 'io_code'
6
5
 
7
- def self.schema_definition
8
- lambda do
9
- string 'io_code'
10
- string 'description'
11
- float 'value'
12
- string 'value_units'
13
- end
14
- end
15
-
16
- data_miner do
17
- Sector.define_schema(self)
6
+ create_table do
7
+ string 'io_code'
8
+ string 'description'
9
+ float 'value'
10
+ string 'value_units'
18
11
  end
19
12
  end
@@ -1,28 +1,5 @@
1
1
  CensusDivision.class_eval do
2
2
  data_miner do
3
- schema Earth.database_options do
4
- integer 'number'
5
- string 'name'
6
- string 'census_region_name'
7
- integer 'census_region_number'
8
- float 'meeting_building_natural_gas_intensity'
9
- string 'meeting_building_natural_gas_intensity_units'
10
- float 'meeting_building_fuel_oil_intensity'
11
- string 'meeting_building_fuel_oil_intensity_units'
12
- float 'meeting_building_electricity_intensity'
13
- string 'meeting_building_electricity_intensity_units'
14
- float 'meeting_building_district_heat_intensity'
15
- string 'meeting_building_district_heat_intensity_units'
16
- float 'lodging_building_natural_gas_intensity'
17
- string 'lodging_building_natural_gas_intensity_units'
18
- float 'lodging_building_fuel_oil_intensity'
19
- string 'lodging_building_fuel_oil_intensity_units'
20
- float 'lodging_building_electricity_intensity'
21
- string 'lodging_building_electricity_intensity_units'
22
- float 'lodging_building_district_heat_intensity'
23
- string 'lodging_building_district_heat_intensity_units'
24
- end
25
-
26
3
  process 'Define some unit conversions' do
27
4
  Conversions.register :hundred_cubic_feet_per_square_foot_hour, :cubic_metres_per_square_metre_hour, 30.48
28
5
  Conversions.register :gallons_per_square_foot_hour, :litres_per_square_metre_hour, 40.7458333
@@ -13,11 +13,26 @@ class CensusDivision < ActiveRecord::Base
13
13
  :meeting_building_electricity_intensity => 0.0084323684 / 1.square_feet.to(:square_metres),
14
14
  :meeting_building_district_heat_intensity => 0.0004776370.kbtus.to(:megajoules) / 1.square_feet.to(:square_metres)
15
15
 
16
- data_miner do
17
- tap "Brighter Planet's sanitized census divisions", Earth.taps_server
18
-
19
- process "pull dependencies" do
20
- run_data_miner_on_belongs_to_associations
21
- end
16
+ create_table do
17
+ integer 'number'
18
+ string 'name'
19
+ string 'census_region_name'
20
+ integer 'census_region_number'
21
+ float 'meeting_building_natural_gas_intensity'
22
+ string 'meeting_building_natural_gas_intensity_units'
23
+ float 'meeting_building_fuel_oil_intensity'
24
+ string 'meeting_building_fuel_oil_intensity_units'
25
+ float 'meeting_building_electricity_intensity'
26
+ string 'meeting_building_electricity_intensity_units'
27
+ float 'meeting_building_district_heat_intensity'
28
+ string 'meeting_building_district_heat_intensity_units'
29
+ float 'lodging_building_natural_gas_intensity'
30
+ string 'lodging_building_natural_gas_intensity_units'
31
+ float 'lodging_building_fuel_oil_intensity'
32
+ string 'lodging_building_fuel_oil_intensity_units'
33
+ float 'lodging_building_electricity_intensity'
34
+ string 'lodging_building_electricity_intensity_units'
35
+ float 'lodging_building_district_heat_intensity'
36
+ string 'lodging_building_district_heat_intensity_units'
22
37
  end
23
38
  end
@@ -1,10 +1,5 @@
1
1
  CensusRegion.class_eval do
2
2
  data_miner do
3
- schema Earth.database_options do
4
- integer 'number'
5
- string 'name'
6
- end
7
-
8
3
  import 'the U.S. Census Geographic Terms and Definitions',
9
4
  :url => 'http://www.census.gov/popest/geographic/codes02.csv',
10
5
  :skip => 9,
@@ -7,7 +7,8 @@ class CensusRegion < ActiveRecord::Base
7
7
  # has_many :zip_codes, :through => :census_divisions
8
8
  has_many :residential_energy_consumption_survey_responses, :foreign_key => 'census_region_number'
9
9
 
10
- data_miner do
11
- tap "Brighter Planet's sanitized census regions", Earth.taps_server
10
+ create_table do
11
+ integer 'number'
12
+ string 'name'
12
13
  end
13
14
  end
@@ -1,12 +1,5 @@
1
1
  ClimateDivision.class_eval do
2
2
  data_miner do
3
- schema Earth.database_options do
4
- string 'name'
5
- float 'heating_degree_days'
6
- float 'cooling_degree_days'
7
- string 'state_postal_abbreviation'
8
- end
9
-
10
3
  import "a list of climate divisions and their average heating and cooling degree days",
11
4
  :url => 'http://static.brighterplanet.com/science/data/climate/climate_divisions/climate_divisions.csv' do
12
5
  key 'name'
@@ -6,12 +6,10 @@ class ClimateDivision < ActiveRecord::Base
6
6
 
7
7
  RADIUS = 750
8
8
 
9
- data_miner do
10
- tap "Brighter Planet's sanitized climate divisions", Earth.taps_server
11
-
12
- process "pull dependencies" do
13
- run_data_miner_on_belongs_to_associations
14
- end
9
+ create_table do
10
+ string 'name'
11
+ float 'heating_degree_days'
12
+ float 'cooling_degree_days'
13
+ string 'state_postal_abbreviation'
15
14
  end
16
-
17
15
  end
@@ -1,20 +1,5 @@
1
1
  Country.class_eval do
2
2
  data_miner do
3
- schema Earth.database_options do
4
- string 'iso_3166_code'
5
- string 'name'
6
- float 'automobile_urbanity'
7
- float 'automobile_fuel_efficiency'
8
- string 'automobile_fuel_efficiency_units'
9
- float 'automobile_city_speed'
10
- string 'automobile_city_speed_units'
11
- float 'automobile_highway_speed'
12
- string 'automobile_highway_speed_units'
13
- float 'automobile_trip_distance'
14
- string 'automobile_trip_distance_units'
15
- float 'flight_route_inefficiency_factor'
16
- end
17
-
18
3
  import 'the official ISO country list',
19
4
  :url => 'http://www.iso.org/iso/list-en1-semic-3.txt',
20
5
  :skip => 2,
@@ -40,21 +25,23 @@ Country.class_eval do
40
25
  store 'automobile_trip_distance', :units_field_name => 'automobile_trip_distance_units'
41
26
  end
42
27
 
28
+ process "Ensure AutomobileTypeFuelYear is populated" do
29
+ AutomobileTypeFuelYear.run_data_miner!
30
+ end
31
+
43
32
  # FIXME TODO eventually need to do this for all countries
44
- # process "Derive US average automobile fuel efficiency from AutomobileTypeFuelYear" do
45
- # AutomobileTypeFuelYear.run_data_miner!
46
- #
47
- # scope = AutomobileTypeFuelYear.where(:year => AutomobileTypeFuelYear.maximum(:year))
48
- # fe = scope.sum(:total_travel) / scope.sum(:fuel_consumption)
49
- # units = scope.first.total_travel_units + '_per_' + scope.first.fuel_consumption_units.singularize
50
- #
51
- # connection.execute %{
52
- # UPDATE countries
53
- # SET automobile_fuel_efficiency = #{fe},
54
- # automobile_fuel_efficiency_units = '#{units}'
55
- # WHERE iso_3166_code = 'US'
56
- # }
57
- # end
33
+ process "Derive US average automobile fuel efficiency from AutomobileTypeFuelYear" do
34
+ scope = AutomobileTypeFuelYear.where(:year => AutomobileTypeFuelYear.maximum(:year))
35
+ fe = scope.sum(:total_travel) / scope.sum(:fuel_consumption)
36
+ units = scope.first.total_travel_units + '_per_' + scope.first.fuel_consumption_units.singularize
37
+
38
+ connection.execute %{
39
+ UPDATE countries
40
+ SET automobile_fuel_efficiency = #{fe},
41
+ automobile_fuel_efficiency_units = '#{units}'
42
+ WHERE iso_3166_code = 'US'
43
+ }
44
+ end
58
45
 
59
46
  process "Convert automobile city speed from miles per hour to kilometres per hour" do
60
47
  conversion_factor = 1.miles.to(:kilometres)
@@ -13,13 +13,24 @@ class Country < ActiveRecord::Base
13
13
  :automobile_trip_distance_units => lambda { Country.united_states.automobile_trip_distance_units }, # for now assume US represents world
14
14
  :flight_route_inefficiency_factor => lambda { Country.maximum(:flight_route_inefficiency_factor) } # default to the largest inefficiency factor
15
15
 
16
- data_miner do
17
- tap "Brighter Planet's sanitized countries list", Earth.taps_server
18
- end
19
-
20
16
  class << self
21
17
  def united_states
22
18
  find_by_iso_3166_code('US')
23
19
  end
24
20
  end
21
+
22
+ create_table do
23
+ string 'iso_3166_code'
24
+ string 'name'
25
+ float 'automobile_urbanity'
26
+ float 'automobile_fuel_efficiency'
27
+ string 'automobile_fuel_efficiency_units'
28
+ float 'automobile_city_speed'
29
+ string 'automobile_city_speed_units'
30
+ float 'automobile_highway_speed'
31
+ string 'automobile_highway_speed_units'
32
+ float 'automobile_trip_distance'
33
+ string 'automobile_trip_distance_units'
34
+ float 'flight_route_inefficiency_factor'
35
+ end
25
36
  end
@@ -8,3 +8,6 @@ require 'earth/locality/petroleum_administration_for_defense_district/data_miner
8
8
  require 'earth/locality/state/data_miner'
9
9
  require 'earth/locality/urbanity/data_miner'
10
10
  require 'earth/locality/zip_code/data_miner'
11
+
12
+ require 'earth/automobile/data_miner'
13
+ require 'earth/residence/data_miner'
@@ -1,10 +1,5 @@
1
1
  EgridRegion.class_eval do
2
2
  data_miner do
3
- schema Earth.database_options do
4
- string 'name'
5
- float 'loss_factor'
6
- end
7
-
8
3
  import "eGRID regions and loss factors derived from eGRID 2007 data",
9
4
  :url => 'http://www.epa.gov/cleanenergy/documents/egridzips/eGRID2007_Version1-1.zip',
10
5
  :filename => 'eGRID2007_Version1-1/eGRID2007V1_1_year0504_STIE_USGC.xls',
@@ -3,15 +3,12 @@ class EgridRegion < ActiveRecord::Base
3
3
 
4
4
  has_many :egrid_subregions, :foreign_key => 'egrid_region_name'
5
5
 
6
- data_miner do
7
- tap "Brighter Planet's egrid region data", Earth.taps_server
8
-
9
- process "pull dependencies" do
10
- run_data_miner_on_belongs_to_associations
11
- end
12
- end
13
-
14
6
  # FIXME TODO someday should calculate this from eGRID data: (USTNGN05 + USTNFI05 - USTCON05) / USTNGN05
15
7
  falls_back_on :name => 'fallback',
16
8
  :loss_factor => 0.061879 # calculated using above formula 2/21/2011
9
+
10
+ create_table do
11
+ string 'name'
12
+ float 'loss_factor'
13
+ end
17
14
  end
@@ -1,24 +1,5 @@
1
1
  EgridSubregion.class_eval do
2
2
  data_miner do
3
- schema Earth.database_options do
4
- string 'abbreviation'
5
- string 'name'
6
- string 'nerc_abbreviation'
7
- string 'egrid_region_name'
8
- float 'net_generation'
9
- string 'net_generation_units'
10
- float 'electricity_co2_emission_factor'
11
- string 'electricity_co2_emission_factor_units'
12
- float 'electricity_co2_biogenic_emission_factor'
13
- string 'electricity_co2_biogenic_emission_factor_units'
14
- float 'electricity_ch4_emission_factor'
15
- string 'electricity_ch4_emission_factor_units'
16
- float 'electricity_n2o_emission_factor'
17
- string 'electricity_n2o_emission_factor_units'
18
- float 'electricity_emission_factor'
19
- string 'electricity_emission_factor_units'
20
- end
21
-
22
3
  # FIXME TODO for some reason this doesn't work...
23
4
  # import "eGRID regions and electricity emission factors derived from eGRID 2007 data",
24
5
  # :url => 'http://www.epa.gov/cleanenergy/documents/egridzips/eGRID2007_Version1-1.zip',
@@ -56,7 +37,7 @@ EgridSubregion.class_eval do
56
37
  WHERE electricity_co2_emission_factor_units = 'pounds_per_megawatt_hour' }
57
38
  end
58
39
 
59
- process "Insure necessary datasets are imported" do
40
+ process "Insure GreenhouseGas is populated" do
60
41
  GreenhouseGas.run_data_miner!
61
42
  end
62
43
 
@@ -23,11 +23,22 @@ class EgridSubregion < ActiveRecord::Base
23
23
  :electricity_emission_factor => lambda { weighted_average(:electricity_emission_factor, :weighted_by => :net_generation) }, # DEPRECATED
24
24
  :electricity_emission_factor_units => 'kilograms_co2e_per_kilowatt_hour' # DEPRECATED
25
25
 
26
- data_miner do
27
- tap "Brighter Planet's egrid subregion data", Earth.taps_server
28
-
29
- process "pull dependencies" do
30
- run_data_miner_on_belongs_to_associations
31
- end
26
+ create_table do
27
+ string 'abbreviation'
28
+ string 'name'
29
+ string 'nerc_abbreviation'
30
+ string 'egrid_region_name'
31
+ float 'net_generation'
32
+ string 'net_generation_units'
33
+ float 'electricity_co2_emission_factor'
34
+ string 'electricity_co2_emission_factor_units'
35
+ float 'electricity_co2_biogenic_emission_factor'
36
+ string 'electricity_co2_biogenic_emission_factor_units'
37
+ float 'electricity_ch4_emission_factor'
38
+ string 'electricity_ch4_emission_factor_units'
39
+ float 'electricity_n2o_emission_factor'
40
+ string 'electricity_n2o_emission_factor_units'
41
+ float 'electricity_emission_factor'
42
+ string 'electricity_emission_factor_units'
32
43
  end
33
44
  end
@@ -1,21 +1,12 @@
1
1
  PetroleumAdministrationForDefenseDistrict.class_eval do
2
2
  data_miner do
3
- schema Earth.database_options do
4
- string 'code'
5
- string 'district_code'
6
- string 'district_name'
7
- string 'subdistrict_code'
8
- string 'subdistrict_name'
9
- end
10
-
11
3
  import "a list of PADD districts and states derived from the EIA PADD definitions",
12
4
  :url => 'http://spreadsheets.google.com/pub?key=t5HM1KbaRngmTUbntg8JwPA&gid=0&output=csv' do
13
5
  key 'code', :field_name => 'Code'
14
- store 'district_code', :field_name => 'PAD district code'
15
- store 'subdistrict_code', :field_name => 'PAD subdistrict code'
16
- store 'district_name', :field_name => 'PAD district name'
17
- store 'subdistrict_name', :field_name => 'PAD subdistrict name'
6
+ store 'district_code', :field_name => 'PAD district code', :nullify => true
7
+ store 'subdistrict_code', :field_name => 'PAD subdistrict code', :nullify => true
8
+ store 'district_name', :field_name => 'PAD district name', :nullify => true
9
+ store 'subdistrict_name', :field_name => 'PAD subdistrict name', :nullify => true
18
10
  end
19
11
  end
20
12
  end
21
-
@@ -2,13 +2,17 @@ class PetroleumAdministrationForDefenseDistrict < ActiveRecord::Base
2
2
  set_primary_key :code
3
3
  set_table_name :petroleum_districts
4
4
 
5
- data_miner do
6
- tap "Brighter Planet's PADD info", Earth.taps_server
7
- end
8
-
9
5
  def name
10
6
  str = "PAD District #{district_code} (#{district_name})"
11
7
  str << " Subdistrict #{district_code}#{subdistrict_code} (#{subdistrict_name})" if subdistrict_code
12
8
  str
13
9
  end
10
+
11
+ create_table do
12
+ string 'code'
13
+ string 'district_code'
14
+ string 'district_name'
15
+ string 'subdistrict_code'
16
+ string 'subdistrict_name'
17
+ end
14
18
  end