earth 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (239) hide show
  1. data/Rakefile +9 -21
  2. data/data/rail/ntd_companies.csv +1 -0
  3. data/data/rail/ntd_fuel_consumption.csv +1 -0
  4. data/data/rail/ntd_modes.csv +1 -0
  5. data/data/rail/ntd_service.csv +1 -0
  6. data/errata/flight_segment/bts_errata.csv +6 -0
  7. data/lib/earth.rb +1 -0
  8. data/lib/earth/air/aircraft.rb +3 -5
  9. data/lib/earth/air/airline.rb +2 -3
  10. data/lib/earth/air/airport.rb +4 -5
  11. data/lib/earth/air/bts_aircraft.rb +1 -1
  12. data/lib/earth/air/flight_distance_class.rb +0 -1
  13. data/lib/earth/air/flight_distance_class/data_miner.rb +0 -4
  14. data/lib/earth/air/flight_distance_class_seat_class.rb +0 -1
  15. data/lib/earth/air/flight_segment.rb +12 -13
  16. data/lib/earth/air/flight_segment/data_miner.rb +13 -0
  17. data/lib/earth/automobile/automobile_activity_year.rb +0 -1
  18. data/lib/earth/automobile/automobile_activity_year_type.rb +4 -4
  19. data/lib/earth/automobile/automobile_activity_year_type_fuel.rb +1 -2
  20. data/lib/earth/automobile/automobile_fuel.rb +1 -2
  21. data/lib/earth/automobile/automobile_make.rb +0 -1
  22. data/lib/earth/automobile/automobile_make/data_miner.rb +2 -0
  23. data/lib/earth/automobile/automobile_make_model.rb +1 -2
  24. data/lib/earth/automobile/automobile_make_model_year_variant.rb +0 -1
  25. data/lib/earth/automobile/automobile_make_model_year_variant/data_miner.rb +2 -223
  26. data/lib/earth/automobile/automobile_make_model_year_variant/parser.rb +224 -0
  27. data/lib/earth/automobile/automobile_make_year_fleet.rb +0 -1
  28. data/lib/earth/automobile/automobile_model.rb +0 -1
  29. data/lib/earth/automobile/automobile_size_class.rb +0 -1
  30. data/lib/earth/automobile/automobile_type_fuel.rb +0 -1
  31. data/lib/earth/automobile/automobile_type_fuel_control.rb +0 -1
  32. data/lib/earth/automobile/automobile_type_fuel_year.rb +4 -4
  33. data/lib/earth/automobile/automobile_type_fuel_year_control.rb +7 -15
  34. data/lib/earth/automobile/automobile_year.rb +0 -1
  35. data/lib/earth/bus/bus_class.rb +0 -1
  36. data/lib/earth/bus/bus_fuel.rb +1 -72
  37. data/lib/earth/bus/bus_fuel_control.rb +0 -1
  38. data/lib/earth/bus/bus_fuel_control/data_miner.rb +0 -2
  39. data/lib/earth/bus/bus_fuel_year_control.rb +0 -1
  40. data/lib/earth/bus/bus_fuel_year_control/data_miner.rb +0 -2
  41. data/lib/earth/computation/computation_carrier.rb +1 -11
  42. data/lib/earth/computation/computation_carrier_instance_class.rb +4 -25
  43. data/lib/earth/computation/computation_carrier_region.rb +0 -1
  44. data/lib/earth/computation/computation_carrier_region/data_miner.rb +0 -3
  45. data/lib/earth/diet/diet_class.rb +0 -1
  46. data/lib/earth/diet/food_group.rb +1 -1
  47. data/lib/earth/electricity/electric_market.rb +2 -0
  48. data/lib/earth/electricity/electric_utility.rb +11 -4
  49. data/lib/earth/electricity/electric_utility/data_miner.rb +2 -8
  50. data/lib/earth/electricity/green_button_adoption.rb +2 -1
  51. data/lib/earth/fuel/fuel.rb +20 -81
  52. data/lib/earth/fuel/fuel_year.rb +0 -44
  53. data/lib/earth/fuel/greenhouse_gas.rb +0 -40
  54. data/lib/earth/hospitality/lodging_class.rb +0 -1
  55. data/lib/earth/industry/cbecs_energy_intensity.rb +25 -29
  56. data/lib/earth/industry/cbecs_energy_intensity/data_miner.rb +1 -1
  57. data/lib/earth/industry/industry.rb +1 -2
  58. data/lib/earth/industry/mecs_energy.rb +9 -10
  59. data/lib/earth/industry/mecs_ratio.rb +2 -1
  60. data/lib/earth/industry/merchant_category.rb +1 -0
  61. data/lib/earth/industry/naics_2002.rb +2 -0
  62. data/lib/earth/industry/naics_2002_naics_2007_concordance.rb +1 -0
  63. data/lib/earth/industry/naics_2002_sic_1987_concordance.rb +1 -0
  64. data/lib/earth/industry/naics_2007.rb +1 -0
  65. data/lib/earth/industry/sic_1987.rb +1 -0
  66. data/lib/earth/locality/census_division.rb +1 -3
  67. data/lib/earth/locality/climate_division.rb +0 -1
  68. data/lib/earth/locality/country.rb +1 -2
  69. data/lib/earth/locality/country/data_miner.rb +4 -0
  70. data/lib/earth/locality/egrid_country.rb +0 -1
  71. data/lib/earth/locality/egrid_region.rb +1 -3
  72. data/lib/earth/locality/egrid_subregion.rb +1 -3
  73. data/lib/earth/locality/electricity_mix.rb +2 -4
  74. data/lib/earth/locality/petroleum_administration_for_defense_district.rb +0 -1
  75. data/lib/earth/locality/state.rb +0 -1
  76. data/lib/earth/locality/zip_code.rb +0 -1
  77. data/lib/earth/model.rb +1 -1
  78. data/lib/earth/pet/breed.rb +0 -1
  79. data/lib/earth/pet/breed_gender.rb +0 -1
  80. data/lib/earth/pet/gender.rb +0 -1
  81. data/lib/earth/pet/species.rb +1 -3
  82. data/lib/earth/rail/country_rail_class.rb +0 -1
  83. data/lib/earth/rail/country_rail_traction.rb +0 -1
  84. data/lib/earth/rail/country_rail_traction_class.rb +0 -1
  85. data/lib/earth/rail/national_transit_database_company.rb +1 -3
  86. data/lib/earth/rail/national_transit_database_company/data_miner.rb +1 -1
  87. data/lib/earth/rail/national_transit_database_mode.rb +0 -1
  88. data/lib/earth/rail/national_transit_database_mode/data_miner.rb +1 -1
  89. data/lib/earth/rail/national_transit_database_record.rb +0 -1
  90. data/lib/earth/rail/national_transit_database_record/data_miner.rb +2 -2
  91. data/lib/earth/rail/rail_class.rb +0 -1
  92. data/lib/earth/rail/rail_class/data_miner.rb +5 -4
  93. data/lib/earth/rail/rail_company.rb +0 -1
  94. data/lib/earth/rail/rail_fuel.rb +0 -1
  95. data/lib/earth/rail/rail_traction.rb +0 -1
  96. data/lib/earth/rail/rail_traction/data_miner.rb +2 -8
  97. data/lib/earth/residence/air_conditioner_use.rb +0 -1
  98. data/lib/earth/residence/clothes_machine_use.rb +0 -1
  99. data/lib/earth/residence/dishwasher_use.rb +0 -1
  100. data/lib/earth/residence/residence_appliance.rb +0 -1
  101. data/lib/earth/residence/residence_class.rb +0 -1
  102. data/lib/earth/residence/residence_fuel_price.rb +1 -2
  103. data/lib/earth/residence/urbanity.rb +0 -1
  104. data/lib/earth/shipping/carrier.rb +1 -52
  105. data/lib/earth/shipping/carrier_mode.rb +0 -34
  106. data/lib/earth/shipping/shipment_mode.rb +0 -26
  107. data/lib/earth/tasks.rb +14 -4
  108. data/lib/earth/version.rb +1 -1
  109. data/spec/earth/air/aircraft_spec.rb +9 -1
  110. data/spec/earth/air/airline_spec.rb +2 -2
  111. data/spec/earth/air/airport_spec.rb +1 -2
  112. data/spec/earth/air/bts_aircraft_spec.rb +2 -2
  113. data/spec/earth/air/flight_distance_class_seat_class_spec.rb +22 -0
  114. data/spec/earth/air/flight_distance_class_spec.rb +26 -18
  115. data/spec/earth/air/flight_seat_class_spec.rb +12 -0
  116. data/spec/earth/air/flight_segment_spec.rb +38 -33
  117. data/spec/earth/automobile/automobile_activity_year_spec.rb +20 -14
  118. data/spec/earth/automobile/automobile_activity_year_type_fuel_spec.rb +14 -10
  119. data/spec/earth/automobile/automobile_activity_year_type_spec.rb +28 -20
  120. data/spec/earth/automobile/automobile_fuel_spec.rb +106 -52
  121. data/spec/earth/automobile/automobile_make_model_spec.rb +103 -62
  122. data/spec/earth/automobile/automobile_make_model_year_spec.rb +69 -46
  123. data/spec/earth/automobile/automobile_make_model_year_variant_spec.rb +108 -109
  124. data/spec/earth/automobile/automobile_make_spec.rb +8 -8
  125. data/spec/earth/automobile/automobile_make_year_fleet_spec.rb +10 -6
  126. data/spec/earth/automobile/automobile_make_year_spec.rb +10 -9
  127. data/spec/earth/automobile/automobile_model_spec.rb +3 -0
  128. data/spec/earth/automobile/automobile_size_class_spec.rb +12 -11
  129. data/spec/earth/automobile/automobile_type_fuel_control_spec.rb +9 -9
  130. data/spec/earth/automobile/automobile_type_fuel_spec.rb +23 -18
  131. data/spec/earth/automobile/automobile_type_fuel_year_control_spec.rb +37 -29
  132. data/spec/earth/automobile/automobile_type_fuel_year_spec.rb +35 -36
  133. data/spec/earth/automobile/automobile_year_spec.rb +4 -2
  134. data/spec/earth/bus/bus_class_spec.rb +10 -0
  135. data/spec/earth/bus/bus_fuel_control_spec.rb +3 -5
  136. data/spec/earth/bus/bus_fuel_spec.rb +16 -8
  137. data/spec/earth/bus/bus_fuel_year_control_spec.rb +7 -7
  138. data/spec/earth/computation/computation_carrrier_instance_class_spec.rb +17 -0
  139. data/spec/earth/computation/computation_carrrier_region_spec.rb +10 -0
  140. data/spec/earth/computation/computation_carrrier_spec.rb +17 -0
  141. data/spec/earth/diet/diet_class_spec.rb +14 -0
  142. data/spec/earth/diet/food_group_spec.rb +26 -0
  143. data/spec/earth/electricity/electric_market_spec.rb +4 -5
  144. data/spec/earth/electricity/electric_utility_spec.rb +30 -19
  145. data/spec/earth/electricity/green_button_adoption_spec.rb +29 -7
  146. data/spec/earth/fuel/fuel_spec.rb +88 -14
  147. data/spec/earth/fuel/fuel_year_spec.rb +21 -0
  148. data/spec/earth/fuel/greenhouse_gas_spec.rb +23 -0
  149. data/spec/earth/hospitality/commercial_building_energy_consumption_survey_response_spec.rb +13 -10
  150. data/spec/earth/hospitality/lodging_class_spec.rb +1 -1
  151. data/spec/earth/industry/cbecs_energy_intensity_spec.rb +72 -72
  152. data/spec/earth/industry/industry_spec.rb +16 -9
  153. data/spec/earth/industry/mecs_energy_spec.rb +76 -72
  154. data/spec/earth/industry/mecs_ratio_spec.rb +35 -31
  155. data/spec/earth/industry/merchant_category_spec.rb +7 -5
  156. data/spec/earth/industry/naics_2002_naics_2007_concordance_spec.rb +10 -19
  157. data/spec/earth/industry/naics_2002_sic_1987_concordance_spec.rb +9 -19
  158. data/spec/earth/industry/naics_2002_spec.rb +1 -11
  159. data/spec/earth/industry/naics_2007_spec.rb +2 -11
  160. data/spec/earth/industry/sic_1987_spec.rb +3 -14
  161. data/spec/earth/locality/census_division_spec.rb +25 -0
  162. data/spec/earth/locality/census_region_spec.rb +8 -0
  163. data/spec/earth/locality/climate_division_spec.rb +13 -0
  164. data/spec/earth/locality/country_spec.rb +24 -23
  165. data/spec/earth/locality/egrid_country_spec.rb +7 -6
  166. data/spec/earth/locality/egrid_region_spec.rb +6 -6
  167. data/spec/earth/locality/egrid_subregion_spec.rb +14 -14
  168. data/spec/earth/locality/electricity_mix_spec.rb +17 -17
  169. data/spec/earth/locality/padd_spec.rb +21 -0
  170. data/spec/earth/locality/state_spec.rb +8 -11
  171. data/spec/earth/locality/zip_code_spec.rb +29 -22
  172. data/spec/earth/pet/breed_gender_spec.rb +8 -0
  173. data/spec/earth/pet/breed_spec.rb +8 -0
  174. data/spec/earth/pet/gender_spec.rb +8 -0
  175. data/spec/earth/pet/species_spec.rb +11 -5
  176. data/spec/earth/rail/country_rail_class_spec.rb +16 -0
  177. data/spec/earth/rail/country_rail_traction_class_spec.rb +14 -0
  178. data/spec/earth/rail/country_rail_traction_spec.rb +14 -0
  179. data/spec/earth/rail/national_transit_database_company_spec.rb +103 -0
  180. data/spec/earth/rail/national_transit_database_mode_spec.rb +21 -0
  181. data/spec/earth/rail/national_transit_database_record_spec.rb +31 -0
  182. data/spec/earth/rail/rail_class_spec.rb +8 -0
  183. data/spec/earth/rail/rail_company_spec.rb +20 -0
  184. data/spec/earth/rail/rail_fuel_spec.rb +19 -0
  185. data/spec/earth/rail/rail_traction_spec.rb +8 -0
  186. data/spec/earth/residence/air_conditioner_use_spec.rb +17 -0
  187. data/spec/earth/residence/clothes_machine_use_spec.rb +11 -0
  188. data/spec/earth/residence/dishwasher_use_spec.rb +11 -0
  189. data/spec/earth/residence/residence_appliance_spec.rb +19 -0
  190. data/spec/earth/residence/residence_class_spec.rb +15 -0
  191. data/spec/earth/residence/residence_fuel_price_spec.rb +12 -0
  192. data/spec/earth/residence/residence_fuel_type_spec.rb +18 -0
  193. data/spec/earth/residence/residential_energy_consumption_survey_response_spec.rb +13 -0
  194. data/spec/earth/residence/urbanity_spec.rb +8 -0
  195. data/spec/earth/shipping/carrier_mode_spec.rb +18 -0
  196. data/spec/earth/shipping/carrier_spec.rb +27 -0
  197. data/spec/earth/shipping/shipment_mode_spec.rb +16 -0
  198. data/spec/earth_spec.rb +1 -1
  199. data/spec/factories/airline.rb +0 -1
  200. data/spec/factories/airport.rb +0 -1
  201. data/spec/factories/automobile_activity_year.rb +8 -0
  202. data/spec/factories/automobile_activity_year_type.rb +8 -0
  203. data/spec/factories/automobile_activity_year_type_fuel.rb +9 -0
  204. data/spec/factories/automobile_fuel.rb +15 -0
  205. data/spec/factories/automobile_make.rb +9 -0
  206. data/spec/factories/automobile_make_model.rb +10 -0
  207. data/spec/factories/automobile_make_model_year.rb +9 -0
  208. data/spec/factories/automobile_model.rb +9 -0
  209. data/spec/factories/automobile_type_fuel.rb +7 -0
  210. data/spec/factories/automobile_type_fuel_control.rb +16 -0
  211. data/spec/factories/automobile_type_fuel_year.rb +9 -0
  212. data/spec/factories/automobile_type_fuel_year_control.rb +11 -0
  213. data/spec/factories/bus_fuel.rb +7 -0
  214. data/spec/factories/bus_fuel_year_control.rb +9 -0
  215. data/spec/factories/cbecs_energy_intensity.rb +15 -0
  216. data/spec/factories/commercial_building_energy_consumption_survey_response.rb +10 -0
  217. data/spec/factories/electric_utility.rb +8 -0
  218. data/spec/factories/flight_distance_class.rb +8 -0
  219. data/spec/factories/flight_segment.rb +0 -1
  220. data/spec/factories/food_group.rb +8 -0
  221. data/spec/factories/fuel.rb +8 -0
  222. data/spec/factories/fuel_year.rb +8 -0
  223. data/spec/factories/green_button_adoption.rb +8 -0
  224. data/spec/factories/greenhouse_gas.rb +7 -0
  225. data/spec/factories/industry.rb +9 -0
  226. data/spec/factories/mecs_energy.rb +15 -0
  227. data/spec/factories/mecs_ratio.rb +15 -0
  228. data/spec/factories/national_transit_database_company.rb +8 -0
  229. data/spec/factories/national_transit_database_mode.rb +8 -0
  230. data/spec/factories/national_transit_database_record.rb +9 -0
  231. data/spec/factories/residence_appliance.rb +7 -0
  232. data/spec/factories/zip_code.rb +9 -0
  233. data/spec/spec_helper.rb +36 -19
  234. metadata +346 -66
  235. data/lib/earth/acronyms.rb +0 -12
  236. data/lib/earth/rail/rail_company_traction.rb +0 -24
  237. data/lib/earth/rail/rail_company_traction/data_miner.rb +0 -4
  238. data/lib/earth/rail/rail_company_traction_class.rb +0 -26
  239. data/lib/earth/rail/rail_company_traction_class/data_miner.rb +0 -4
@@ -18,7 +18,5 @@ BusFuelYearControl.class_eval do
18
18
  process "Derive bus fuel control name for association with BusFuelControl" do
19
19
  update_all "bus_fuel_control_name = bus_fuel_name || ' ' || control"
20
20
  end
21
-
22
- # FIXME TODO verify that for any year the percentages sum to 1
23
21
  end
24
22
  end
@@ -1,6 +1,5 @@
1
- require 'falls_back_on'
2
-
3
1
  require 'earth/model'
2
+ require 'falls_back_on'
4
3
 
5
4
  class ComputationCarrier < ActiveRecord::Base
6
5
  extend Earth::Model
@@ -20,14 +19,5 @@ EOS
20
19
  falls_back_on :name => 'fallback',
21
20
  :power_usage_effectiveness => lambda { ComputationCarrier.maximum('power_usage_effectiveness') }
22
21
 
23
-
24
- # verify "Power usage effectiveness should be one or more" do
25
- # ComputationCarrier.all.each do |carrier|
26
- # unless carrier.power_usage_effectiveness >= 1.0
27
- # raise "Invalid power usage effectiveness for ComputationCarrier #{carrier.name}: #{carrier.power_usage_effectiveness} (should be >= 1.0)"
28
- # end
29
- # end
30
- # end
31
-
32
22
  warn_unless_size 1
33
23
  end
@@ -1,6 +1,5 @@
1
- require 'falls_back_on'
2
-
3
1
  require 'earth/model'
2
+ require 'falls_back_on'
4
3
 
5
4
  require 'earth/computation/computation_carrier'
6
5
 
@@ -24,29 +23,9 @@ EOS
24
23
 
25
24
  belongs_to :carrier, :class_name => 'ComputationCarrier', :foreign_key => 'computation_carrier_name'
26
25
 
27
- falls_back_on :name => 'fallback',
28
- :electricity_intensity => lambda { ComputationCarrierInstanceClass.find_by_name('Amazon m1.small').electricity_intensity },
29
- :electricity_intensity_units => lambda { ComputationCarrierInstanceClass.find_by_name('Amazon m1.small').electricity_intensity_units }
30
-
26
+ def self.fallback
27
+ find_by_name 'Amazon m1.small'
28
+ end
31
29
 
32
- # FIXME TODO verify that computation carrier name appears in computation_carriers
33
-
34
- # verify "Electricity intensity should be more than zero" do
35
- # ComputationCarrierInstanceClass.all.each do |instance_class|
36
- # unless instance_class.electricity_intensity > 0
37
- # raise "Invalid electricity intensity for ComputationCarrierInstanceClass #{instance_class.name}: #{instance_class.electricity_intensity} (should be > 0)"
38
- # end
39
- # end
40
- # end
41
- #
42
- # verify "Electricity intensity units should be kilowatts" do
43
- # ComputationCarrierInstanceClass.all.each do |instance_class|
44
- # unless instance_class.electricity_intensity_units == 'kilowatts'
45
- # raise "Invalid electricity intensity units for ComputationCarrierInstanceClass #{instance_class.name}: #{instance_class.electricity_intensity_units} (should be kilowatts)"
46
- # end
47
- # end
48
- # end
49
-
50
-
51
30
  warn_unless_size 8
52
31
  end
@@ -21,6 +21,5 @@ EOS
21
21
 
22
22
  belongs_to :egrid_subregion, :foreign_key => 'egrid_subregion_abbreviation'
23
23
 
24
-
25
24
  warn_unless_size 4
26
25
  end
@@ -7,8 +7,5 @@ ComputationCarrierRegion.class_eval do
7
7
  store 'region'
8
8
  store 'egrid_subregion_abbreviation'
9
9
  end
10
-
11
- # FIXME TODO verify carrier_name appears in Carrier
12
- # FIXME TODO verify egrid_subregion_abbreviation appears in EgridSubregion
13
10
  end
14
11
  end
@@ -32,6 +32,5 @@ EOS
32
32
  end
33
33
  end
34
34
 
35
-
36
35
  warn_unless_size 3
37
36
  end
@@ -21,7 +21,7 @@ EOS
21
21
 
22
22
  class << self
23
23
  def names
24
- connection.select_values arel_table.project(:name).to_sql
24
+ all.map(&:name)
25
25
  end
26
26
 
27
27
  def [](name)
@@ -21,4 +21,6 @@ EOS
21
21
 
22
22
  belongs_to :electric_utility, :foreign_key => 'electric_utility_eia_id'
23
23
  belongs_to :zip_code, :foreign_key => 'zip_code_name'
24
+
25
+ warn_unless_size 64864
24
26
  end
@@ -6,8 +6,14 @@ require 'earth/locality/state'
6
6
  require 'earth/locality/zip_code'
7
7
 
8
8
  class ElectricUtility < ActiveRecord::Base
9
+ data_miner do
10
+ process "Data mine GreenButtonAdoption because it's like a belongs_to association" do
11
+ GreenButtonAdoption.run_data_miner!
12
+ end
13
+ end
14
+
9
15
  extend Earth::Model
10
-
16
+
11
17
  TABLE_STRUCTURE = <<-EOS
12
18
 
13
19
  CREATE TABLE electric_utilities
@@ -28,12 +34,13 @@ EOS
28
34
  has_many :electric_markets, :foreign_key => :electric_utility_eia_id
29
35
  has_many :zip_codes, :through => :electric_markets
30
36
 
31
-
32
37
  def green_button_implementer?
33
- GreenButtonAdoption.implemented? name, nickname
38
+ GreenButtonAdoption.implemented? name, nickname
34
39
  end
35
-
40
+
36
41
  def green_button_committer?
37
42
  GreenButtonAdoption.committed? name, nickname
38
43
  end
44
+
45
+ warn_unless_size 3265
39
46
  end
@@ -1,11 +1,5 @@
1
- require 'earth/electricity/green_button_adoption'
2
-
3
1
  ElectricUtility.class_eval do
4
2
  data_miner do
5
- process "make sure green button adoption is populated" do
6
- GreenButtonAdoption.run_data_miner!
7
- end
8
-
9
3
  import 'EIA Form 861 records from 2010 (revised)',
10
4
  :url => 'http://www.eia.gov/Ftproot/pub/electricity/f86110.zip',
11
5
  :filename => 'file1_2010.xls',
@@ -17,8 +11,8 @@ ElectricUtility.class_eval do
17
11
  store 'nerc_region_abbreviation', :synthesize => proc { |row| (first_nerc = row['NERC_LOCATION'].match(/^(\w+)/))? first_nerc.captures[0] : nil }
18
12
  store 'second_nerc_region_abbreviation', :synthesize => proc { |row| (second_nerc = row['NERC_LOCATION'].match(/^\w+ ?[&,\/] ?(\w+)$/)) ? second_nerc.captures[0] : nil }
19
13
  end
20
-
21
- import 'Aliases', :url => 'https://docs.google.com/spreadsheet/pub?key=0AtyCBJLCFHlwdEM5WjVxRjBKWVJRcTJ3c1BhUnlSVXc&single=true&gid=0&output=csv' do
14
+
15
+ import 'aliases', :url => 'https://docs.google.com/spreadsheet/pub?key=0AtyCBJLCFHlwdEM5WjVxRjBKWVJRcTJ3c1BhUnlSVXc&single=true&gid=0&output=csv' do
22
16
  key 'eia_id', :field_name => 'utility_id'
23
17
  store 'nickname', :field_name => 'alias'
24
18
  end
@@ -16,7 +16,6 @@ EOS
16
16
 
17
17
  self.primary_key = "electric_utility_name"
18
18
 
19
-
20
19
  class << self
21
20
  def implemented?(*names)
22
21
  names.any? do |name|
@@ -29,4 +28,6 @@ EOS
29
28
  end
30
29
  end
31
30
  end
31
+
32
+ warn_unless_size 23
32
33
  end
@@ -3,10 +3,8 @@ require 'earth/model'
3
3
  require 'earth/fuel/fuel_year'
4
4
 
5
5
  class Fuel < ActiveRecord::Base
6
- # Need to ensure FuelYear gets data_mined even when pulling with taps
7
- # b/c Fuel has instance methods to look up missing values from FuelYear
8
6
  data_miner do
9
- process "Ensure FuelYear is imported" do
7
+ process "Data mine FuelYear because some methods are delegated to it" do
10
8
  FuelYear.run_data_miner!
11
9
  end
12
10
  end
@@ -40,88 +38,29 @@ EOS
40
38
  has_many :fuel_years, :foreign_key => 'fuel_name'
41
39
 
42
40
  def latest_fuel_year
43
- fuel_years.find_by_year(fuel_years.maximum('year'))
41
+ fuel_years.find_by_year fuel_years.maximum(:year)
44
42
  end
45
43
 
46
- def energy_content
47
- if content = super
48
- content
49
- elsif fuel_years.present?
50
- latest_fuel_year.energy_content
44
+ [
45
+ :energy_content,
46
+ :energy_content_units,
47
+ :carbon_content,
48
+ :carbon_content_units,
49
+ :oxidation_factor,
50
+ :biogenic_fraction,
51
+ :co2_emission_factor,
52
+ :co2_emission_factor_units,
53
+ :co2_biogenic_emission_factor,
54
+ :co2_biogenic_emission_factor_units
55
+ ].each do |method_name|
56
+ define_method method_name do
57
+ if attribute = super()
58
+ attribute
59
+ elsif fuel_years.present?
60
+ latest_fuel_year.send method_name
61
+ end
51
62
  end
52
63
  end
53
64
 
54
- def energy_content_units
55
- if units = super
56
- units
57
- elsif fuel_years.present?
58
- latest_fuel_year.energy_content_units
59
- end
60
- end
61
-
62
- def carbon_content
63
- if content = super
64
- content
65
- elsif fuel_years.present?
66
- latest_fuel_year.carbon_content
67
- end
68
- end
69
-
70
- def carbon_content_units
71
- if units = super
72
- units
73
- elsif fuel_years.present?
74
- latest_fuel_year.carbon_content_units
75
- end
76
- end
77
-
78
- def oxidation_factor
79
- if oxidation_factor = super
80
- oxidation_factor
81
- elsif fuel_years.present?
82
- latest_fuel_year.oxidation_factor
83
- end
84
- end
85
-
86
- def biogenic_fraction
87
- if biogenic_fraction = super
88
- biogenic_fraction
89
- elsif fuel_years.present?
90
- latest_fuel_year.biogenic_fraction
91
- end
92
- end
93
-
94
- def co2_emission_factor
95
- if ef = super
96
- ef
97
- elsif fuel_years.present?
98
- latest_fuel_year.co2_emission_factor
99
- end
100
- end
101
-
102
- def co2_emission_factor_units
103
- if units = super
104
- units
105
- elsif fuel_years.present?
106
- latest_fuel_year.co2_emission_factor_units
107
- end
108
- end
109
-
110
- def co2_biogenic_emission_factor
111
- if ef = super
112
- ef
113
- elsif fuel_years.present?
114
- latest_fuel_year.co2_biogenic_emission_factor
115
- end
116
- end
117
-
118
- def co2_biogenic_emission_factor_units
119
- if units = super
120
- units
121
- elsif fuel_years.present?
122
- latest_fuel_year.co2_biogenic_emission_factor_units
123
- end
124
- end
125
-
126
65
  warn_unless_size 23
127
66
  end
@@ -30,49 +30,5 @@ EOS
30
30
 
31
31
  belongs_to :fuel, :foreign_key => 'fuel_name'
32
32
 
33
-
34
- # FIXME TODO verify fuel name is in Fuel
35
- # verify "Fuel name should never be missing" do
36
- # FuelYear.all.each do |record|
37
- # fuel_name = record.send(:fuel_name)
38
- # if fuel_name.nil?
39
- # raise "Missing fuel name for FuelYear '#{record.name}'"
40
- # end
41
- # end
42
- # end
43
- #
44
- # verify "Year should be from 1990 to 2008" do
45
- # FuelYear.all.each do |record|
46
- # year = record.send(:year)
47
- # unless year > 1989 and year < 2009
48
- # raise "Invalid year for FuelYear '#{record.name}': #{year} (should be from 1990 to 2008)"
49
- # end
50
- # end
51
- # end
52
- #
53
- # verify "Carbon content and energy content should be greater than zero" do
54
- # FuelYear.all.each do |record|
55
- # %w{ carbon_content energy_content }.each do |attribute|
56
- # value = record.send(:"#{attribute}")
57
- # unless value > 0
58
- # raise "Invalid #{attribute} for FuelYear '#{record.name}': #{value} (should be > 0)"
59
- # end
60
- # end
61
- # end
62
- # end
63
- #
64
- # verify "Emission factors should be zero or more" do
65
- # FuelYear.all.each do |record|
66
- # %w{ co2_emission_factor co2_biogenic_emission_factor }.each do |attribute|
67
- # value = record.send(:"#{attribute}")
68
- # unless value >= 0
69
- # raise "Invalid #{attribute} for FuelYear '#{record.name}': #{value} (should be >= 0)"
70
- # end
71
- # end
72
- # end
73
- # end
74
- #
75
- # FIXME TODO verify units
76
-
77
33
  warn_unless_size 171
78
34
  end
@@ -25,45 +25,5 @@ EOS
25
25
  end
26
26
  end
27
27
 
28
-
29
- # verify "Abbreviation and IPCC report should never be missing" do
30
- # GreenhouseGas.all.each do |record|
31
- # %w{ abbreviation ipcc_report }.each do |attribute|
32
- # value = record.send(:"#{attribute}")
33
- # unless value.present?
34
- # raise "Missing #{attribute} for GreenhouseGas '#{record.name}'"
35
- # end
36
- # end
37
- # end
38
- # end
39
- #
40
- # verify "Time horizon should be 100" do
41
- # GreenhouseGas.all.each do |record|
42
- # value = record.send(:time_horizon)
43
- # unless value == 100
44
- # raise "Invalid time horizon for GreenhouseGas '#{record.name}': #{value} (should be 100)"
45
- # end
46
- # end
47
- # end
48
- #
49
- # verify "Time horizon units should be years" do
50
- # GreenhouseGas.all.each do |record|
51
- # units = record.send(:time_horizon_units)
52
- # unless units == "years"
53
- # raise "Invalid time horizon units for GreenhouseGas '#{record.name}': #{units} (should be years)"
54
- # end
55
- # end
56
- # end
57
- #
58
- # verify "Global warming potential should be one or more" do
59
- # GreenhouseGas.all.each do |record|
60
- # value = record.send(:global_warming_potential)
61
- # unless value >= 1
62
- # raise "Invalid global warming potential for GreenhouseGas '#{record.name}': #{value} (should >= 1)"
63
- # end
64
- # end
65
- # end
66
-
67
-
68
28
  warn_unless_size 4
69
29
  end
@@ -14,6 +14,5 @@ EOS
14
14
 
15
15
  self.primary_key = "name"
16
16
 
17
-
18
17
  warn_unless_size 3
19
18
  end
@@ -1,7 +1,29 @@
1
1
  require 'earth/model'
2
- require 'earth/locality'
3
2
 
4
3
  class CbecsEnergyIntensity < ActiveRecord::Base
4
+ FUELS = {
5
+ :electricity => {
6
+ :consumption => :billion_kilowatt_hours,
7
+ :intensity => :kilowatt_hours_per_square_foot,
8
+ :set => 10
9
+ },
10
+ :natural_gas => {
11
+ :consumption => :billion_cubic_feet_of_natural_gas,
12
+ :intensity => :cubic_feet_of_natural_gas_per_square_foot,
13
+ :set => 11
14
+ },
15
+ :fuel_oil => {
16
+ :consumption => :million_gallons_of_fuel_oil,
17
+ :intensity => :gallons_of_fuel_oil_per_square_foot,
18
+ :set => 12
19
+ },
20
+ :district_heat => {
21
+ :consumption => :trillion_btu,
22
+ :intensity => :trillion_btu_per_million_square_feet,
23
+ :set => 13
24
+ }
25
+ }
26
+
5
27
  extend Earth::Model
6
28
 
7
29
  TABLE_STRUCTURE = <<-EOS
@@ -46,38 +68,10 @@ EOS
46
68
 
47
69
  self.primary_key = "name"
48
70
 
49
-
50
-
51
-
52
-
53
-
54
71
  scope :divisional, where('census_region_number IS NOT NULL AND census_division_number IS NOT NULL')
55
72
  scope :regional, where('census_region_number IS NOT NULL AND census_division_number IS NULL')
56
73
  scope :national, where(:census_region_number => nil, :census_division_number => nil)
57
74
 
58
- FUELS = {
59
- :electricity => {
60
- :consumption => :billion_kilowatt_hours,
61
- :intensity => :kilowatt_hours_per_square_foot,
62
- :set => 10
63
- },
64
- :natural_gas => {
65
- :consumption => :billion_cubic_feet_of_natural_gas,
66
- :intensity => :cubic_feet_of_natural_gas_per_square_foot,
67
- :set => 11
68
- },
69
- :fuel_oil => {
70
- :consumption => :million_gallons_of_fuel_oil,
71
- :intensity => :gallons_of_fuel_oil_per_square_foot,
72
- :set => 12
73
- },
74
- :district_heat => {
75
- :consumption => :trillion_btu,
76
- :intensity => :trillion_btu_per_million_square_feet,
77
- :set => 13
78
- }
79
- }
80
-
81
75
  # Find the first record whose naics_code matches code.
82
76
  # If no record found chop off the last character of code and try again, and so on.
83
77
  def self.find_by_naics_code(code)
@@ -114,4 +108,6 @@ EOS
114
108
  ratios
115
109
  end
116
110
  end
111
+
112
+ warn_unless_size 182
117
113
  end