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
@@ -65,11 +65,7 @@ AutomobileTypeFuelYear.class_eval do
65
65
  end
66
66
 
67
67
  process "Derive type year name for association with AutomobileTypeYear" do
68
- if ActiveRecord::Base.connection.adapter_name.downcase == 'sqlite'
69
- update_all "type_year_name = type_name || ' ' || year"
70
- else
71
- update_all "type_year_name = CONCAT(type_name, ' ', year)"
72
- end
68
+ update_all "type_year_name = type_name || ' ' || year"
73
69
  end
74
70
 
75
71
  process "Ensure AutomobileTypeFuelYearControl and AutomobileTypeFuelControl are populated" do
@@ -93,52 +89,5 @@ AutomobileTypeFuelYear.class_eval do
93
89
  record.save
94
90
  end
95
91
  end
96
-
97
- %w{ type_name fuel_common_name type_year_name }.each do |attribute|
98
- verify "#{attribute.humanize} should never be missing" do
99
- AutomobileTypeFuelYear.all.each do |record|
100
- value = record.send(:"#{attribute}")
101
- unless value.present?
102
- raise "Missing #{attribute.humanize.downcase} for AutomobileTypeFuelYear '#{record.name}'"
103
- end
104
- end
105
- end
106
- end
107
-
108
- verify "Year should be from 1990 to 2008" do
109
- AutomobileTypeFuelYear.all.each do |record|
110
- year = record.send(:year)
111
- unless year > 1989 and year < 2009
112
- raise "Invalid year for AutomobileTypeFuelYear '#{record.name}': #{year} (should be from 1990 to 2008)"
113
- end
114
- end
115
- end
116
-
117
- %w{ total_travel fuel_consumption ch4_emission_factor n2o_emission_factor }.each do |attribute|
118
- verify "#{attribute.humanize} should be greater than zero" do
119
- AutomobileTypeFuelYear.all.each do |record|
120
- value = record.send(:"#{attribute}")
121
- unless value > 0
122
- raise "Invalid #{attribute.humanize.downcase} for AutomobileTypeFuelYear '#{record.name}': #{value} (should be > 0)"
123
- end
124
- end
125
- end
126
- end
127
-
128
- [["total_travel_units", "kilometres"],
129
- ["fuel_consumption_units", "litres"],
130
- ["ch4_emission_factor_units", "kilograms_per_litre"],
131
- ["n2o_emission_factor_units", "kilograms_per_litre"]].each do |pair|
132
- attribute = pair[0]
133
- proper_units = pair[1]
134
- verify "#{attribute.humanize} should be #{proper_units.humanize.downcase}" do
135
- AutomobileTypeFuelYear.all.each do |record|
136
- units = record.send(:"#{attribute}")
137
- unless units == proper_units
138
- raise "Invalid #{attribute.humanize.downcase} for AutomobileTypeFuelYear '#{record.name}': #{units} (should be #{proper_units})"
139
- end
140
- end
141
- end
142
- end
143
92
  end
144
93
  end
@@ -3,16 +3,68 @@ class AutomobileTypeFuelYearAge < ActiveRecord::Base
3
3
 
4
4
  belongs_to :type_fuel_year, :class_name => 'AutomobileTypeFuelYear', :foreign_key => 'type_fuel_year_name'
5
5
 
6
- force_schema do
7
- string 'name'
8
- string 'type_name'
9
- string 'fuel_common_name'
10
- integer 'year'
11
- integer 'age'
12
- string 'type_fuel_year_name'
13
- float 'total_travel_percent'
14
- float 'annual_distance'
15
- string 'annual_distance_units'
16
- integer 'vehicles'
17
- end
6
+ col :name
7
+ col :type_name
8
+ col :fuel_common_name
9
+ col :year, :type => :integer
10
+ col :age, :type => :integer
11
+ col :type_fuel_year_name
12
+ col :total_travel_percent, :type => :float
13
+ col :annual_distance, :type => :float
14
+ col :annual_distance_units
15
+ col :vehicles, :type => :integer
16
+
17
+ # %w{ type_name fuel_common_name type_fuel_year_name}.each do |attribute|
18
+ # verify "#{attribute.humanize} should never be missing" do
19
+ # AutomobileTypeFuelYearAge.all.each do |record|
20
+ # value = record.send(:"#{attribute}")
21
+ # unless value.present?
22
+ # raise "Missing #{attribute.humanize.downcase} for AutomobileTypeFuelYearAge '#{record.name}'"
23
+ # end
24
+ # end
25
+ # end
26
+ # end
27
+ #
28
+ # verify "Year should be 2008" do
29
+ # AutomobileTypeFuelYearAge.all.each do |record|
30
+ # value = record.send(:year)
31
+ # unless value == 2008
32
+ # raise "Invalid year for AutomobileTypeFuelYearAge '#{record.name}': #{value} (should be 2008)"
33
+ # end
34
+ # end
35
+ # end
36
+ #
37
+ # [["age", 0, 30], ["total_travel_percent", 0, 1]].each do |triplet|
38
+ # attribute = triplet[0]
39
+ # min = triplet[1]
40
+ # max = triplet[2]
41
+ # verify "#{attribute.humanize} should be from #{min} to #{max}" do
42
+ # AutomobileTypeFuelYearAge.all.each do |record|
43
+ # value = record.send(:"#{attribute}")
44
+ # unless value >= min and value <= max
45
+ # raise "Invalid #{attribute.humanize.downcase} for AutomobileTypeFuelYearAge '#{record.name}': #{value} (should be from #{min} to #{max})"
46
+ # end
47
+ # end
48
+ # end
49
+ # end
50
+ #
51
+ # %w{ annual_distance vehicles }.each do |attribute|
52
+ # verify "#{attribute.humanize} should be greater than zero" do
53
+ # AutomobileTypeFuelYearAge.all.each do |record|
54
+ # value = record.send(:"#{attribute}")
55
+ # unless value > 0
56
+ # raise "Invalid #{attribute.humanize.downcase} for AutomobileTypeFuelYearAge '#{record.name}': #{value} (should be > 0)"
57
+ # end
58
+ # end
59
+ # end
60
+ # end
61
+ #
62
+ # verify "Annual distance units should be kilometres" do
63
+ # AutomobileTypeFuelYearAge.all.each do |record|
64
+ # units = record.send(:annual_distance_units)
65
+ # unless units == "kilometres"
66
+ # raise "Invalid annual distance units for AutomobileTypeFuelYearAge '#{record.name}': #{units} (should be kilometres)"
67
+ # end
68
+ # end
69
+ # end
18
70
  end
@@ -99,11 +99,7 @@ AutomobileTypeFuelYearAge.class_eval do
99
99
  end
100
100
 
101
101
  process "Derive type fuel year name for association with AutomobileTypeFuelYear" do
102
- if ActiveRecord::Base.connection.adapter_name.downcase == 'sqlite'
103
- update_all "type_fuel_year_name = type_name || ' ' || fuel_common_name || ' ' || year"
104
- else
105
- update_all "type_fuel_year_name = CONCAT(type_name, ' ', fuel_common_name, ' ', year)"
106
- end
102
+ update_all "type_fuel_year_name = type_name || ' ' || fuel_common_name || ' ' || year"
107
103
  end
108
104
 
109
105
  process "Ensure AutomobileTypeFuelYear is populated" do
@@ -116,59 +112,5 @@ AutomobileTypeFuelYearAge.class_eval do
116
112
  record.save
117
113
  end
118
114
  end
119
-
120
- %w{ type_name fuel_common_name type_fuel_year_name}.each do |attribute|
121
- verify "#{attribute.humanize} should never be missing" do
122
- AutomobileTypeFuelYearAge.all.each do |record|
123
- value = record.send(:"#{attribute}")
124
- unless value.present?
125
- raise "Missing #{attribute.humanize.downcase} for AutomobileTypeFuelYearAge '#{record.name}'"
126
- end
127
- end
128
- end
129
- end
130
-
131
- verify "Year should be 2008" do
132
- AutomobileTypeFuelYearAge.all.each do |record|
133
- value = record.send(:year)
134
- unless value == 2008
135
- raise "Invalid year for AutomobileTypeFuelYearAge '#{record.name}': #{value} (should be 2008)"
136
- end
137
- end
138
- end
139
-
140
- [["age", 0, 30], ["total_travel_percent", 0, 1]].each do |triplet|
141
- attribute = triplet[0]
142
- min = triplet[1]
143
- max = triplet[2]
144
- verify "#{attribute.humanize} should be from #{min} to #{max}" do
145
- AutomobileTypeFuelYearAge.all.each do |record|
146
- value = record.send(:"#{attribute}")
147
- unless value >= min and value <= max
148
- raise "Invalid #{attribute.humanize.downcase} for AutomobileTypeFuelYearAge '#{record.name}': #{value} (should be from #{min} to #{max})"
149
- end
150
- end
151
- end
152
- end
153
-
154
- %w{ annual_distance vehicles }.each do |attribute|
155
- verify "#{attribute.humanize} should be greater than zero" do
156
- AutomobileTypeFuelYearAge.all.each do |record|
157
- value = record.send(:"#{attribute}")
158
- unless value > 0
159
- raise "Invalid #{attribute.humanize.downcase} for AutomobileTypeFuelYearAge '#{record.name}': #{value} (should be > 0)"
160
- end
161
- end
162
- end
163
- end
164
-
165
- verify "Annual distance units should be kilometres" do
166
- AutomobileTypeFuelYearAge.all.each do |record|
167
- units = record.send(:annual_distance_units)
168
- unless units == "kilometres"
169
- raise "Invalid annual distance units for AutomobileTypeFuelYearAge '#{record.name}': #{units} (should be kilometres)"
170
- end
171
- end
172
- end
173
115
  end
174
116
  end
@@ -3,14 +3,35 @@ class AutomobileTypeFuelYearControl < ActiveRecord::Base
3
3
 
4
4
  belongs_to :control, :class_name => 'AutomobileTypeFuelControl', :foreign_key => 'type_fuel_control_name'
5
5
 
6
- force_schema do
7
- string 'name'
8
- string 'type_name'
9
- string 'fuel_common_name'
10
- integer 'year'
11
- string 'control_name'
12
- string 'type_fuel_control_name'
13
- string 'type_fuel_year_name'
14
- float 'total_travel_percent'
15
- end
6
+ col :name
7
+ col :type_name
8
+ col :fuel_common_name
9
+ col :year, :type => :integer
10
+ col :control_name
11
+ col :type_fuel_control_name
12
+ col :type_fuel_year_name
13
+ col :total_travel_percent, :type => :float
14
+
15
+ # %w{ type_name fuel_common_name control_name type_fuel_control_name type_fuel_year_name }.each do |attribute|
16
+ # verify "#{attribute.humanize} should never be missing" do
17
+ # AutomobileTypeFuelYearControl.all.each do |record|
18
+ # value = record.send(:"#{attribute}")
19
+ # unless value.present?
20
+ # raise "Missing #{attribute.humanize.downcase} for AutomobileTypeFuelYearControl '#{record.name}'"
21
+ # end
22
+ # end
23
+ # end
24
+ # end
25
+ #
26
+ # verify "Year should be from 1990 to 2008" do
27
+ # AutomobileTypeFuelYearControl.all.each do |record|
28
+ # year = record.send(:year)
29
+ # unless year > 1989 and year < 2009
30
+ # raise "Invalid year for AutomobileTypeFuelYearControl '#{record.name}': #{year} (should be from 1990 to 2008)"
31
+ # end
32
+ # end
33
+ # end
34
+
35
+ # FIXME TODO verify "Total travel percent for each type fuel year should sum to one"
36
+
16
37
  end
@@ -11,41 +11,11 @@ AutomobileTypeFuelYearControl.class_eval do
11
11
  end
12
12
 
13
13
  process "Derive type fuel control name for association with AutomobileTypeFuelControl" do
14
- if ActiveRecord::Base.connection.adapter_name.downcase == 'sqlite'
15
- update_all "type_fuel_control_name = type_name || ' ' || fuel_common_name || ' ' || control_name"
16
- else
17
- update_all "type_fuel_control_name = CONCAT(type_name, ' ', fuel_common_name, ' ', control_name)"
18
- end
14
+ update_all "type_fuel_control_name = type_name || ' ' || fuel_common_name || ' ' || control_name"
19
15
  end
20
16
 
21
17
  process "Derive type fuel year name for association with AutomobileTypeFuelYear" do
22
- if ActiveRecord::Base.connection.adapter_name.downcase == 'sqlite'
23
- update_all "type_fuel_year_name = type_name || ' ' || fuel_common_name || ' ' || year"
24
- else
25
- update_all "type_fuel_year_name = CONCAT(type_name, ' ', fuel_common_name, ' ', year)"
26
- end
18
+ update_all "type_fuel_year_name = type_name || ' ' || fuel_common_name || ' ' || year"
27
19
  end
28
-
29
- %w{ type_name fuel_common_name control_name type_fuel_control_name type_fuel_year_name }.each do |attribute|
30
- verify "#{attribute.humanize} should never be missing" do
31
- AutomobileTypeFuelYearControl.all.each do |record|
32
- value = record.send(:"#{attribute}")
33
- unless value.present?
34
- raise "Missing #{attribute.humanize.downcase} for AutomobileTypeFuelYearControl '#{record.name}'"
35
- end
36
- end
37
- end
38
- end
39
-
40
- verify "Year should be from 1990 to 2008" do
41
- AutomobileTypeFuelYearControl.all.each do |record|
42
- year = record.send(:year)
43
- unless year > 1989 and year < 2009
44
- raise "Invalid year for AutomobileTypeFuelYearControl '#{record.name}': #{year} (should be from 1990 to 2008)"
45
- end
46
- end
47
- end
48
-
49
- # FIXME TODO verify "Total travel percent for each type fuel year should sum to one"
50
20
  end
51
21
  end
@@ -3,13 +3,54 @@ class AutomobileTypeYear < ActiveRecord::Base
3
3
 
4
4
  has_many :type_fuel_years, :class_name => 'AutomobileTypeFuelYear', :foreign_key => 'type_year_name'
5
5
 
6
- force_schema do
7
- string 'name'
8
- string 'type_name'
9
- integer 'year'
10
- float 'hfc_emissions'
11
- string 'hfc_emissions_units'
12
- float 'hfc_emission_factor'
13
- string 'hfc_emission_factor_units'
14
- end
15
- end
6
+ col :name
7
+ col :type_name
8
+ col :year, :type => :integer
9
+ col :hfc_emissions, :type => :float
10
+ col :hfc_emissions_units
11
+ col :hfc_emission_factor, :type => :float
12
+ col :hfc_emission_factor_units
13
+
14
+ # verify "Type name should never be missing" do
15
+ # AutomobileTypeYear.all.each do |record|
16
+ # value = record.send(:type_name)
17
+ # unless value.present?
18
+ # raise "Missing type name for AutomobileTypeYear '#{record.name}'"
19
+ # end
20
+ # end
21
+ # end
22
+ #
23
+ # verify "Year should be from 1990 to 2008" do
24
+ # AutomobileTypeYear.all.each do |record|
25
+ # year = record.send(:year)
26
+ # unless year > 1989 and year < 2009
27
+ # raise "Invalid year for AutomobileTypeYear '#{record.name}': #{year} (should be from 1990 to 2008)"
28
+ # end
29
+ # end
30
+ # end
31
+ #
32
+ # %w{ hfc_emissions hfc_emission_factor }.each do |attribute|
33
+ # verify "#{attribute.humanize} should be zero or more" do
34
+ # AutomobileTypeYear.all.each do |record|
35
+ # value = record.send(:"#{attribute}")
36
+ # unless value >= 0
37
+ # raise "Invalid #{attribute.humanize.downcase} for AutomobileTypeYear '#{record.name}': #{value} (should be zero or more)"
38
+ # end
39
+ # end
40
+ # end
41
+ # end
42
+ #
43
+ # [["hfc_emissions_units", "kilograms_co2e"], ["hfc_emission_factor_units", "kilograms_co2e_per_litre"]].each do |pair|
44
+ # attribute = pair[0]
45
+ # proper_units = pair[1]
46
+ # verify "#{attribute.humanize} should be #{proper_units.humanize.downcase}" do
47
+ # AutomobileTypeYear.all.each do |record|
48
+ # units = record.send(:"#{attribute}")
49
+ # unless units == proper_units
50
+ # raise "Invalid #{attribute.humanize.downcase} for AutomobileTypeYear '#{record.name}': #{units} (should be #{proper_units})"
51
+ # end
52
+ # end
53
+ # end
54
+ # end
55
+
56
+ end
@@ -18,48 +18,6 @@ AutomobileTypeYear.class_eval do
18
18
  record.hfc_emission_factor_units = "kilograms_co2e_per_litre"
19
19
  record.save
20
20
  end
21
- end
22
-
23
- verify "Type name should never be missing" do
24
- AutomobileTypeYear.all.each do |record|
25
- value = record.send(:type_name)
26
- unless value.present?
27
- raise "Missing type name for AutomobileTypeYear '#{record.name}'"
28
- end
29
- end
30
- end
31
-
32
- verify "Year should be from 1990 to 2008" do
33
- AutomobileTypeYear.all.each do |record|
34
- year = record.send(:year)
35
- unless year > 1989 and year < 2009
36
- raise "Invalid year for AutomobileTypeYear '#{record.name}': #{year} (should be from 1990 to 2008)"
37
- end
38
- end
39
- end
40
-
41
- %w{ hfc_emissions hfc_emission_factor }.each do |attribute|
42
- verify "#{attribute.humanize} should be zero or more" do
43
- AutomobileTypeYear.all.each do |record|
44
- value = record.send(:"#{attribute}")
45
- unless value >= 0
46
- raise "Invalid #{attribute.humanize.downcase} for AutomobileTypeYear '#{record.name}': #{value} (should be zero or more)"
47
- end
48
- end
49
- end
50
- end
51
-
52
- [["hfc_emissions_units", "kilograms_co2e"], ["hfc_emission_factor_units", "kilograms_co2e_per_litre"]].each do |pair|
53
- attribute = pair[0]
54
- proper_units = pair[1]
55
- verify "#{attribute.humanize} should be #{proper_units.humanize.downcase}" do
56
- AutomobileTypeYear.all.each do |record|
57
- units = record.send(:"#{attribute}")
58
- unless units == proper_units
59
- raise "Invalid #{attribute.humanize.downcase} for AutomobileTypeYear '#{record.name}': #{units} (should be #{proper_units})"
60
- end
61
- end
62
- end
63
- end
21
+ end
64
22
  end
65
23
  end
@@ -13,3 +13,4 @@ require 'earth/automobile/automobile_type_fuel_control/data_miner'
13
13
  require 'earth/automobile/automobile_type_fuel_year/data_miner'
14
14
  require 'earth/automobile/automobile_type_fuel_year_age/data_miner'
15
15
  require 'earth/automobile/automobile_type_fuel_year_control/data_miner'
16
+ require 'earth/fuel/data_miner'
@@ -28,32 +28,112 @@ class BusClass < ActiveRecord::Base
28
28
  :alternative_fuels_intensity => 0.04632038.gallons_per_mile.to(:litres_per_kilometre), # deprecated
29
29
  :alternative_fuels_intensity_units => 'litres_per_kilometre' # deprecated
30
30
 
31
- force_schema do
32
- string 'name'
33
- float 'distance'
34
- string 'distance_units'
35
- float 'passengers'
36
- float 'speed'
37
- string 'speed_units'
38
- float 'gasoline_intensity'
39
- string 'gasoline_intensity_units'
40
- float 'diesel_intensity'
41
- string 'diesel_intensity_units'
42
- float 'cng_intensity'
43
- string 'cng_intensity_units'
44
- float 'lng_intensity'
45
- string 'lng_intensity_units'
46
- float 'lpg_intensity'
47
- string 'lpg_intensity_units'
48
- float 'methanol_intensity'
49
- string 'methanol_intensity_units'
50
- float 'biodiesel_intensity'
51
- string 'biodiesel_intensity_units'
52
- float 'electricity_intensity'
53
- string 'electricity_intensity_units'
54
- float 'air_conditioning_emission_factor'
55
- string 'air_conditioning_emission_factor_units'
56
- float 'alternative_fuels_intensity'
57
- string 'alternative_fuels_intensity_units'
58
- end
31
+ col :name
32
+ col :distance, :type => :float
33
+ col :distance_units
34
+ col :passengers, :type => :float
35
+ col :speed, :type => :float
36
+ col :speed_units
37
+ col :gasoline_intensity, :type => :float
38
+ col :gasoline_intensity_units
39
+ col :diesel_intensity, :type => :float
40
+ col :diesel_intensity_units
41
+ col :cng_intensity, :type => :float
42
+ col :cng_intensity_units
43
+ col :lng_intensity, :type => :float
44
+ col :lng_intensity_units
45
+ col :lpg_intensity, :type => :float
46
+ col :lpg_intensity_units
47
+ col :methanol_intensity, :type => :float
48
+ col :methanol_intensity_units
49
+ col :biodiesel_intensity, :type => :float
50
+ col :biodiesel_intensity_units
51
+ col :electricity_intensity, :type => :float
52
+ col :electricity_intensity_units
53
+ col :air_conditioning_emission_factor, :type => :float
54
+ col :air_conditioning_emission_factor_units
55
+ col :alternative_fuels_intensity, :type => :float
56
+ col :alternative_fuels_intensity_units
57
+
58
+ # verify "Some attributes should be greater than zero" do
59
+ # BusClass.all.each do |bus_class|
60
+ # %w{ distance passengers speed diesel_intensity air_conditioning_emission_factor }.each do |attribute|
61
+ # value = bus_class.send(:"#{attribute}")
62
+ # unless value > 0
63
+ # raise "Invalid #{attribute.humanize.downcase} for BusClass #{bus_class.name}: #{value} (should be > 0)"
64
+ # end
65
+ # end
66
+ # end
67
+ # end
68
+ #
69
+ # verify "Some attributes should be zero or more" do
70
+ # BusClass.all.each do |bus_class|
71
+ # %w{ gasoline_intensity cng_intensity lng_intensity lpg_intensity methanol_intensity biodiesel_intensity electricity_intensity alternative_fuels_intensity }.each do |attribute|
72
+ # value = bus_class.send(:"#{attribute}")
73
+ # unless value >= 0
74
+ # raise "Invalid #{attribute.humanize.downcase} for BusClass #{bus_class.name}: #{value} (should be >= 0)"
75
+ # end
76
+ # end
77
+ # end
78
+ # end
79
+ #
80
+ # verify "Units should be correct" do
81
+ # BusClass.all.each do |bus_class|
82
+ # [["distance_units", "kilometres"],
83
+ # ["speed_units", "kilometres_per_hour"],
84
+ # ["diesel_intensity_units", "litres_per_kilometre"],
85
+ # ["gasoline_intensity_units", "litres_per_kilometre"],
86
+ # ["cng_intensity_units", "litres_per_kilometre"],
87
+ # ["lng_intensity_units", "litres_per_kilometre"],
88
+ # ["lpg_intensity_units", "litres_per_kilometre"],
89
+ # ["methanol_intensity_units", "litres_per_kilometre"],
90
+ # ["biodiesel_intensity_units", "litres_per_kilometre"],
91
+ # ["electricity_intensity_units", "kilowatt_hours_per_kilometre"],
92
+ # ["air_conditioning_emission_factor_units", "kilograms_co2e_per_kilometre"],
93
+ # ["alternative_fuels_intensity_units", "litres_per_kilometre"]].each do |pair|
94
+ # attribute = pair[0]
95
+ # proper_units = pair[1]
96
+ # units = bus_class.send(:"#{attribute}")
97
+ # unless units == proper_units
98
+ # raise "Invalid #{attribute.humanize.downcase} for BusClass #{bus_class.name}: #{units} (should be #{proper_units})"
99
+ # end
100
+ # end
101
+ # end
102
+ # end
103
+ #
104
+ # verify "Fallbacks should satisfy same constraints as data" do
105
+ # %w{ distance passengers speed diesel_intensity air_conditioning_emission_factor }.each do |attribute|
106
+ # value = BusClass.fallback.send(:"#{attribute}")
107
+ # unless value > 0
108
+ # raise "Invalid #{attribute.humanize.downcase} for fallback BusClass: #{value} (should be > 0)"
109
+ # end
110
+ # end
111
+ #
112
+ # %w{ gasoline_intensity cng_intensity lng_intensity lpg_intensity methanol_intensity biodiesel_intensity electricity_intensity alternative_fuels_intensity }.each do |attribute|
113
+ # value = BusClass.fallback.send(:"#{attribute}")
114
+ # unless value >= 0
115
+ # raise "Invalid #{attribute.humanize.downcase} for fallback BusClass: #{value} (should be >= 0)"
116
+ # end
117
+ # end
118
+ #
119
+ # [["distance_units", "kilometres"],
120
+ # ["speed_units", "kilometres_per_hour"],
121
+ # ["diesel_intensity_units", "litres_per_kilometre"],
122
+ # ["gasoline_intensity_units", "litres_per_kilometre"],
123
+ # ["cng_intensity_units", "litres_per_kilometre"],
124
+ # ["lng_intensity_units", "litres_per_kilometre"],
125
+ # ["lpg_intensity_units", "litres_per_kilometre"],
126
+ # ["methanol_intensity_units", "litres_per_kilometre"],
127
+ # ["biodiesel_intensity_units", "litres_per_kilometre"],
128
+ # ["electricity_intensity_units", "kilowatt_hours_per_kilometre"],
129
+ # ["air_conditioning_emission_factor_units", "kilograms_co2e_per_kilometre"],
130
+ # ["alternative_fuels_intensity_units", "litres_per_kilometre"]].each do |pair|
131
+ # attribute = pair[0]
132
+ # proper_units = pair[1]
133
+ # units = BusClass.fallback.send(:"#{attribute}")
134
+ # unless units == proper_units
135
+ # raise "Invalid #{attribute.humanize.downcase} for fallback BusClass: #{units} (should be #{proper_units})"
136
+ # end
137
+ # end
138
+ # end
59
139
  end