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.
- data/Gemfile +1 -0
- data/TODO +2 -0
- data/bin/earth_tester.rb +62 -9
- data/earth.gemspec +7 -4
- data/lib/earth.rb +18 -17
- data/lib/earth/air.rb +2 -0
- data/lib/earth/air/aircraft.rb +76 -19
- data/lib/earth/air/aircraft/data_miner.rb +1 -63
- data/lib/earth/air/aircraft_class.rb +48 -12
- data/lib/earth/air/aircraft_class/data_miner.rb +3 -46
- data/lib/earth/air/aircraft_fuel_use_equation.rb +11 -13
- data/lib/earth/air/aircraft_instance.rb +9 -0
- data/lib/earth/air/aircraft_instance_seat_class.rb +12 -0
- data/lib/earth/air/airline.rb +6 -8
- data/lib/earth/air/airline/data_miner.rb +3 -3
- data/lib/earth/air/airport.rb +8 -10
- data/lib/earth/air/airport/data_miner.rb +1 -1
- data/lib/earth/air/bts_aircraft.rb +3 -5
- data/lib/earth/air/flight_distance_class.rb +4 -6
- data/lib/earth/air/flight_seat_class.rb +5 -7
- data/lib/earth/air/flight_segment.rb +58 -42
- data/lib/earth/air/flight_segment/data_miner.rb +11 -26
- data/lib/earth/automobile.rb +1 -0
- data/lib/earth/automobile/automobile_fuel.rb +78 -25
- data/lib/earth/automobile/automobile_fuel/data_miner.rb +5 -72
- data/lib/earth/automobile/automobile_make.rb +14 -6
- data/lib/earth/automobile/automobile_make/data_miner.rb +20 -35
- data/lib/earth/automobile/automobile_make_fleet_year.rb +39 -10
- data/lib/earth/automobile/automobile_make_fleet_year/data_miner.rb +0 -29
- data/lib/earth/automobile/automobile_make_model.rb +30 -9
- data/lib/earth/automobile/automobile_make_model/data_miner.rb +11 -26
- data/lib/earth/automobile/automobile_make_model_year.rb +41 -12
- data/lib/earth/automobile/automobile_make_model_year/data_miner.rb +14 -34
- data/lib/earth/automobile/automobile_make_model_year_variant.rb +56 -38
- data/lib/earth/automobile/automobile_make_model_year_variant/data_miner.rb +15 -61
- data/lib/earth/automobile/automobile_make_year.rb +15 -8
- data/lib/earth/automobile/automobile_make_year/data_miner.rb +17 -51
- data/lib/earth/automobile/automobile_size_class.rb +78 -14
- data/lib/earth/automobile/automobile_size_class/data_miner.rb +0 -66
- data/lib/earth/automobile/automobile_size_class_year.rb +38 -10
- data/lib/earth/automobile/automobile_size_class_year/data_miner.rb +0 -30
- data/lib/earth/automobile/automobile_type_fuel_age.rb +60 -11
- data/lib/earth/automobile/automobile_type_fuel_age/data_miner.rb +10 -65
- data/lib/earth/automobile/automobile_type_fuel_control.rb +41 -10
- data/lib/earth/automobile/automobile_type_fuel_control/data_miner.rb +0 -33
- data/lib/earth/automobile/automobile_type_fuel_year.rb +60 -15
- data/lib/earth/automobile/automobile_type_fuel_year/data_miner.rb +1 -52
- data/lib/earth/automobile/automobile_type_fuel_year_age.rb +64 -12
- data/lib/earth/automobile/automobile_type_fuel_year_age/data_miner.rb +1 -59
- data/lib/earth/automobile/automobile_type_fuel_year_control.rb +31 -10
- data/lib/earth/automobile/automobile_type_fuel_year_control/data_miner.rb +2 -32
- data/lib/earth/automobile/automobile_type_year.rb +51 -10
- data/lib/earth/automobile/automobile_type_year/data_miner.rb +1 -43
- data/lib/earth/automobile/data_miner.rb +1 -0
- data/lib/earth/bus/bus_class.rb +108 -28
- data/lib/earth/bus/bus_class/data_miner.rb +0 -88
- data/lib/earth/bus/bus_fuel.rb +83 -15
- data/lib/earth/bus/bus_fuel/data_miner.rb +0 -76
- data/lib/earth/bus/bus_fuel_control.rb +8 -10
- data/lib/earth/bus/bus_fuel_year_control.rb +7 -9
- data/lib/earth/bus/bus_fuel_year_control/data_miner.rb +1 -5
- data/lib/earth/computation/computation_carrier.rb +11 -5
- data/lib/earth/computation/computation_carrier/data_miner.rb +0 -7
- data/lib/earth/computation/computation_carrier_instance_class.rb +25 -8
- data/lib/earth/computation/computation_carrier_instance_class/data_miner.rb +0 -18
- data/lib/earth/computation/computation_carrier_region.rb +5 -7
- data/lib/earth/diet/diet_class.rb +14 -16
- data/lib/earth/diet/food_group.rb +7 -9
- data/lib/earth/fuel/fuel.rb +14 -16
- data/lib/earth/fuel/fuel/data_miner.rb +7 -3
- data/lib/earth/fuel/fuel_price.rb +4 -6
- data/lib/earth/fuel/fuel_type.rb +12 -14
- data/lib/earth/fuel/fuel_year.rb +57 -16
- data/lib/earth/fuel/fuel_year/data_miner.rb +0 -43
- data/lib/earth/fuel/greenhouse_gas.rb +46 -9
- data/lib/earth/fuel/greenhouse_gas/data_miner.rb +0 -38
- data/lib/earth/hospitality/lodging_class.rb +10 -12
- data/lib/earth/industry/industry.rb +3 -5
- data/lib/earth/industry/industry_product.rb +6 -8
- data/lib/earth/industry/industry_product_line.rb +5 -7
- data/lib/earth/industry/industry_sector.rb +5 -7
- data/lib/earth/industry/merchant.rb +4 -6
- data/lib/earth/industry/merchant_category.rb +3 -5
- data/lib/earth/industry/merchant_category_industry.rb +5 -7
- data/lib/earth/industry/product_line.rb +5 -7
- data/lib/earth/industry/product_line_industry_product.rb +5 -7
- data/lib/earth/industry/sector.rb +5 -7
- data/lib/earth/locality/census_division.rb +21 -23
- data/lib/earth/locality/census_region.rb +3 -5
- data/lib/earth/locality/climate_division.rb +5 -7
- data/lib/earth/locality/country.rb +13 -15
- data/lib/earth/locality/egrid_region.rb +14 -5
- data/lib/earth/locality/egrid_region/data_miner.rb +0 -10
- data/lib/earth/locality/egrid_subregion.rb +71 -18
- data/lib/earth/locality/egrid_subregion/data_miner.rb +0 -59
- data/lib/earth/locality/petroleum_administration_for_defense_district.rb +6 -8
- data/lib/earth/locality/state.rb +6 -8
- data/lib/earth/locality/urbanity.rb +2 -4
- data/lib/earth/locality/urbanity/data_miner.rb +7 -3
- data/lib/earth/locality/zip_code.rb +8 -10
- data/lib/earth/pet/breed.rb +5 -7
- data/lib/earth/pet/breed_gender.rb +6 -8
- data/lib/earth/pet/gender.rb +2 -4
- data/lib/earth/pet/species.rb +15 -17
- data/lib/earth/rail/rail_class.rb +64 -14
- data/lib/earth/rail/rail_class/data_miner.rb +0 -51
- data/lib/earth/residence/air_conditioner_use.rb +4 -6
- data/lib/earth/residence/air_conditioner_use/data_miner.rb +7 -3
- data/lib/earth/residence/clothes_machine_use.rb +4 -6
- data/lib/earth/residence/clothes_machine_use/data_miner.rb +11 -9
- data/lib/earth/residence/dishwasher_use.rb +4 -6
- data/lib/earth/residence/dishwasher_use/data_miner.rb +11 -9
- data/lib/earth/residence/residence_appliance.rb +4 -6
- data/lib/earth/residence/residence_class.rb +2 -4
- data/lib/earth/residence/residence_class/data_miner.rb +7 -3
- data/lib/earth/residence/residence_fuel_price.rb +12 -14
- data/lib/earth/residence/residence_fuel_price/data_miner.rb +7 -0
- data/lib/earth/residence/residence_fuel_type.rb +6 -8
- data/lib/earth/residence/residential_energy_consumption_survey_response.rb +91 -93
- data/lib/earth/residence/residential_energy_consumption_survey_response/data_miner.rb +9 -8
- data/lib/earth/shipping/carrier.rb +57 -10
- data/lib/earth/shipping/carrier/data_miner.rb +0 -48
- data/lib/earth/shipping/carrier_mode.rb +41 -10
- data/lib/earth/shipping/carrier_mode/data_miner.rb +0 -33
- data/lib/earth/shipping/shipment_mode.rb +30 -7
- data/lib/earth/shipping/shipment_mode/data_miner.rb +0 -23
- data/lib/earth/utils.rb +45 -0
- data/lib/earth/version.rb +1 -1
- data/spec/earth/air/aircraft_spec.rb +1 -1
- data/vendor/clean_find_in_batches/init.rb +35 -0
- 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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|