earth 0.3.9 → 0.3.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/Gemfile +5 -0
  2. data/Gemfile.lock +58 -20
  3. data/features/automobile_fuel_type.feature +44 -0
  4. data/features/automobile_make.feature +24 -0
  5. data/features/automobile_make_fleet_year.feature +44 -0
  6. data/features/automobile_make_model.feature +24 -0
  7. data/features/automobile_make_model_year.feature +34 -0
  8. data/features/automobile_make_model_year_variant.feature +46 -0
  9. data/features/automobile_make_year.feature +44 -0
  10. data/features/automobile_size_class.feature +59 -0
  11. data/features/bus_class.feature +69 -0
  12. data/features/carrier.feature +64 -0
  13. data/features/carrier_mode.feature +74 -0
  14. data/features/egrid_region.feature +14 -0
  15. data/features/egrid_subregion.feature +36 -0
  16. data/features/rail_class.feature +64 -0
  17. data/features/shipment_mode.feature +34 -0
  18. data/features/support/env.rb +7 -0
  19. data/features/support/imports/automobile_fuel_type_bad.csv +3 -0
  20. data/features/support/imports/automobile_fuel_type_good.csv +3 -0
  21. data/features/support/imports/automobile_make_bad.csv +3 -0
  22. data/features/support/imports/automobile_make_fleet_year_bad.csv +3 -0
  23. data/features/support/imports/automobile_make_fleet_year_good.csv +3 -0
  24. data/features/support/imports/automobile_make_good.csv +3 -0
  25. data/features/support/imports/automobile_make_model_bad.csv +3 -0
  26. data/features/support/imports/automobile_make_model_good.csv +3 -0
  27. data/features/support/imports/automobile_make_model_year_bad.csv +3 -0
  28. data/features/support/imports/automobile_make_model_year_good.csv +3 -0
  29. data/features/support/imports/automobile_make_model_year_variant_bad.csv +3 -0
  30. data/features/support/imports/automobile_make_model_year_variant_good.csv +3 -0
  31. data/features/support/imports/automobile_make_year_bad.csv +3 -0
  32. data/features/support/imports/automobile_make_year_good.csv +3 -0
  33. data/features/support/imports/automobile_size_class_bad.csv +3 -0
  34. data/features/support/imports/automobile_size_class_good.csv +3 -0
  35. data/features/support/imports/bus_class_bad.csv +3 -0
  36. data/features/support/imports/bus_class_good.csv +3 -0
  37. data/features/support/imports/carrier_bad.csv +3 -0
  38. data/features/support/imports/carrier_good.csv +3 -0
  39. data/features/support/imports/carrier_mode_bad.csv +3 -0
  40. data/features/support/imports/carrier_mode_good.csv +3 -0
  41. data/features/support/imports/egrid_region_bad.csv +3 -0
  42. data/features/support/imports/egrid_region_good.csv +3 -0
  43. data/features/support/imports/egrid_subregion_bad.csv +3 -0
  44. data/features/support/imports/egrid_subregion_good.csv +3 -0
  45. data/features/support/imports/rail_class_bad.csv +3 -0
  46. data/features/support/imports/rail_class_good.csv +3 -0
  47. data/features/support/imports/shipment_mode_bad.csv +3 -0
  48. data/features/support/imports/shipment_mode_good.csv +3 -0
  49. data/lib/earth/automobile/automobile_fuel_type/data_miner.rb +35 -14
  50. data/lib/earth/automobile/automobile_make/data_miner.rb +24 -9
  51. data/lib/earth/automobile/automobile_make_fleet_year/data_miner.rb +32 -1
  52. data/lib/earth/automobile/automobile_make_model/data_miner.rb +27 -5
  53. data/lib/earth/automobile/automobile_make_model_year/data_miner.rb +35 -5
  54. data/lib/earth/automobile/automobile_make_model_year_variant/data_miner.rb +80 -39
  55. data/lib/earth/automobile/automobile_make_year/data_miner.rb +32 -1
  56. data/lib/earth/automobile/automobile_size_class/data_miner.rb +67 -4
  57. data/lib/earth/bus/bus_class/data_miner.rb +73 -0
  58. data/lib/earth/locality/egrid_region/data_miner.rb +8 -0
  59. data/lib/earth/locality/egrid_subregion/data_miner.rb +26 -0
  60. data/lib/earth/rail/rail_class/data_miner.rb +51 -0
  61. data/lib/earth/shipping/carrier/data_miner.rb +47 -8
  62. data/lib/earth/shipping/carrier_mode/data_miner.rb +57 -8
  63. data/lib/earth/shipping/shipment_mode/data_miner.rb +23 -4
  64. metadata +110 -98
@@ -40,6 +40,37 @@ AutomobileMakeYear.class_eval do
40
40
  UPDATE automobile_make_years SET automobile_make_years.volume = (SELECT SUM(automobile_make_fleet_years.volume) FROM automobile_make_fleet_years WHERE automobile_make_fleet_years.make_year_name = automobile_make_years.name)
41
41
  }
42
42
  end
43
+
44
+ verify "Year should be between 1978 and 2007" do
45
+ AutomobileMakeYear.all.each do |make_year|
46
+ unless make_year.year > 1977 and make_year.year < 2008
47
+ raise "Invalid year for AutomobileMakeYear #{make_year.name}: #{make_year.year} (should be between 1978 and 2007)"
48
+ end
49
+ end
50
+ end
51
+
52
+ verify "Fuel efficiency should be greater than zero" do
53
+ AutomobileMakeYear.all.each do |make_year|
54
+ unless make_year.fuel_efficiency > 0
55
+ raise "Invalid fuel efficiency for AutomobileMakeYear #{make_year.name}: #{make_year.fuel_efficiency} (should be > 0)"
56
+ end
57
+ end
58
+ end
59
+
60
+ verify "Fuel efficiency units should be kilometres per litre" do
61
+ AutomobileMakeYear.all.each do |make_year|
62
+ unless make_year.fuel_efficiency_units == "kilometres_per_litre"
63
+ raise "Invalid fuel efficiency units for AutomobileMakeYear #{make_year.name}: #{make_year.fuel_efficiency_units} (should be kilometres_per_litre)"
64
+ end
65
+ end
66
+ end
67
+
68
+ verify "Volume should be greater than zero" do
69
+ AutomobileMakeYear.all.each do |make_year|
70
+ unless make_year.volume > 0
71
+ raise "Invalid volume for AutomobileMakeYear #{make_year.name}: #{make_year.volume} (should be > 0)"
72
+ end
73
+ end
74
+ end
43
75
  end
44
76
  end
45
-
@@ -2,13 +2,13 @@ AutomobileSizeClass.class_eval do
2
2
  data_miner do
3
3
  schema Earth.database_options do
4
4
  string 'name'
5
+ string 'emblem'
6
+ float 'annual_distance'
7
+ string 'annual_distance_units'
5
8
  float 'fuel_efficiency_city'
6
9
  string 'fuel_efficiency_city_units'
7
10
  float 'fuel_efficiency_highway'
8
11
  string 'fuel_efficiency_highway_units'
9
- float 'annual_distance'
10
- string 'annual_distance_units'
11
- string 'emblem'
12
12
  float 'hybrid_fuel_efficiency_city_multiplier'
13
13
  float 'hybrid_fuel_efficiency_highway_multiplier'
14
14
  float 'conventional_fuel_efficiency_city_multiplier'
@@ -38,6 +38,69 @@ AutomobileSizeClass.class_eval do
38
38
  store 'conventional_fuel_efficiency_city_multiplier'
39
39
  store 'conventional_fuel_efficiency_highway_multiplier'
40
40
  end
41
+
42
+ verify "Annual distance should be greater than zero" do
43
+ AutomobileSizeClass.all.each do |size_class|
44
+ unless size_class.annual_distance > 0
45
+ raise "Invalid annual distance for AutomobileSizeClass #{size_class.name}: #{size_class.annual_distance} (should be > 0)"
46
+ end
47
+ end
48
+ end
49
+
50
+ verify "Annual distance units should be kilometres" do
51
+ AutomobileSizeClass.all.each do |size_class|
52
+ unless size_class.annual_distance_units == "kilometres"
53
+ raise "Invalid annual distance units for AutomobileSizeClass #{size_class.name}: #{size_class.annual_distance_units} (should be kilometres)"
54
+ end
55
+ end
56
+ end
57
+
58
+ verify "Fuel efficiencies should be greater than zero" do
59
+ AutomobileSizeClass.all.each do |size_class|
60
+ %w{ city highway }.each do |type|
61
+ fuel_efficiency = size_class.send(:"fuel_efficiency_#{type}")
62
+ unless fuel_efficiency > 0
63
+ raise "Invalid fuel efficiency #{type} for AutomobileSizeClass #{size_class.name}: #{fuel_efficiency} (should be > 0)"
64
+ end
65
+ end
66
+ end
67
+ end
68
+
69
+ verify "Fuel efficiency units should be kilometres per litre" do
70
+ AutomobileSizeClass.all.each do |size_class|
71
+ %w{ city highway }.each do |type|
72
+ units = size_class.send(:"fuel_efficiency_#{type}_units")
73
+ unless units == "kilometres_per_litre"
74
+ raise "Invalid fuel efficiency #{type} units for AutomobileSizeClass #{size_class.name}: #{units} (should be kilometres_per_litre)"
75
+ end
76
+ end
77
+ end
78
+ end
79
+
80
+ verify "Any fuel efficiency multipliers should be greater than zero" do
81
+ AutomobileSizeClass.all.each do |size_class|
82
+ %w{ hybrid conventional }.each do |hybridity|
83
+ %w{ city highway }.each do |type|
84
+ multiplier = size_class.send(:"#{hybridity}_fuel_efficiency_#{type}_multiplier")
85
+ if not multiplier.nil?
86
+ unless multiplier > 0
87
+ raise "Invalid #{hybridity} fuel efficiency #{type} multiplier for AutomobileSizeClass #{size_class.name}: #{multiplier} (should be > 0)"
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
94
+
95
+ verify "Fallback fuel efficiency multipliers should be greater than zero" do
96
+ %w{ hybrid conventional }.each do |hybridity|
97
+ %w{ city highway }.each do |type|
98
+ multiplier = AutomobileSizeClass.fallback.send(:"#{hybridity}_fuel_efficiency_#{type}_multiplier")
99
+ unless multiplier > 0
100
+ raise "Invalid AutomobileSizeClass fallback #{hybridity} fuel efficiency #{type} multiplier: #{multiplier} (should be > 0)"
101
+ end
102
+ end
103
+ end
104
+ end
41
105
  end
42
106
  end
43
-
@@ -25,5 +25,78 @@ BusClass.class_eval do
25
25
  store 'alternative_fuels_intensity', :units_field_name => 'alternative_fuels_intensity_units'
26
26
  store 'air_conditioning_emission_factor', :units_field_name => 'air_conditioning_emission_factor_units'
27
27
  end
28
+
29
+ verify "Distance, passengers, speed, and diesel intensity should be greater than zero" do
30
+ BusClass.all.each do |bus_class|
31
+ %w{ distance passengers speed diesel_intensity }.each do |attribute|
32
+ value = bus_class.send(:"#{attribute}")
33
+ unless value > 0
34
+ raise "Invalid #{attribute} for BusClass #{bus_class.name}: #{value} (should be > 0)"
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ verify "Alternative fuels intensity and air conditioning emission factor should be zero or more" do
41
+ BusClass.all.each do |bus_class|
42
+ %w{ alternative_fuels_intensity air_conditioning_emission_factor }.each do |attribute|
43
+ value = bus_class.send(:"#{attribute}")
44
+ unless value >= 0
45
+ raise "Invalid #{attribute} for BusClass #{bus_class.name}: #{value} (should be >= 0)"
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+ verify "Distance units should be kilometres" do
52
+ BusClass.all.each do |bus_class|
53
+ unless bus_class.distance_units == "kilometres"
54
+ raise "Invalid distance units for BusClass #{bus_class.name}: #{bus_class.distance_units} (should be kilometres)"
55
+ end
56
+ end
57
+ end
58
+
59
+ verify "Speed units should be kilometres per hour" do
60
+ BusClass.all.each do |bus_class|
61
+ unless bus_class.speed_units == "kilometres_per_hour"
62
+ raise "Invalid speed units for BusClass #{bus_class.name}: #{bus_class.speed_units} (should be kilometres_per_hour)"
63
+ end
64
+ end
65
+ end
66
+
67
+ verify "Diesel intensity and alternative fuel intensity units should be litres per kilometre" do
68
+ BusClass.all.each do |bus_class|
69
+ %w{ diesel_intensity alternative_fuels_intensity }.each do |attribute|
70
+ units = bus_class.send(:"#{attribute}_units")
71
+ unless units == "litres_per_kilometre"
72
+ raise "Invalid #{attribute}_units for BusClass #{bus_class.name}: #{units} (should be litres_per_kilometre)"
73
+ end
74
+ end
75
+ end
76
+ end
77
+
78
+ verify "Air conditioning emission factor units should be kilograms per kilometre" do
79
+ BusClass.all.each do |bus_class|
80
+ unless bus_class.air_conditioning_emission_factor_units == "kilograms_per_kilometre"
81
+ raise "Invalid air conditioning emission factor units for BusClass #{bus_class.name}: #{bus_class.air_conditioning_emission_factor_units} (should be kilograms_per_kilometre)"
82
+ end
83
+ end
84
+ end
85
+
86
+ verify "Fallbacks should satisfy same constraints as data" do
87
+ %w{ distance passengers speed diesel_intensity }.each do |attribute|
88
+ value = BusClass.fallback.send(:"#{attribute}")
89
+ unless value > 0
90
+ raise "Invalid BusClass fallback #{attribute}: #{value} (should be > 0)"
91
+ end
92
+ end
93
+
94
+ %w{ alternative_fuels_intensity air_conditioning_emission_factor }.each do |attribute|
95
+ value = BusClass.fallback.send(:"#{attribute}")
96
+ unless value >= 0
97
+ raise "Invalid BusClass fallback #{attribute}: #{value} (should be >= 0)"
98
+ end
99
+ end
100
+ end
28
101
  end
29
102
  end
@@ -31,5 +31,13 @@ EgridRegion.class_eval do
31
31
  key 'name'
32
32
  store 'loss_factor'
33
33
  end
34
+
35
+ verify "Loss factor should be greater than zero and less than one" do
36
+ EgridRegion.all.each do |region|
37
+ unless region.loss_factor > 0 and region.loss_factor < 1
38
+ raise "Invalid loss factor for EgridRegion #{region.name}: #{region.loss_factor} (should be > 0 and < 1)"
39
+ end
40
+ end
41
+ end
34
42
  end
35
43
  end
@@ -61,5 +61,31 @@ EgridSubregion.class_eval do
61
61
  store 'egrid_region_name'
62
62
  store 'electricity_emission_factor', :units_field_name => 'electricity_emission_factor_units'
63
63
  end
64
+
65
+ # FIXME TODO make this work
66
+ # verify "eGRID region name should appear in egrid_regions" do
67
+ # regions = EgridRegion.all.map { |region| region.name }
68
+ # EgridSubregion.all.each do |subregion|
69
+ # unless regions.includes? subregion.egrid_region_name
70
+ # raise "Invalid eGRID region name for EgridSubregion #{subregion.name}: #{subregion.egrid_region_name} (not found in egrid_regions)"
71
+ # end
72
+ # end
73
+ # end
74
+
75
+ verify "Electricity emission factor should be greater than zero" do
76
+ EgridSubregion.all.each do |subregion|
77
+ unless subregion.electricity_emission_factor > 0
78
+ raise "Invalid electricity emission factor for EgridSubregion #{subregion.name}: #{subregion.electricity_emission_factor} (should be > 0)"
79
+ end
80
+ end
81
+ end
82
+
83
+ verify "Electricity emission factor units should be kilograms per kilowatt hour" do
84
+ EgridSubregion.all.each do |subregion|
85
+ unless subregion.electricity_emission_factor_units == "kilograms_per_kilowatt_hour"
86
+ raise "Invalid electricity emission factor units for EgridSubregion #{subregion.name}: #{subregion.electricity_emission_factor_units} (should be kilograms_per_kilowatt_hour)"
87
+ end
88
+ end
89
+ end
64
90
  end
65
91
  end
@@ -28,5 +28,56 @@ RailClass.class_eval do
28
28
  store 'electricity_intensity', :units_field_name => 'electricity_intensity_units'
29
29
  store 'diesel_intensity', :units_field_name => 'diesel_intensity_units'
30
30
  end
31
+
32
+ verify "Passengers, distance, speed, and electricity intensity should be greater than zero" do
33
+ RailClass.all.each do |rail_class|
34
+ %w{ passengers distance speed electricity_intensity }.each do |attribute|
35
+ value = rail_class.send(:"#{attribute}")
36
+ unless value > 0
37
+ raise "Invalid #{attribute} for RailClass #{rail_class.name}: #{value} (should be > 0)"
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ verify "Distance units should be kilometres" do
44
+ RailClass.all.each do |rail_class|
45
+ unless rail_class.distance_units == "kilometres"
46
+ raise "Invalid distance units for RailClass #{rail_class.name}: #{rail_class.distance_units} (should be kilometres)"
47
+ end
48
+ end
49
+ end
50
+
51
+ verify "Speed units should be kilometres per hour" do
52
+ RailClass.all.each do |rail_class|
53
+ unless rail_class.speed_units == "kilometres_per_hour"
54
+ raise "Invalid speed units for RailClass #{rail_class.name}: #{rail_class.speed_units} (should be kilometres_per_hour)"
55
+ end
56
+ end
57
+ end
58
+
59
+ verify "Electricity intensity units should be kilowatt hours per kilometre" do
60
+ RailClass.all.each do |rail_class|
61
+ unless rail_class.electricity_intensity_units == "kilowatt_hours_per_kilometre"
62
+ raise "Invalid electricity intensity units for RailClass #{rail_class.name}: #{rail_class.electricity_intensity_units} (should be kilowatt_hours_per_kilometre)"
63
+ end
64
+ end
65
+ end
66
+
67
+ verify "Diesel intensity should be zero or more" do
68
+ RailClass.all.each do |rail_class|
69
+ unless rail_class.diesel_intensity >= 0
70
+ raise "Invalid diesel intensity for RailClass #{rail_class.name}: #{rail_class.diesel_intensity} (should be > 0)"
71
+ end
72
+ end
73
+ end
74
+
75
+ verify "Diesel intensity units should be litres per kilometre" do
76
+ RailClass.all.each do |rail_class|
77
+ unless rail_class.diesel_intensity_units == "litres_per_kilometre"
78
+ raise "Invalid distance units for RailClass #{rail_class.name}: #{rail_class.diesel_intensity_units} (should be litres_per_kilometre)"
79
+ end
80
+ end
81
+ end
31
82
  end
32
83
  end
@@ -33,13 +33,52 @@ Carrier.class_eval do
33
33
  # what about transport_emission_factor_units?
34
34
  # end
35
35
 
36
- # TODO: verification
37
- # all entries should have name
38
- # all entries should have package_volume
39
- # all entries should have route_inefficiency_factor
40
- # all entries should have transport_emission_factor > 0
41
- # all entries should have transport_emission_factor_units
42
- # all entries should have corporate_emission_factor > 0
43
- # all entries should have corporate_emission_factor_units
36
+ verify "Package volume should be greater than zero" do
37
+ Carrier.all.each do |carrier|
38
+ unless carrier.package_volume > 0
39
+ raise "Invalid package volume for Carrier #{carrier.name}: #{carrier.package_volume} (should be > 0)"
40
+ end
41
+ end
42
+ end
43
+
44
+ verify "Route inefficiency factor should be one or more" do
45
+ Carrier.all.each do |carrier|
46
+ unless carrier.route_inefficiency_factor >= 1.0
47
+ raise "Invalid route inefficiency factor for Carrier #{carrier.name}: #{carrier.route_inefficiency_factor} (should be >= 1.0)"
48
+ end
49
+ end
50
+ end
51
+
52
+ verify "Transport emission factor should be greater than zero" do
53
+ Carrier.all.each do |carrier|
54
+ unless carrier.transport_emission_factor > 0
55
+ raise "Invalid transport emission factor for Carrier #{carrier.name}: #{carrier.transport_emission_factor} (should be > 0)"
56
+ end
57
+ end
58
+ end
59
+
60
+ verify "Transport emission factor units should never be missing" do
61
+ Carrier.all.each do |carrier|
62
+ if carrier.transport_emission_factor_units.nil?
63
+ raise "Missing transport emission factor units for Carrier #{carrier.name}"
64
+ end
65
+ end
66
+ end
67
+
68
+ verify "Corporate emission factor should be greater than zero" do
69
+ Carrier.all.each do |carrier|
70
+ unless carrier.corporate_emission_factor > 0
71
+ raise "Invalid corporate emission factor for Carrier #{carrier.name}: #{carrier.corporate_emission_factor} (should be > 0)"
72
+ end
73
+ end
74
+ end
75
+
76
+ verify "Corporate emission factor units should never be missing" do
77
+ Carrier.all.each do |carrier|
78
+ if carrier.corporate_emission_factor_units.nil?
79
+ raise "Missing corporate emission factor units for Carrier #{carrier.name}"
80
+ end
81
+ end
82
+ end
44
83
  end
45
84
  end
@@ -22,13 +22,62 @@ CarrierMode.class_eval do
22
22
  store 'transport_emission_factor', :units_field_name => 'transport_emission_factor_units'
23
23
  end
24
24
 
25
- # TODO: verification
26
- # all entries should have carrier_name
27
- # all entries should have mode_name
28
- # all entries should have include_in_fallbacks
29
- # all entries should have package_volume
30
- # all entries should have route_inefficiency_factor
31
- # all entries should have transport emission factor > 0
32
- # all entries should have transport emission factor units
25
+ # Don't need to check that carrier_name appears in carriers b/c carriers is derived from carrier_modes.carrier_name
26
+ verify "Carrier name should never be missing" do
27
+ CarrierMode.all.each do |carrier_mode|
28
+ if carrier_mode.carrier_name.nil?
29
+ raise "Missing carrier name for CarrierMode #{carrier_mode.name}"
30
+ end
31
+ end
32
+ end
33
+
34
+ # Don't need to check that mode_name appears in shipment_modes b/c shipment_modes is derived from carrier_modes.mode_name
35
+ verify "Mode name should never be missing" do
36
+ CarrierMode.all.each do |carrier_mode|
37
+ if carrier_mode.mode_name.nil?
38
+ raise "Missing mode name for CarrierMode #{carrier_mode.name}"
39
+ end
40
+ end
41
+ end
42
+
43
+ verify "Include in fallbacks should never be missing" do
44
+ CarrierMode.all.each do |carrier_mode|
45
+ if carrier_mode.include_in_fallbacks.nil?
46
+ raise "Missing include in fallbacks for CarrierMode #{carrier_mode.name}"
47
+ end
48
+ end
49
+ end
50
+
51
+ verify "Package volume should be greater than zero" do
52
+ CarrierMode.all.each do |carrier_mode|
53
+ unless carrier_mode.package_volume > 0
54
+ raise "Invalid package volume for CarrierMode #{carrier_mode.name}: #{carrier_mode.package_volume} (should be > 0)"
55
+ end
56
+ end
57
+ end
58
+
59
+ verify "Route inefficiency factor should be one or more" do
60
+ CarrierMode.all.each do |carrier_mode|
61
+ unless carrier_mode.route_inefficiency_factor >= 1.0
62
+ raise "Invalid route inefficiency factor for CarrierMode #{carrier_mode.name}: #{carrier_mode.route_inefficiency_factor} (should be >= 1.0)"
63
+ end
64
+ end
65
+ end
66
+
67
+ verify "Transport emission factor should be greater than zero" do
68
+ CarrierMode.all.each do |carrier_mode|
69
+ unless carrier_mode.transport_emission_factor > 0
70
+ raise "Invalid transport emission factor for CarrierMode #{carrier_mode.name}: #{carrier_mode.transport_emission_factor} (should be > 0)"
71
+ end
72
+ end
73
+ end
74
+
75
+ verify "Transport emission factor units should never be missing" do
76
+ CarrierMode.all.each do |carrier_mode|
77
+ if carrier_mode.transport_emission_factor_units.nil?
78
+ raise "Missing transport emission factor units for CarrierMode #{carrier_mode.name}"
79
+ end
80
+ end
81
+ end
33
82
  end
34
83
  end
@@ -26,9 +26,28 @@ ShipmentMode.class_eval do
26
26
  # what about transport_emission_factor_units?
27
27
  # end
28
28
 
29
- # TODO: verification
30
- # all entries should have route_inefficiency_factor >= 1
31
- # all entries should have transport_emission_factor > 0
32
- # all entries should have transport_emission_factor_units
29
+ verify "Route inefficiency factor should be one or more" do
30
+ ShipmentMode.all.each do |mode|
31
+ unless mode.route_inefficiency_factor >= 1.0
32
+ raise "Invalid route inefficiency factor for ShipmentMode #{mode.name}: #{mode.route_inefficiency_factor} (should be >= 1.0)"
33
+ end
34
+ end
35
+ end
36
+
37
+ verify "Transport emission factor should be greater than zero" do
38
+ ShipmentMode.all.each do |mode|
39
+ unless mode.transport_emission_factor > 0
40
+ raise "Invalid transport emission factor for ShipmentMode #{mode.name}: #{mode.transport_emission_factor} (should be > 0)"
41
+ end
42
+ end
43
+ end
44
+
45
+ verify "Transport emission factor units should never be missing" do
46
+ ShipmentMode.all.each do |mode|
47
+ if mode.transport_emission_factor_units.nil?
48
+ raise "Missing transport emission factor units for ShipmentMode #{mode.name}"
49
+ end
50
+ end
51
+ end
33
52
  end
34
53
  end