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
@@ -30,71 +30,5 @@ AutomobileSizeClass.class_eval do
30
30
  store 'conventional_fuel_efficiency_city_multiplier'
31
31
  store 'conventional_fuel_efficiency_highway_multiplier'
32
32
  end
33
-
34
- # FIXME TODO verify type_name?
35
-
36
- verify "Annual distance should be greater than zero" do
37
- AutomobileSizeClass.all.each do |size_class|
38
- unless size_class.annual_distance > 0
39
- raise "Invalid annual distance for AutomobileSizeClass #{size_class.name}: #{size_class.annual_distance} (should be > 0)"
40
- end
41
- end
42
- end
43
-
44
- verify "Annual distance units should be kilometres" do
45
- AutomobileSizeClass.all.each do |size_class|
46
- unless size_class.annual_distance_units == "kilometres"
47
- raise "Invalid annual distance units for AutomobileSizeClass #{size_class.name}: #{size_class.annual_distance_units} (should be kilometres)"
48
- end
49
- end
50
- end
51
-
52
- verify "Fuel efficiencies should be greater than zero" do
53
- AutomobileSizeClass.all.each do |size_class|
54
- %w{ city highway }.each do |type|
55
- fuel_efficiency = size_class.send(:"fuel_efficiency_#{type}")
56
- unless fuel_efficiency > 0
57
- raise "Invalid fuel efficiency #{type} for AutomobileSizeClass #{size_class.name}: #{fuel_efficiency} (should be > 0)"
58
- end
59
- end
60
- end
61
- end
62
-
63
- verify "Fuel efficiency units should be kilometres per litre" do
64
- AutomobileSizeClass.all.each do |size_class|
65
- %w{ city highway }.each do |type|
66
- units = size_class.send(:"fuel_efficiency_#{type}_units")
67
- unless units == "kilometres_per_litre"
68
- raise "Invalid fuel efficiency #{type} units for AutomobileSizeClass #{size_class.name}: #{units} (should be kilometres_per_litre)"
69
- end
70
- end
71
- end
72
- end
73
-
74
- verify "Any fuel efficiency multipliers should be greater than zero" do
75
- AutomobileSizeClass.all.each do |size_class|
76
- %w{ hybrid conventional }.each do |hybridity|
77
- %w{ city highway }.each do |type|
78
- multiplier = size_class.send(:"#{hybridity}_fuel_efficiency_#{type}_multiplier")
79
- if multiplier.present?
80
- unless multiplier > 0
81
- raise "Invalid #{hybridity} fuel efficiency #{type} multiplier for AutomobileSizeClass #{size_class.name}: #{multiplier} (should be > 0)"
82
- end
83
- end
84
- end
85
- end
86
- end
87
- end
88
-
89
- verify "Fallback fuel efficiency multipliers should be greater than zero" do
90
- %w{ hybrid conventional }.each do |hybridity|
91
- %w{ city highway }.each do |type|
92
- multiplier = AutomobileSizeClass.fallback.send(:"#{hybridity}_fuel_efficiency_#{type}_multiplier")
93
- unless multiplier > 0
94
- raise "Invalid AutomobileSizeClass fallback #{hybridity} fuel efficiency #{type} multiplier: #{multiplier} (should be > 0)"
95
- end
96
- end
97
- end
98
- end
99
33
  end
100
34
  end
@@ -1,14 +1,42 @@
1
1
  class AutomobileSizeClassYear < ActiveRecord::Base
2
2
  set_primary_key :name
3
3
 
4
- force_schema do
5
- string 'name'
6
- string 'size_class_name'
7
- integer 'year'
8
- string 'type_name'
9
- float 'fuel_efficiency_city'
10
- string 'fuel_efficiency_city_units'
11
- float 'fuel_efficiency_highway'
12
- string 'fuel_efficiency_highway_units'
13
- end
4
+ col :name
5
+ col :size_class_name
6
+ col :year, :type => :integer
7
+ col :type_name
8
+ col :fuel_efficiency_city, :type => :float
9
+ col :fuel_efficiency_city_units
10
+ col :fuel_efficiency_highway, :type => :float
11
+ col :fuel_efficiency_highway_units
12
+
13
+ # verify "Year should be from 1975 to 2010" do
14
+ # AutomobileSizeClassYear.all.each do |record|
15
+ # unless record.year > 1974 and record.year < 2011
16
+ # raise "Invalid year for AutomobileSizeClassYear #{record.name}: #{record.year} (should be from 1975 to 2010)"
17
+ # end
18
+ # end
19
+ # end
20
+ #
21
+ # verify "Fuel efficiencies should be greater than zero" do
22
+ # AutomobileSizeClassYear.all.each do |year|
23
+ # %w{ fuel_efficiency_city fuel_efficiency_highway }.each do |attribute|
24
+ # value = year.send(:"#{attribute}")
25
+ # unless value > 0
26
+ # raise "Invalid #{attribute} for AutomobileSizeClassYear #{year.name}: #{value} (should be > 0)"
27
+ # end
28
+ # end
29
+ # end
30
+ # end
31
+ #
32
+ # verify "Fuel efficiency units should be kilometres per litre" do
33
+ # AutomobileSizeClassYear.all.each do |year|
34
+ # %w{ fuel_efficiency_city_units fuel_efficiency_highway_units }.each do |attribute|
35
+ # value = year.send(:"#{attribute}")
36
+ # unless value == "kilometres_per_litre"
37
+ # raise "Invalid #{attribute} for AutomobileSizeClassYear #{year.name}: #{value} (should be kilometres_per_litre)"
38
+ # end
39
+ # end
40
+ # end
41
+ # end
14
42
  end
@@ -12,35 +12,5 @@ AutomobileSizeClassYear.class_eval do
12
12
 
13
13
  # FIXME TODO verify that size_class_name is never missing?
14
14
  # FIXME TODO verify that type_name appears in AutomobileTypeFuelYearAges
15
-
16
- verify "Year should be from 1975 to 2010" do
17
- AutomobileSizeClassYear.all.each do |record|
18
- unless record.year > 1974 and record.year < 2011
19
- raise "Invalid year for AutomobileSizeClassYear #{record.name}: #{record.year} (should be from 1975 to 2010)"
20
- end
21
- end
22
- end
23
-
24
- verify "Fuel efficiencies should be greater than zero" do
25
- AutomobileSizeClassYear.all.each do |year|
26
- %w{ fuel_efficiency_city fuel_efficiency_highway }.each do |attribute|
27
- value = year.send(:"#{attribute}")
28
- unless value > 0
29
- raise "Invalid #{attribute} for AutomobileSizeClassYear #{year.name}: #{value} (should be > 0)"
30
- end
31
- end
32
- end
33
- end
34
-
35
- verify "Fuel efficiency units should be kilometres per litre" do
36
- AutomobileSizeClassYear.all.each do |year|
37
- %w{ fuel_efficiency_city_units fuel_efficiency_highway_units }.each do |attribute|
38
- value = year.send(:"#{attribute}")
39
- unless value == "kilometres_per_litre"
40
- raise "Invalid #{attribute} for AutomobileSizeClassYear #{year.name}: #{value} (should be kilometres_per_litre)"
41
- end
42
- end
43
- end
44
- end
45
15
  end
46
16
  end
@@ -2,15 +2,64 @@
2
2
  class AutomobileTypeFuelAge < ActiveRecord::Base
3
3
  set_primary_key :name
4
4
 
5
- force_schema do
6
- string 'name'
7
- string 'type_name'
8
- string 'fuel_common_name'
9
- integer 'age'
10
- float 'age_percent'
11
- float 'total_travel_percent'
12
- float 'annual_distance'
13
- string 'annual_distance_units'
14
- integer 'vehicles'
15
- end
5
+ col :name
6
+ col :type_name
7
+ col :fuel_common_name
8
+ col :age, :type => :integer
9
+ col :age_percent, :type => :float
10
+ col :total_travel_percent, :type => :float
11
+ col :annual_distance, :type => :float
12
+ col :annual_distance_units
13
+ col :vehicles, :type => :integer
14
+
15
+ # verify "Type name and fuel common name should never be missing" do
16
+ # AutomobileTypeFuelAge.all.each do |record|
17
+ # %w{ type_name fuel_common_name }.each do |attribute|
18
+ # value = record.send(:"#{attribute}")
19
+ # unless value.present?
20
+ # raise "Missing #{attribute} for AutomobileTypeFuelAge '#{record.name}'"
21
+ # end
22
+ # end
23
+ # end
24
+ # end
25
+ #
26
+ # verify "Age should be from zero to thirty" do
27
+ # AutomobileTypeFuelAge.all.each do |record|
28
+ # value = record.send(:age)
29
+ # unless value >= 0 and value < 31
30
+ # raise "Invalid age for AutomobileTypeFuelAge '#{record.name}': #{value} (should be from 0 to 30)"
31
+ # end
32
+ # end
33
+ # end
34
+ #
35
+ # verify "Age percent and total travel percent should be from zero to one" do
36
+ # AutomobileTypeFuelAge.all.each do |record|
37
+ # %w{ age_percent total_travel_percent }.each do |attribute|
38
+ # percent = record.send(:"#{attribute}")
39
+ # unless percent > 0 and percent < 1
40
+ # raise "Invalid #{attribute} for AutomobileTypeFuelAge '#{record.name}': #{percent} (should be from 0 to 1)"
41
+ # end
42
+ # end
43
+ # end
44
+ # end
45
+ #
46
+ # verify "Annual distance and vehicles should be greater than zero" do
47
+ # AutomobileTypeFuelAge.all.each do |record|
48
+ # %w{ annual_distance vehicles }.each do |attribute|
49
+ # value = record.send(:"#{attribute}")
50
+ # unless value > 0
51
+ # raise "Invalid #{attribute} for AutomobileTypeFuelAge '#{record.name}': #{value} (should be > 0)"
52
+ # end
53
+ # end
54
+ # end
55
+ # end
56
+ #
57
+ # verify "Annual distance units should be kilometres" do
58
+ # AutomobileTypeFuelAge.all.each do |record|
59
+ # units = record.send(:annual_distance_units)
60
+ # unless units == "kilometres"
61
+ # raise "Invalid annual distance units for AutomobileTypeFuelAge '#{record.name}': #{units} (should be kilometres)"
62
+ # end
63
+ # end
64
+ # end
16
65
  end
@@ -133,72 +133,17 @@ AutomobileTypeFuelAge.class_eval do
133
133
 
134
134
  # FIXME TODO maybe make this a method on AutomobileTypeFuelAge?
135
135
  process "Calculate number of vehicles from total travel percent and AutomobileTypeFuelYear" do
136
- connection.execute %{
137
- UPDATE automobile_type_fuel_ages
138
- SET vehicles =
139
- (
140
- (
141
- SELECT automobile_type_fuel_years.total_travel
142
- FROM automobile_type_fuel_years
143
- WHERE automobile_type_fuel_years.`year` =
144
- (SELECT max(automobile_type_fuel_years.`year`) FROM automobile_type_fuel_years)
145
- AND automobile_type_fuel_years.`type_name` = automobile_type_fuel_ages.`type_name`
146
- AND automobile_type_fuel_years.fuel_common_name = automobile_type_fuel_ages.fuel_common_name
147
- ) *
148
- automobile_type_fuel_ages.total_travel_percent / automobile_type_fuel_ages.annual_distance
149
- )
136
+ max_year = AutomobileTypeFuelYear.maximum :year
137
+ update_all %{
138
+ vehicles =
139
+ ( SELECT t1.total_travel
140
+ FROM #{AutomobileTypeFuelYear.quoted_table_name} AS t1
141
+ WHERE
142
+ t1.year = #{max_year}
143
+ AND t1.type_name = #{quoted_table_name}.type_name
144
+ AND t1.fuel_common_name = #{quoted_table_name}.fuel_common_name )
145
+ * #{quoted_table_name}.total_travel_percent / #{quoted_table_name}.annual_distance
150
146
  }
151
147
  end
152
-
153
- verify "Type name and fuel common name should never be missing" do
154
- AutomobileTypeFuelAge.all.each do |record|
155
- %w{ type_name fuel_common_name }.each do |attribute|
156
- value = record.send(:"#{attribute}")
157
- unless value.present?
158
- raise "Missing #{attribute} for AutomobileTypeFuelAge '#{record.name}'"
159
- end
160
- end
161
- end
162
- end
163
-
164
- verify "Age should be from zero to thirty" do
165
- AutomobileTypeFuelAge.all.each do |record|
166
- value = record.send(:age)
167
- unless value >= 0 and value < 31
168
- raise "Invalid age for AutomobileTypeFuelAge '#{record.name}': #{value} (should be from 0 to 30)"
169
- end
170
- end
171
- end
172
-
173
- verify "Age percent and total travel percent should be from zero to one" do
174
- AutomobileTypeFuelAge.all.each do |record|
175
- %w{ age_percent total_travel_percent }.each do |attribute|
176
- percent = record.send(:"#{attribute}")
177
- unless percent > 0 and percent < 1
178
- raise "Invalid #{attribute} for AutomobileTypeFuelAge '#{record.name}': #{percent} (should be from 0 to 1)"
179
- end
180
- end
181
- end
182
- end
183
-
184
- verify "Annual distance and vehicles should be greater than zero" do
185
- AutomobileTypeFuelAge.all.each do |record|
186
- %w{ annual_distance vehicles }.each do |attribute|
187
- value = record.send(:"#{attribute}")
188
- unless value > 0
189
- raise "Invalid #{attribute} for AutomobileTypeFuelAge '#{record.name}': #{value} (should be > 0)"
190
- end
191
- end
192
- end
193
- end
194
-
195
- verify "Annual distance units should be kilometres" do
196
- AutomobileTypeFuelAge.all.each do |record|
197
- units = record.send(:annual_distance_units)
198
- unless units == "kilometres"
199
- raise "Invalid annual distance units for AutomobileTypeFuelAge '#{record.name}': #{units} (should be kilometres)"
200
- end
201
- end
202
- end
203
148
  end
204
149
  end
@@ -1,13 +1,44 @@
1
1
  class AutomobileTypeFuelControl < ActiveRecord::Base
2
2
  set_primary_key :name
3
- force_schema do
4
- string 'name'
5
- string 'type_name'
6
- string 'fuel_common_name'
7
- string 'control_name'
8
- float 'ch4_emission_factor'
9
- string 'ch4_emission_factor_units'
10
- float 'n2o_emission_factor'
11
- string 'n2o_emission_factor_units'
12
- end
3
+ col :name
4
+ col :type_name
5
+ col :fuel_common_name
6
+ col :control_name
7
+ col :ch4_emission_factor, :type => :float
8
+ col :ch4_emission_factor_units
9
+ col :n2o_emission_factor, :type => :float
10
+ col :n2o_emission_factor_units
11
+
12
+ # verify "Type name, fuel common name, and control name should never be missing" do
13
+ # AutomobileTypeFuelControl.all.each do |record|
14
+ # %w{ type_name fuel_common_name control_name }.each do |attribute|
15
+ # value = record.send(:"#{attribute}")
16
+ # unless value.present?
17
+ # raise "Missing #{attribute} for AutomobileTypeFuelControl '#{record.name}'"
18
+ # end
19
+ # end
20
+ # end
21
+ # end
22
+ #
23
+ # verify "Emission factors should be greater than zero" do
24
+ # AutomobileTypeFuelControl.all.each do |record|
25
+ # %w{ ch4_emission_factor n2o_emission_factor }.each do |factor|
26
+ # value = record.send(:"#{factor}")
27
+ # unless value > 0
28
+ # raise "Invalid #{factor} for AutomobileTypeFuelControl '#{record.name}': #{valuel} (should be > 0)"
29
+ # end
30
+ # end
31
+ # end
32
+ # end
33
+ #
34
+ # verify "Emission factor units should be kilograms per kilometre" do
35
+ # AutomobileTypeFuelControl.all.each do |record|
36
+ # %w{ ch4_emission_factor_units n2o_emission_factor_units }.each do |attribute|
37
+ # units = record.send(:"#{attribute}")
38
+ # unless units == "kilograms_per_kilometre"
39
+ # raise "Invalid #{attribute} for AutomobileTypeFuelControl '#{record.name}': #{units} (should be kilograms_per_kilometre)"
40
+ # end
41
+ # end
42
+ # end
43
+ # end
13
44
  end
@@ -9,38 +9,5 @@ AutomobileTypeFuelControl.class_eval do
9
9
  store 'ch4_emission_factor', :units_field_name => 'ch4_emission_factor_units'
10
10
  store 'n2o_emission_factor', :units_field_name => 'n2o_emission_factor_units'
11
11
  end
12
-
13
- verify "Type name, fuel common name, and control name should never be missing" do
14
- AutomobileTypeFuelControl.all.each do |record|
15
- %w{ type_name fuel_common_name control_name }.each do |attribute|
16
- value = record.send(:"#{attribute}")
17
- unless value.present?
18
- raise "Missing #{attribute} for AutomobileTypeFuelControl '#{record.name}'"
19
- end
20
- end
21
- end
22
- end
23
-
24
- verify "Emission factors should be greater than zero" do
25
- AutomobileTypeFuelControl.all.each do |record|
26
- %w{ ch4_emission_factor n2o_emission_factor }.each do |factor|
27
- value = record.send(:"#{factor}")
28
- unless value > 0
29
- raise "Invalid #{factor} for AutomobileTypeFuelControl '#{record.name}': #{valuel} (should be > 0)"
30
- end
31
- end
32
- end
33
- end
34
-
35
- verify "Emission factor units should be kilograms per kilometre" do
36
- AutomobileTypeFuelControl.all.each do |record|
37
- %w{ ch4_emission_factor_units n2o_emission_factor_units }.each do |attribute|
38
- units = record.send(:"#{attribute}")
39
- unless units == "kilograms_per_kilometre"
40
- raise "Invalid #{attribute} for AutomobileTypeFuelControl '#{record.name}': #{units} (should be kilograms_per_kilometre)"
41
- end
42
- end
43
- end
44
- end
45
12
  end
46
13
  end
@@ -4,19 +4,64 @@ class AutomobileTypeFuelYear < ActiveRecord::Base
4
4
  has_many :year_controls, :class_name => 'AutomobileTypeFuelYearControl', :foreign_key => 'type_fuel_year_name'
5
5
  belongs_to :type_year, :class_name => 'AutomobileTypeYear', :foreign_key => 'type_year_name'
6
6
 
7
- force_schema do
8
- string 'name'
9
- string 'type_name'
10
- string 'fuel_common_name'
11
- integer 'year'
12
- string 'type_year_name'
13
- float 'total_travel'
14
- string 'total_travel_units'
15
- float 'fuel_consumption'
16
- string 'fuel_consumption_units'
17
- float 'ch4_emission_factor'
18
- string 'ch4_emission_factor_units'
19
- float 'n2o_emission_factor'
20
- string 'n2o_emission_factor_units'
21
- end
7
+ col :name
8
+ col :type_name
9
+ col :fuel_common_name
10
+ col :year, :type => :integer
11
+ col :type_year_name
12
+ col :total_travel, :type => :float
13
+ col :total_travel_units
14
+ col :fuel_consumption, :type => :float
15
+ col :fuel_consumption_units
16
+ col :ch4_emission_factor, :type => :float
17
+ col :ch4_emission_factor_units
18
+ col :n2o_emission_factor, :type => :float
19
+ col :n2o_emission_factor_units
20
+
21
+ # %w{ type_name fuel_common_name type_year_name }.each do |attribute|
22
+ # verify "#{attribute.humanize} should never be missing" do
23
+ # AutomobileTypeFuelYear.all.each do |record|
24
+ # value = record.send(:"#{attribute}")
25
+ # unless value.present?
26
+ # raise "Missing #{attribute.humanize.downcase} for AutomobileTypeFuelYear '#{record.name}'"
27
+ # end
28
+ # end
29
+ # end
30
+ # end
31
+ #
32
+ # verify "Year should be from 1990 to 2008" do
33
+ # AutomobileTypeFuelYear.all.each do |record|
34
+ # year = record.send(:year)
35
+ # unless year > 1989 and year < 2009
36
+ # raise "Invalid year for AutomobileTypeFuelYear '#{record.name}': #{year} (should be from 1990 to 2008)"
37
+ # end
38
+ # end
39
+ # end
40
+ #
41
+ # %w{ total_travel fuel_consumption ch4_emission_factor n2o_emission_factor }.each do |attribute|
42
+ # verify "#{attribute.humanize} should be greater than zero" do
43
+ # AutomobileTypeFuelYear.all.each do |record|
44
+ # value = record.send(:"#{attribute}")
45
+ # unless value > 0
46
+ # raise "Invalid #{attribute.humanize.downcase} for AutomobileTypeFuelYear '#{record.name}': #{value} (should be > 0)"
47
+ # end
48
+ # end
49
+ # end
50
+ # end
51
+ #
52
+ # [["total_travel_units", "kilometres"],
53
+ # ["fuel_consumption_units", "litres"],
54
+ # ["ch4_emission_factor_units", "kilograms_per_litre"],
55
+ # ["n2o_emission_factor_units", "kilograms_per_litre"]].each do |pair|
56
+ # attribute = pair[0]
57
+ # proper_units = pair[1]
58
+ # verify "#{attribute.humanize} should be #{proper_units.humanize.downcase}" do
59
+ # AutomobileTypeFuelYear.all.each do |record|
60
+ # units = record.send(:"#{attribute}")
61
+ # unless units == proper_units
62
+ # raise "Invalid #{attribute.humanize.downcase} for AutomobileTypeFuelYear '#{record.name}': #{units} (should be #{proper_units})"
63
+ # end
64
+ # end
65
+ # end
66
+ # end
22
67
  end