earth 0.5.4 → 0.6.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.
Files changed (131) hide show
  1. data/Gemfile +1 -0
  2. data/TODO +2 -0
  3. data/bin/earth_tester.rb +62 -9
  4. data/earth.gemspec +7 -4
  5. data/lib/earth.rb +18 -17
  6. data/lib/earth/air.rb +2 -0
  7. data/lib/earth/air/aircraft.rb +76 -19
  8. data/lib/earth/air/aircraft/data_miner.rb +1 -63
  9. data/lib/earth/air/aircraft_class.rb +48 -12
  10. data/lib/earth/air/aircraft_class/data_miner.rb +3 -46
  11. data/lib/earth/air/aircraft_fuel_use_equation.rb +11 -13
  12. data/lib/earth/air/aircraft_instance.rb +9 -0
  13. data/lib/earth/air/aircraft_instance_seat_class.rb +12 -0
  14. data/lib/earth/air/airline.rb +6 -8
  15. data/lib/earth/air/airline/data_miner.rb +3 -3
  16. data/lib/earth/air/airport.rb +8 -10
  17. data/lib/earth/air/airport/data_miner.rb +1 -1
  18. data/lib/earth/air/bts_aircraft.rb +3 -5
  19. data/lib/earth/air/flight_distance_class.rb +4 -6
  20. data/lib/earth/air/flight_seat_class.rb +5 -7
  21. data/lib/earth/air/flight_segment.rb +58 -42
  22. data/lib/earth/air/flight_segment/data_miner.rb +11 -26
  23. data/lib/earth/automobile.rb +1 -0
  24. data/lib/earth/automobile/automobile_fuel.rb +78 -25
  25. data/lib/earth/automobile/automobile_fuel/data_miner.rb +5 -72
  26. data/lib/earth/automobile/automobile_make.rb +14 -6
  27. data/lib/earth/automobile/automobile_make/data_miner.rb +20 -35
  28. data/lib/earth/automobile/automobile_make_fleet_year.rb +39 -10
  29. data/lib/earth/automobile/automobile_make_fleet_year/data_miner.rb +0 -29
  30. data/lib/earth/automobile/automobile_make_model.rb +30 -9
  31. data/lib/earth/automobile/automobile_make_model/data_miner.rb +11 -26
  32. data/lib/earth/automobile/automobile_make_model_year.rb +41 -12
  33. data/lib/earth/automobile/automobile_make_model_year/data_miner.rb +14 -34
  34. data/lib/earth/automobile/automobile_make_model_year_variant.rb +56 -38
  35. data/lib/earth/automobile/automobile_make_model_year_variant/data_miner.rb +15 -61
  36. data/lib/earth/automobile/automobile_make_year.rb +15 -8
  37. data/lib/earth/automobile/automobile_make_year/data_miner.rb +17 -51
  38. data/lib/earth/automobile/automobile_size_class.rb +78 -14
  39. data/lib/earth/automobile/automobile_size_class/data_miner.rb +0 -66
  40. data/lib/earth/automobile/automobile_size_class_year.rb +38 -10
  41. data/lib/earth/automobile/automobile_size_class_year/data_miner.rb +0 -30
  42. data/lib/earth/automobile/automobile_type_fuel_age.rb +60 -11
  43. data/lib/earth/automobile/automobile_type_fuel_age/data_miner.rb +10 -65
  44. data/lib/earth/automobile/automobile_type_fuel_control.rb +41 -10
  45. data/lib/earth/automobile/automobile_type_fuel_control/data_miner.rb +0 -33
  46. data/lib/earth/automobile/automobile_type_fuel_year.rb +60 -15
  47. data/lib/earth/automobile/automobile_type_fuel_year/data_miner.rb +1 -52
  48. data/lib/earth/automobile/automobile_type_fuel_year_age.rb +64 -12
  49. data/lib/earth/automobile/automobile_type_fuel_year_age/data_miner.rb +1 -59
  50. data/lib/earth/automobile/automobile_type_fuel_year_control.rb +31 -10
  51. data/lib/earth/automobile/automobile_type_fuel_year_control/data_miner.rb +2 -32
  52. data/lib/earth/automobile/automobile_type_year.rb +51 -10
  53. data/lib/earth/automobile/automobile_type_year/data_miner.rb +1 -43
  54. data/lib/earth/automobile/data_miner.rb +1 -0
  55. data/lib/earth/bus/bus_class.rb +108 -28
  56. data/lib/earth/bus/bus_class/data_miner.rb +0 -88
  57. data/lib/earth/bus/bus_fuel.rb +83 -15
  58. data/lib/earth/bus/bus_fuel/data_miner.rb +0 -76
  59. data/lib/earth/bus/bus_fuel_control.rb +8 -10
  60. data/lib/earth/bus/bus_fuel_year_control.rb +7 -9
  61. data/lib/earth/bus/bus_fuel_year_control/data_miner.rb +1 -5
  62. data/lib/earth/computation/computation_carrier.rb +11 -5
  63. data/lib/earth/computation/computation_carrier/data_miner.rb +0 -7
  64. data/lib/earth/computation/computation_carrier_instance_class.rb +25 -8
  65. data/lib/earth/computation/computation_carrier_instance_class/data_miner.rb +0 -18
  66. data/lib/earth/computation/computation_carrier_region.rb +5 -7
  67. data/lib/earth/diet/diet_class.rb +14 -16
  68. data/lib/earth/diet/food_group.rb +7 -9
  69. data/lib/earth/fuel/fuel.rb +14 -16
  70. data/lib/earth/fuel/fuel/data_miner.rb +7 -3
  71. data/lib/earth/fuel/fuel_price.rb +4 -6
  72. data/lib/earth/fuel/fuel_type.rb +12 -14
  73. data/lib/earth/fuel/fuel_year.rb +57 -16
  74. data/lib/earth/fuel/fuel_year/data_miner.rb +0 -43
  75. data/lib/earth/fuel/greenhouse_gas.rb +46 -9
  76. data/lib/earth/fuel/greenhouse_gas/data_miner.rb +0 -38
  77. data/lib/earth/hospitality/lodging_class.rb +10 -12
  78. data/lib/earth/industry/industry.rb +3 -5
  79. data/lib/earth/industry/industry_product.rb +6 -8
  80. data/lib/earth/industry/industry_product_line.rb +5 -7
  81. data/lib/earth/industry/industry_sector.rb +5 -7
  82. data/lib/earth/industry/merchant.rb +4 -6
  83. data/lib/earth/industry/merchant_category.rb +3 -5
  84. data/lib/earth/industry/merchant_category_industry.rb +5 -7
  85. data/lib/earth/industry/product_line.rb +5 -7
  86. data/lib/earth/industry/product_line_industry_product.rb +5 -7
  87. data/lib/earth/industry/sector.rb +5 -7
  88. data/lib/earth/locality/census_division.rb +21 -23
  89. data/lib/earth/locality/census_region.rb +3 -5
  90. data/lib/earth/locality/climate_division.rb +5 -7
  91. data/lib/earth/locality/country.rb +13 -15
  92. data/lib/earth/locality/egrid_region.rb +14 -5
  93. data/lib/earth/locality/egrid_region/data_miner.rb +0 -10
  94. data/lib/earth/locality/egrid_subregion.rb +71 -18
  95. data/lib/earth/locality/egrid_subregion/data_miner.rb +0 -59
  96. data/lib/earth/locality/petroleum_administration_for_defense_district.rb +6 -8
  97. data/lib/earth/locality/state.rb +6 -8
  98. data/lib/earth/locality/urbanity.rb +2 -4
  99. data/lib/earth/locality/urbanity/data_miner.rb +7 -3
  100. data/lib/earth/locality/zip_code.rb +8 -10
  101. data/lib/earth/pet/breed.rb +5 -7
  102. data/lib/earth/pet/breed_gender.rb +6 -8
  103. data/lib/earth/pet/gender.rb +2 -4
  104. data/lib/earth/pet/species.rb +15 -17
  105. data/lib/earth/rail/rail_class.rb +64 -14
  106. data/lib/earth/rail/rail_class/data_miner.rb +0 -51
  107. data/lib/earth/residence/air_conditioner_use.rb +4 -6
  108. data/lib/earth/residence/air_conditioner_use/data_miner.rb +7 -3
  109. data/lib/earth/residence/clothes_machine_use.rb +4 -6
  110. data/lib/earth/residence/clothes_machine_use/data_miner.rb +11 -9
  111. data/lib/earth/residence/dishwasher_use.rb +4 -6
  112. data/lib/earth/residence/dishwasher_use/data_miner.rb +11 -9
  113. data/lib/earth/residence/residence_appliance.rb +4 -6
  114. data/lib/earth/residence/residence_class.rb +2 -4
  115. data/lib/earth/residence/residence_class/data_miner.rb +7 -3
  116. data/lib/earth/residence/residence_fuel_price.rb +12 -14
  117. data/lib/earth/residence/residence_fuel_price/data_miner.rb +7 -0
  118. data/lib/earth/residence/residence_fuel_type.rb +6 -8
  119. data/lib/earth/residence/residential_energy_consumption_survey_response.rb +91 -93
  120. data/lib/earth/residence/residential_energy_consumption_survey_response/data_miner.rb +9 -8
  121. data/lib/earth/shipping/carrier.rb +57 -10
  122. data/lib/earth/shipping/carrier/data_miner.rb +0 -48
  123. data/lib/earth/shipping/carrier_mode.rb +41 -10
  124. data/lib/earth/shipping/carrier_mode/data_miner.rb +0 -33
  125. data/lib/earth/shipping/shipment_mode.rb +30 -7
  126. data/lib/earth/shipping/shipment_mode/data_miner.rb +0 -23
  127. data/lib/earth/utils.rb +45 -0
  128. data/lib/earth/version.rb +1 -1
  129. data/spec/earth/air/aircraft_spec.rb +1 -1
  130. data/vendor/clean_find_in_batches/init.rb +35 -0
  131. metadata +74 -47
@@ -101,6 +101,13 @@ ResidenceFuelPrice.class_eval do
101
101
  end
102
102
  end
103
103
 
104
+ # TODO sabshere fix data_miner strangeness
105
+ # Ran #<DataMiner::Process(ResidenceFuelPrice) auto_upgrade!> in 0
106
+ # Ran #<DataMiner::Process(ResidenceFuelPrice) Define some unit conversions> in 0
107
+ # Ran #<DataMiner::Import(ResidenceFuelPrice) residential electricity prices from the EIA> in 93
108
+ # Skipping {"locatable_id"=>"US", "locatable_type"=>"Country", "price"=>"1.71", "year"=>1990, "month"=>6, "row_hash"=>"142ed08d9adac8e322dd123317b06de8"} because there's no primary key
109
+ # Skipping {"locatable_id"=>"Alabama", "locatable_type"=>"State", "price"=>"2.75", "year"=>1990, "month"=>6, "row_hash"=>"d56480d06e32e7e99ba5f85444fe4827"} because there's no primary key
110
+
104
111
  data_miner do
105
112
  process "Define some unit conversions" do
106
113
  Conversions.register :dollars, :cents, 100
@@ -3,13 +3,11 @@ class ResidenceFuelType < ActiveRecord::Base
3
3
 
4
4
  has_many :prices, :class_name => 'ResidenceFuelPrice', :foreign_key => 'residence_fuel_type_name'
5
5
 
6
- force_schema do
7
- string 'name'
8
- float 'emission_factor'
9
- string 'emission_factor_units'
10
- # float 'energy_content'
11
- # string 'energy_content_units'
12
- end
6
+ col :name
7
+ col :emission_factor, :type => :float
8
+ col :emission_factor_units
9
+ # col :energy_content, :type => :float
10
+ # col :energy_content_units
13
11
 
14
12
  def price_per_unit(relaxations = [])
15
13
  conditions = { :residence_fuel_type_name => self }
@@ -33,4 +31,4 @@ class ResidenceFuelType < ActiveRecord::Base
33
31
  find_by_name fuel.to_s.humanize.downcase
34
32
  end
35
33
  end
36
- end
34
+ end
@@ -31,96 +31,94 @@ class ResidentialEnergyConsumptionSurveyResponse < ActiveRecord::Base
31
31
  ]
32
32
 
33
33
  # sabshere 9/20/10 sorted with sort -d -t "'" -k 2 ~/Desktop/parts.txt
34
- force_schema do
35
- integer 'id'
36
- string 'air_conditioner_use_id'
37
- float 'annual_energy_from_electricity_for_air_conditioners'
38
- string 'annual_energy_from_electricity_for_air_conditioners_units'
39
- float 'annual_energy_from_electricity_for_clothes_driers'
40
- string 'annual_energy_from_electricity_for_clothes_driers_units'
41
- float 'annual_energy_from_electricity_for_dishwashers'
42
- string 'annual_energy_from_electricity_for_dishwashers_units'
43
- float 'annual_energy_from_electricity_for_freezers'
44
- string 'annual_energy_from_electricity_for_freezers_units'
45
- float 'annual_energy_from_electricity_for_heating_space'
46
- string 'annual_energy_from_electricity_for_heating_space_units'
47
- float 'annual_energy_from_electricity_for_heating_water'
48
- string 'annual_energy_from_electricity_for_heating_water_units'
49
- float 'annual_energy_from_electricity_for_other_appliances'
50
- string 'annual_energy_from_electricity_for_other_appliances_units'
51
- float 'annual_energy_from_electricity_for_refrigerators'
52
- string 'annual_energy_from_electricity_for_refrigerators_units'
53
- float 'annual_energy_from_fuel_oil_for_appliances'
54
- string 'annual_energy_from_fuel_oil_for_appliances_units'
55
- float 'annual_energy_from_fuel_oil_for_heating_space'
56
- string 'annual_energy_from_fuel_oil_for_heating_space_units'
57
- float 'annual_energy_from_fuel_oil_for_heating_water'
58
- string 'annual_energy_from_fuel_oil_for_heating_water_units'
59
- float 'annual_energy_from_kerosene'
60
- string 'annual_energy_from_kerosene_units'
61
- float 'annual_energy_from_natural_gas_for_appliances'
62
- string 'annual_energy_from_natural_gas_for_appliances_units'
63
- float 'annual_energy_from_natural_gas_for_heating_space'
64
- string 'annual_energy_from_natural_gas_for_heating_space_units'
65
- float 'annual_energy_from_natural_gas_for_heating_water'
66
- string 'annual_energy_from_natural_gas_for_heating_water_units'
67
- float 'annual_energy_from_propane_for_appliances'
68
- string 'annual_energy_from_propane_for_appliances_units'
69
- float 'annual_energy_from_propane_for_heating_space'
70
- string 'annual_energy_from_propane_for_heating_space_units'
71
- float 'annual_energy_from_propane_for_heating_water'
72
- string 'annual_energy_from_propane_for_heating_water_units'
73
- float 'annual_energy_from_wood'
74
- string 'annual_energy_from_wood_units'
75
- boolean 'attached_1car_garage'
76
- boolean 'attached_2car_garage'
77
- boolean 'attached_3car_garage'
78
- float 'bathrooms'
79
- integer 'bedrooms'
80
- string 'census_division_name'
81
- integer 'census_division_number'
82
- string 'census_region_name'
83
- integer 'census_region_number'
84
- string 'central_ac_use'
85
- string 'clothes_dryer_use'
86
- string 'clothes_machine_use_id'
87
- string 'clothes_washer_use'
88
- string 'construction_period'
89
- date 'construction_year'
90
- integer 'cooling_degree_days'
91
- string 'cooling_degree_days_units'
92
- boolean 'detached_1car_garage'
93
- boolean 'detached_2car_garage'
94
- boolean 'detached_3car_garage'
95
- string 'dishwasher_use_id'
96
- integer 'efficient_lights_on_1_to_4_hours'
97
- integer 'efficient_lights_on_4_to_12_hours'
98
- integer 'efficient_lights_on_over_12_hours'
99
- float 'floorspace'
100
- string 'floorspace_units'
101
- integer 'freezer_count'
102
- integer 'full_bathrooms'
103
- integer 'half_bathrooms'
104
- boolean 'heated_garage'
105
- integer 'heating_degree_days'
106
- string 'heating_degree_days_units'
107
- float 'lighting_efficiency'
108
- float 'lighting_use'
109
- string 'lighting_use_units'
110
- integer 'lights_on_1_to_4_hours'
111
- integer 'lights_on_4_to_12_hours'
112
- integer 'lights_on_over_12_hours'
113
- integer 'outdoor_all_night_gas_lights'
114
- integer 'outdoor_all_night_lights'
115
- boolean 'ownership'
116
- integer 'refrigerator_count'
117
- string 'residence_class_id'
118
- integer 'residents'
119
- float 'rooms'
120
- boolean 'thermostat_programmability'
121
- integer 'total_rooms'
122
- string 'urbanity_id'
123
- float 'weighting'
124
- string 'window_ac_use'
125
- end
126
- end
34
+ col :id, :type => :integer
35
+ col :air_conditioner_use_id
36
+ col :annual_energy_from_electricity_for_air_conditioners, :type => :float
37
+ col :annual_energy_from_electricity_for_air_conditioners_units
38
+ col :annual_energy_from_electricity_for_clothes_driers, :type => :float
39
+ col :annual_energy_from_electricity_for_clothes_driers_units
40
+ col :annual_energy_from_electricity_for_dishwashers, :type => :float
41
+ col :annual_energy_from_electricity_for_dishwashers_units
42
+ col :annual_energy_from_electricity_for_freezers, :type => :float
43
+ col :annual_energy_from_electricity_for_freezers_units
44
+ col :annual_energy_from_electricity_for_heating_space, :type => :float
45
+ col :annual_energy_from_electricity_for_heating_space_units
46
+ col :annual_energy_from_electricity_for_heating_water, :type => :float
47
+ col :annual_energy_from_electricity_for_heating_water_units
48
+ col :annual_energy_from_electricity_for_other_appliances, :type => :float
49
+ col :annual_energy_from_electricity_for_other_appliances_units
50
+ col :annual_energy_from_electricity_for_refrigerators, :type => :float
51
+ col :annual_energy_from_electricity_for_refrigerators_units
52
+ col :annual_energy_from_fuel_oil_for_appliances, :type => :float
53
+ col :annual_energy_from_fuel_oil_for_appliances_units
54
+ col :annual_energy_from_fuel_oil_for_heating_space, :type => :float
55
+ col :annual_energy_from_fuel_oil_for_heating_space_units
56
+ col :annual_energy_from_fuel_oil_for_heating_water, :type => :float
57
+ col :annual_energy_from_fuel_oil_for_heating_water_units
58
+ col :annual_energy_from_kerosene, :type => :float
59
+ col :annual_energy_from_kerosene_units
60
+ col :annual_energy_from_natural_gas_for_appliances, :type => :float
61
+ col :annual_energy_from_natural_gas_for_appliances_units
62
+ col :annual_energy_from_natural_gas_for_heating_space, :type => :float
63
+ col :annual_energy_from_natural_gas_for_heating_space_units
64
+ col :annual_energy_from_natural_gas_for_heating_water, :type => :float
65
+ col :annual_energy_from_natural_gas_for_heating_water_units
66
+ col :annual_energy_from_propane_for_appliances, :type => :float
67
+ col :annual_energy_from_propane_for_appliances_units
68
+ col :annual_energy_from_propane_for_heating_space, :type => :float
69
+ col :annual_energy_from_propane_for_heating_space_units
70
+ col :annual_energy_from_propane_for_heating_water, :type => :float
71
+ col :annual_energy_from_propane_for_heating_water_units
72
+ col :annual_energy_from_wood, :type => :float
73
+ col :annual_energy_from_wood_units
74
+ col :attached_1car_garage, :type => :integer
75
+ col :attached_2car_garage, :type => :integer
76
+ col :attached_3car_garage, :type => :integer
77
+ col :bathrooms, :type => :float
78
+ col :bedrooms, :type => :integer
79
+ col :census_division_name
80
+ col :census_division_number, :type => :integer
81
+ col :census_region_name
82
+ col :census_region_number, :type => :integer
83
+ col :central_ac_use
84
+ col :clothes_dryer_use
85
+ col :clothes_machine_use_id
86
+ col :clothes_washer_use
87
+ col :construction_period
88
+ col :construction_year, :type => :date
89
+ col :cooling_degree_days, :type => :integer
90
+ col :cooling_degree_days_units
91
+ col :detached_1car_garage, :type => :integer
92
+ col :detached_2car_garage, :type => :integer
93
+ col :detached_3car_garage, :type => :integer
94
+ col :dishwasher_use_id
95
+ col :efficient_lights_on_1_to_4_hours, :type => :integer
96
+ col :efficient_lights_on_4_to_12_hours, :type => :integer
97
+ col :efficient_lights_on_over_12_hours, :type => :integer
98
+ col :floorspace, :type => :float
99
+ col :floorspace_units
100
+ col :freezer_count, :type => :integer
101
+ col :full_bathrooms, :type => :integer
102
+ col :half_bathrooms, :type => :integer
103
+ col :heated_garage, :type => :integer
104
+ col :heating_degree_days, :type => :integer
105
+ col :heating_degree_days_units
106
+ col :lighting_efficiency, :type => :float
107
+ col :lighting_use, :type => :float
108
+ col :lighting_use_units
109
+ col :lights_on_1_to_4_hours, :type => :integer
110
+ col :lights_on_4_to_12_hours, :type => :integer
111
+ col :lights_on_over_12_hours, :type => :integer
112
+ col :outdoor_all_night_gas_lights, :type => :integer
113
+ col :outdoor_all_night_lights, :type => :integer
114
+ col :ownership, :type => :boolean
115
+ col :refrigerator_count, :type => :integer
116
+ col :residence_class_id
117
+ col :residents, :type => :integer
118
+ col :rooms, :type => :float
119
+ col :thermostat_programmability, :type => :boolean
120
+ col :total_rooms, :type => :integer
121
+ col :urbanity_id
122
+ col :weighting, :type => :float
123
+ col :window_ac_use
124
+ end
@@ -66,16 +66,17 @@ ResidentialEnergyConsumptionSurveyResponse.class_eval do
66
66
  store 'efficient_lights_on_over_12_hours', :field_name => 'LGT12EE'
67
67
  store 'outdoor_all_night_lights', :field_name => 'NOUTLGTNT'
68
68
  store 'outdoor_all_night_gas_lights', :field_name => 'NGASLIGHT'
69
+ # integers where we treat anything other than true (for example legitimate skip or "occupied without paying rent") as 0
70
+ store 'heated_garage', :synthesize => lambda { |row| row['GARGHEAT'] == '1' ? 1 : 0 }
71
+ store 'attached_1car_garage', :synthesize => lambda { |row| row['GARAGE1C'] == '1' ? 1 : 0 }
72
+ store 'detached_1car_garage', :synthesize => lambda { |row| row['DGARG1C'] == '1' ? 1 : 0 }
73
+ store 'attached_2car_garage', :synthesize => lambda { |row| row['GARAGE2C'] == '1' ? 1 : 0 }
74
+ store 'detached_2car_garage', :synthesize => lambda { |row| row['DGARG2C'] == '1' ? 1 : 0 }
75
+ store 'attached_3car_garage', :synthesize => lambda { |row| row['GARAGE3C'] == '1' ? 1 : 0 }
76
+ store 'detached_3car_garage', :synthesize => lambda { |row| row['DGARG3C'] == '1' ? 1 : 0 }
69
77
  # booleans where we treat anything other than true (for example legitimate skip or "occupied without paying rent") as false
70
78
  store 'ownership', :synthesize => lambda { |row| row['KOWNRENT'] == '1' }
71
79
  store 'thermostat_programmability', :synthesize => lambda { |row| row['PROTHERM'] == '1' }
72
- store 'heated_garage', :synthesize => lambda { |row| row['GARGHEAT'] == '1' }
73
- store 'attached_1car_garage', :synthesize => lambda { |row| row['GARAGE1C'] == '1' }
74
- store 'detached_1car_garage', :synthesize => lambda { |row| row['DGARG1C'] == '1' }
75
- store 'attached_2car_garage', :synthesize => lambda { |row| row['GARAGE2C'] == '1' }
76
- store 'detached_2car_garage', :synthesize => lambda { |row| row['DGARG2C'] == '1' }
77
- store 'attached_3car_garage', :synthesize => lambda { |row| row['GARAGE3C'] == '1' }
78
- store 'detached_3car_garage', :synthesize => lambda { |row| row['DGARG3C'] == '1' }
79
80
  end
80
81
 
81
82
  # Rather than nullify the continuous variables that EIA identifies as LEGITIMATE SKIPS, we convert them to zero
@@ -158,7 +159,7 @@ ResidentialEnergyConsumptionSurveyResponse.class_eval do
158
159
  end
159
160
 
160
161
  process 'Add a new field "lighting_efficiency" that estimates what percentage of light bulbs in a house are energy-efficient' do
161
- update_all 'lighting_efficiency = (2*efficient_lights_on_1_to_4_hours + 8*efficient_lights_on_4_to_12_hours + 16*efficient_lights_on_over_12_hours) / lighting_use'
162
+ update_all 'lighting_efficiency = (2*efficient_lights_on_1_to_4_hours + 8*efficient_lights_on_4_to_12_hours + 16*efficient_lights_on_over_12_hours) / lighting_use', 'lighting_use > 0'
162
163
  end
163
164
 
164
165
  process "synthesize air conditioner use from central AC and window AC use" do
@@ -8,13 +8,60 @@ class Carrier < ActiveRecord::Base
8
8
  :transport_emission_factor => 0.0005266,
9
9
  :corporate_emission_factor => 0.221
10
10
 
11
- force_schema do
12
- string 'name'
13
- float 'package_volume'
14
- float 'route_inefficiency_factor'
15
- float 'transport_emission_factor'
16
- string 'transport_emission_factor_units'
17
- float 'corporate_emission_factor'
18
- string 'corporate_emission_factor_units'
19
- end
20
- end
11
+ col :name
12
+ col :package_volume, :type => :float
13
+ col :route_inefficiency_factor, :type => :float
14
+ col :transport_emission_factor, :type => :float
15
+ col :transport_emission_factor_units
16
+ col :corporate_emission_factor, :type => :float
17
+ col :corporate_emission_factor_units
18
+
19
+ # verify "Package volume should be greater than zero" do
20
+ # Carrier.all.each do |carrier|
21
+ # unless carrier.package_volume > 0
22
+ # raise "Invalid package volume for Carrier #{carrier.name}: #{carrier.package_volume} (should be > 0)"
23
+ # end
24
+ # end
25
+ # end
26
+ #
27
+ # verify "Route inefficiency factor should be one or more" do
28
+ # Carrier.all.each do |carrier|
29
+ # unless carrier.route_inefficiency_factor >= 1.0
30
+ # raise "Invalid route inefficiency factor for Carrier #{carrier.name}: #{carrier.route_inefficiency_factor} (should be >= 1.0)"
31
+ # end
32
+ # end
33
+ # end
34
+ #
35
+ # verify "Transport emission factor should be greater than zero" do
36
+ # Carrier.all.each do |carrier|
37
+ # unless carrier.transport_emission_factor > 0
38
+ # raise "Invalid transport emission factor for Carrier #{carrier.name}: #{carrier.transport_emission_factor} (should be > 0)"
39
+ # end
40
+ # end
41
+ # end
42
+ #
43
+ # verify "Transport emission factor units should never be missing" do
44
+ # Carrier.all.each do |carrier|
45
+ # unless carrier.transport_emission_factor_units.present?
46
+ # raise "Missing transport emission factor units for Carrier #{carrier.name}"
47
+ # end
48
+ # end
49
+ # end
50
+ #
51
+ # verify "Corporate emission factor should be greater than zero" do
52
+ # Carrier.all.each do |carrier|
53
+ # unless carrier.corporate_emission_factor > 0
54
+ # raise "Invalid corporate emission factor for Carrier #{carrier.name}: #{carrier.corporate_emission_factor} (should be > 0)"
55
+ # end
56
+ # end
57
+ # end
58
+ #
59
+ # verify "Corporate emission factor units should never be missing" do
60
+ # Carrier.all.each do |carrier|
61
+ # unless carrier.corporate_emission_factor_units.present?
62
+ # raise "Missing corporate emission factor units for Carrier #{carrier.name}"
63
+ # end
64
+ # end
65
+ # end
66
+
67
+ end
@@ -22,53 +22,5 @@ Carrier.class_eval do
22
22
  # update_all "transport_emission_factor = (#{CarrierMode.weighted_average_relation(:transport_emission_factor, :weighted_by => :package_volume).where(conditional_relation).to_sql})"
23
23
  # what about transport_emission_factor_units?
24
24
  # end
25
-
26
- verify "Package volume should be greater than zero" do
27
- Carrier.all.each do |carrier|
28
- unless carrier.package_volume > 0
29
- raise "Invalid package volume for Carrier #{carrier.name}: #{carrier.package_volume} (should be > 0)"
30
- end
31
- end
32
- end
33
-
34
- verify "Route inefficiency factor should be one or more" do
35
- Carrier.all.each do |carrier|
36
- unless carrier.route_inefficiency_factor >= 1.0
37
- raise "Invalid route inefficiency factor for Carrier #{carrier.name}: #{carrier.route_inefficiency_factor} (should be >= 1.0)"
38
- end
39
- end
40
- end
41
-
42
- verify "Transport emission factor should be greater than zero" do
43
- Carrier.all.each do |carrier|
44
- unless carrier.transport_emission_factor > 0
45
- raise "Invalid transport emission factor for Carrier #{carrier.name}: #{carrier.transport_emission_factor} (should be > 0)"
46
- end
47
- end
48
- end
49
-
50
- verify "Transport emission factor units should never be missing" do
51
- Carrier.all.each do |carrier|
52
- unless carrier.transport_emission_factor_units.present?
53
- raise "Missing transport emission factor units for Carrier #{carrier.name}"
54
- end
55
- end
56
- end
57
-
58
- verify "Corporate emission factor should be greater than zero" do
59
- Carrier.all.each do |carrier|
60
- unless carrier.corporate_emission_factor > 0
61
- raise "Invalid corporate emission factor for Carrier #{carrier.name}: #{carrier.corporate_emission_factor} (should be > 0)"
62
- end
63
- end
64
- end
65
-
66
- verify "Corporate emission factor units should never be missing" do
67
- Carrier.all.each do |carrier|
68
- unless carrier.corporate_emission_factor_units.present?
69
- raise "Missing corporate emission factor units for Carrier #{carrier.name}"
70
- end
71
- end
72
- end
73
25
  end
74
26
  end
@@ -4,13 +4,44 @@ class CarrierMode < ActiveRecord::Base
4
4
  belongs_to :carrier, :foreign_key => 'carrier_name', :primary_key => 'name'
5
5
  belongs_to :mode, :foreign_key => 'mode_name', :primary_key => 'name', :class_name => 'ShipmentMode'
6
6
 
7
- force_schema do
8
- string 'name'
9
- string 'carrier_name'
10
- string 'mode_name'
11
- float 'package_volume'
12
- float 'route_inefficiency_factor'
13
- float 'transport_emission_factor'
14
- string 'transport_emission_factor_units'
15
- end
16
- end
7
+ col :name
8
+ col :carrier_name
9
+ col :mode_name
10
+ col :package_volume, :type => :float
11
+ col :route_inefficiency_factor, :type => :float
12
+ col :transport_emission_factor, :type => :float
13
+ col :transport_emission_factor_units
14
+
15
+ # Don't need to check that carrier_name appears in carriers b/c carriers is derived from carrier_modes.carrier_name
16
+ # Don't need to check that mode_name appears in shipment_modes b/c shipment_modes is derived from carrier_modes.mode_name
17
+ # FIXME TODO test for valid transport_emission_factor_units
18
+ # %w{carrier_name mode_name transport_emission_factor_units}.each do |attribute|
19
+ # verify "#{attribute.humanize} should never be missing" do
20
+ # CarrierMode.all.each do |carrier_mode|
21
+ # value = carrier_mode.send(:"#{attribute}")
22
+ # unless value.present?
23
+ # raise "Missing #{attribute.humanize.downcase} for CarrierMode #{carrier_mode.name}"
24
+ # end
25
+ # end
26
+ # end
27
+ # end
28
+ #
29
+ # %w{package_volume transport_emission_factor}.each do |attribute|
30
+ # verify "#{attribute.humanize} should be greater than zero" do
31
+ # CarrierMode.all.each do |carrier_mode|
32
+ # value = carrier_mode.send(:"#{attribute}")
33
+ # unless value > 0
34
+ # raise "Invalid #{attribute.humanize.downcase} for CarrierMode #{carrier_mode.name}: #{value} (should be > 0)"
35
+ # end
36
+ # end
37
+ # end
38
+ # end
39
+ #
40
+ # verify "Route inefficiency factor should be one or more" do
41
+ # CarrierMode.all.each do |carrier_mode|
42
+ # unless carrier_mode.route_inefficiency_factor >= 1.0
43
+ # raise "Invalid route inefficiency factor for CarrierMode #{carrier_mode.name}: #{carrier_mode.route_inefficiency_factor} (should be >= 1.0)"
44
+ # end
45
+ # end
46
+ # end
47
+ end
@@ -9,38 +9,5 @@ CarrierMode.class_eval do
9
9
  store 'route_inefficiency_factor'
10
10
  store 'transport_emission_factor', :units_field_name => 'transport_emission_factor_units'
11
11
  end
12
-
13
- # Don't need to check that carrier_name appears in carriers b/c carriers is derived from carrier_modes.carrier_name
14
- # Don't need to check that mode_name appears in shipment_modes b/c shipment_modes is derived from carrier_modes.mode_name
15
- # FIXME TODO test for valid transport_emission_factor_units
16
- %w{carrier_name mode_name transport_emission_factor_units}.each do |attribute|
17
- verify "#{attribute.humanize} should never be missing" do
18
- CarrierMode.all.each do |carrier_mode|
19
- value = carrier_mode.send(:"#{attribute}")
20
- unless value.present?
21
- raise "Missing #{attribute.humanize.downcase} for CarrierMode #{carrier_mode.name}"
22
- end
23
- end
24
- end
25
- end
26
-
27
- %w{package_volume transport_emission_factor}.each do |attribute|
28
- verify "#{attribute.humanize} should be greater than zero" do
29
- CarrierMode.all.each do |carrier_mode|
30
- value = carrier_mode.send(:"#{attribute}")
31
- unless value > 0
32
- raise "Invalid #{attribute.humanize.downcase} for CarrierMode #{carrier_mode.name}: #{value} (should be > 0)"
33
- end
34
- end
35
- end
36
- end
37
-
38
- verify "Route inefficiency factor should be one or more" do
39
- CarrierMode.all.each do |carrier_mode|
40
- unless carrier_mode.route_inefficiency_factor >= 1.0
41
- raise "Invalid route inefficiency factor for CarrierMode #{carrier_mode.name}: #{carrier_mode.route_inefficiency_factor} (should be >= 1.0)"
42
- end
43
- end
44
- end
45
12
  end
46
13
  end