earth 0.7.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. data/certification_changelog.markdown +21 -0
  2. data/lib/earth/air.rb +0 -2
  3. data/lib/earth/air/aircraft.rb +77 -27
  4. data/lib/earth/air/aircraft/data_miner.rb +12 -19
  5. data/lib/earth/air/aircraft_instance.rb +2 -0
  6. data/lib/earth/air/aircraft_instance_seat_class.rb +1 -0
  7. data/lib/earth/air/airport/data_miner.rb +1 -1
  8. data/lib/earth/air/data_miner.rb +0 -2
  9. data/lib/earth/air/flight_distance_class.rb +2 -3
  10. data/lib/earth/air/flight_distance_class/data_miner.rb +0 -13
  11. data/lib/earth/air/flight_distance_class_seat_class.rb +3 -2
  12. data/lib/earth/air/flight_seat_class.rb +0 -6
  13. data/lib/earth/air/flight_seat_class/data_miner.rb +0 -7
  14. data/lib/earth/air/flight_segment.rb +47 -53
  15. data/lib/earth/air/flight_segment/data_miner.rb +2 -2
  16. data/lib/earth/automobile.rb +4 -3
  17. data/lib/earth/automobile/automobile_fuel.rb +56 -119
  18. data/lib/earth/automobile/automobile_fuel/data_miner.rb +17 -4
  19. data/lib/earth/automobile/automobile_make.rb +1 -16
  20. data/lib/earth/automobile/automobile_make/data_miner.rb +25 -25
  21. data/lib/earth/automobile/automobile_make_model.rb +0 -26
  22. data/lib/earth/automobile/automobile_make_model/data_miner.rb +12 -13
  23. data/lib/earth/automobile/automobile_make_model_year.rb +6 -37
  24. data/lib/earth/automobile/automobile_make_model_year/data_miner.rb +34 -18
  25. data/lib/earth/automobile/automobile_make_model_year_variant.rb +27 -49
  26. data/lib/earth/automobile/automobile_make_model_year_variant/data_miner.rb +111 -140
  27. data/lib/earth/automobile/automobile_make_year.rb +0 -12
  28. data/lib/earth/automobile/automobile_make_year/data_miner.rb +22 -23
  29. data/lib/earth/automobile/automobile_make_year_fleet.rb +11 -0
  30. data/lib/earth/automobile/{automobile_make_fleet_year → automobile_make_year_fleet}/data_miner.rb +1 -2
  31. data/lib/earth/automobile/automobile_model.rb +5 -0
  32. data/lib/earth/automobile/automobile_model/data_miner.rb +19 -0
  33. data/lib/earth/automobile/automobile_size_class.rb +1 -0
  34. data/lib/earth/automobile/automobile_size_class/data_miner.rb +30 -4
  35. data/lib/earth/automobile/automobile_type_fuel_year.rb +1 -1
  36. data/lib/earth/automobile/automobile_type_fuel_year/data_miner.rb +30 -19
  37. data/lib/earth/automobile/automobile_type_fuel_year_age.rb +0 -3
  38. data/lib/earth/automobile/automobile_type_fuel_year_age/data_miner.rb +13 -15
  39. data/lib/earth/automobile/automobile_type_fuel_year_control.rb +0 -4
  40. data/lib/earth/automobile/automobile_type_fuel_year_control/data_miner.rb +0 -8
  41. data/lib/earth/automobile/automobile_type_year.rb +2 -1
  42. data/lib/earth/automobile/automobile_type_year/data_miner.rb +12 -10
  43. data/lib/earth/automobile/automobile_year.rb +5 -0
  44. data/lib/earth/automobile/automobile_year/data_miner.rb +15 -0
  45. data/lib/earth/automobile/data_miner.rb +5 -3
  46. data/lib/earth/automobile/dependencies.txt +45 -0
  47. data/lib/earth/bus/bus_class.rb +1 -87
  48. data/lib/earth/bus/bus_class/data_miner.rb +0 -1
  49. data/lib/earth/bus/bus_fuel/data_miner.rb +12 -19
  50. data/lib/earth/bus/bus_fuel_control/data_miner.rb +8 -12
  51. data/lib/earth/conversions_ext.rb +1 -0
  52. data/lib/earth/fuel/fuel/data_miner.rb +28 -38
  53. data/lib/earth/fuel/fuel_year/data_miner.rb +36 -47
  54. data/lib/earth/hospitality/lodging_class/data_miner.rb +12 -6
  55. data/lib/earth/locality.rb +1 -0
  56. data/lib/earth/locality/country.rb +1 -1
  57. data/lib/earth/locality/country/data_miner.rb +36 -28
  58. data/lib/earth/locality/data_miner.rb +1 -0
  59. data/lib/earth/locality/egrid_subregion/data_miner.rb +19 -14
  60. data/lib/earth/locality/urbanity/data_miner.rb +1 -3
  61. data/lib/earth/locality/zip_code/data_miner.rb +1 -1
  62. data/lib/earth/rail/national_transit_database_record/data_miner.rb +10 -14
  63. data/lib/earth/rail/rail_fuel.rb +2 -6
  64. data/lib/earth/residence/air_conditioner_use/data_miner.rb +1 -3
  65. data/lib/earth/residence/clothes_machine_use/data_miner.rb +1 -3
  66. data/lib/earth/residence/dishwasher_use/data_miner.rb +1 -3
  67. data/lib/earth/residence/residence_class/data_miner.rb +1 -3
  68. data/lib/earth/residence/residential_energy_consumption_survey_response/data_miner.rb +3 -1
  69. data/lib/earth/utils.rb +15 -5
  70. data/lib/earth/version.rb +1 -1
  71. data/spec/earth_spec.rb +4 -4
  72. metadata +9 -11
  73. data/features/automobile_type_fuel_age.feature +0 -55
  74. data/lib/earth/air/aircraft_class.rb +0 -59
  75. data/lib/earth/air/aircraft_class/data_miner.rb +0 -14
  76. data/lib/earth/air/aircraft_fuel_use_equation.rb +0 -33
  77. data/lib/earth/air/aircraft_fuel_use_equation/data_miner.rb +0 -13
  78. data/lib/earth/automobile/automobile_make_fleet_year.rb +0 -46
  79. data/lib/earth/automobile/automobile_type_fuel_age.rb +0 -65
  80. data/lib/earth/automobile/automobile_type_fuel_age/data_miner.rb +0 -149
@@ -1,22 +1,10 @@
1
1
  class AutomobileMakeYear < ActiveRecord::Base
2
2
  set_primary_key :name
3
3
 
4
- belongs_to :make, :class_name => 'AutomobileMake', :foreign_key => 'make_name'
5
- has_many :fleet_years, :class_name => 'AutomobileMakeFleetYear', :foreign_key => 'make_year_name'
6
-
7
4
  col :name
8
5
  col :make_name
9
6
  col :year, :type => :integer
10
7
  col :fuel_efficiency, :type => :float
11
8
  col :fuel_efficiency_units
12
9
  col :volume, :type => :integer # This will sometimes be null because not all make_years have CAFE data
13
-
14
- # FIXME TODO verify make_name and volume?
15
-
16
- # verify "Fuel efficiency should be greater than zero" do
17
- # if violator = first(:conditions => ['fuel_efficiency IS NULL OR fuel_efficiency <= 0'])
18
- # raise "Invalid fuel efficiency for AutomobileMakeYear #{record.name}: #{record.fuel_efficiency} (should be > 0)"
19
- # end
20
- # true
21
- # end
22
10
  end
@@ -4,9 +4,9 @@ AutomobileMakeYear.class_eval do
4
4
  delete_all
5
5
  end
6
6
 
7
- process "Ensure AutomobileMakeModelYearVariant and AutomobileMakeFleetYear are populated" do
7
+ process "Ensure AutomobileMakeModelYearVariant and AutomobileMakeYearFleet are populated" do
8
8
  AutomobileMakeModelYearVariant.run_data_miner!
9
- AutomobileMakeFleetYear.run_data_miner!
9
+ AutomobileMakeYearFleet.run_data_miner!
10
10
  end
11
11
 
12
12
  process "Derive manufacturer names and years from automobile make model year variants" do
@@ -14,36 +14,35 @@ AutomobileMakeYear.class_eval do
14
14
  :src => AutomobileMakeModelYearVariant,
15
15
  :dest => AutomobileMakeYear,
16
16
  :cols => {
17
- :make_year_name => :name,
17
+ [:make_name, :year] => :name,
18
18
  :make_name => :make_name,
19
19
  :year => :year
20
20
  }
21
- # :where => 'src.make_name IS NOT NULL AND LENGTH(src.make_name) > 0 AND src.year IS NOT NULL AND LENGTH(src.year) > 0'
22
21
  )
23
22
  end
24
23
 
25
- # FIXME TODO make this a method on AutomobileMakeYear?
26
- process "Calculate fuel efficiency from make fleet years for makes with CAFE data" do
27
- make_fleet_years = AutomobileMakeFleetYear.arel_table
28
- make_years = AutomobileMakeYear.arel_table
29
- conditional_relation = make_years[:name].eq(make_fleet_years[:make_year_name])
30
- relation = AutomobileMakeFleetYear.weighted_average_relation(:fuel_efficiency, :weighted_by => :volume).where(conditional_relation)
31
- update_all "fuel_efficiency = (#{relation.to_sql})"
24
+ process "Calculate fuel efficiency and sales volume from make year fleets for makes with CAFE data" do
25
+ make_years = arel_table
26
+ year_fleets = AutomobileMakeYearFleet.arel_table
27
+ conditional_relation = make_years[:make_name].eq(year_fleets[:make_name]).and(make_years[:year].eq(year_fleets[:year]))
28
+ fuel_efficiency_relation = AutomobileMakeYearFleet.weighted_average_relation(:fuel_efficiency, :weighted_by => :volume).where(conditional_relation)
29
+ volume_relation = year_fleets.project(year_fleets[:volume].sum).where(conditional_relation)
30
+ update_all(%{
31
+ fuel_efficiency = (#{fuel_efficiency_relation.to_sql}),
32
+ fuel_efficiency_units = 'kilometres_per_litre',
33
+ volume = (#{volume_relation.to_sql})
34
+ })
32
35
  end
33
36
 
34
37
  process "Calculate fuel effeciency from automobile make model year variants for makes without CAFE data" do
35
- update_all(
36
- %{fuel_efficiency = (SELECT AVG(automobile_make_model_year_variants.fuel_efficiency) FROM automobile_make_model_year_variants WHERE automobile_make_years.name = automobile_make_model_year_variants.make_year_name)},
37
- %{fuel_efficiency IS NULL}
38
- )
39
- end
40
-
41
- process "Calculate sales volume from automobile make fleet years for makes with CAFE data" do
42
- update_all %{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)}
43
- end
44
-
45
- process 'Set units' do
46
- update_all "fuel_efficiency_units = 'kilometres_per_litre'"
38
+ make_years = arel_table
39
+ variants = AutomobileMakeModelYearVariant.arel_table
40
+ conditional_relation = make_years[:make_name].eq(variants[:make_name]).and(make_years[:year].eq(variants[:year]))
41
+ relation = variants.project(variants[:fuel_efficiency].average).where(conditional_relation)
42
+ where(:fuel_efficiency => nil).update_all(%{
43
+ fuel_efficiency = (#{relation.to_sql}),
44
+ fuel_efficiency_units = 'kilometres_per_litre'
45
+ })
47
46
  end
48
47
  end
49
48
  end
@@ -0,0 +1,11 @@
1
+ class AutomobileMakeYearFleet < ActiveRecord::Base
2
+ set_primary_key :name
3
+
4
+ col :name
5
+ col :make_name
6
+ col :year, :type => :integer
7
+ col :fleet
8
+ col :fuel_efficiency, :type => :float
9
+ col :fuel_efficiency_units
10
+ col :volume, :type => :integer
11
+ end
@@ -1,11 +1,10 @@
1
- AutomobileMakeFleetYear.class_eval do
1
+ AutomobileMakeYearFleet.class_eval do
2
2
  data_miner do
3
3
  import "annual corporate average fuel economy data for domestic and imported vehicle fleets from the NHTSA",
4
4
  :url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdEdXWXB6dkVLWkowLXhYSFVUT01sS2c&hl=en&gid=0&output=csv',
5
5
  :errata => { 'url' => 'http://static.brighterplanet.com/science/data/transport/automobiles/make_fleet_years/errata.csv' },
6
6
  :select => lambda { |row| row['volume'].to_i > 0 } do
7
7
  key 'name', :synthesize => lambda { |row| [ row['manufacturer_name'], row['year_content'], row['fleet'][2,2] ].join ' ' }
8
- store 'make_year_name', :synthesize => lambda { |row| [ row['manufacturer_name'], row['year_content'] ].join ' ' }
9
8
  store 'make_name', :field_name => 'manufacturer_name'
10
9
  store 'year', :field_name => 'year_content'
11
10
  store 'fleet', :chars => 2..3 # zero-based
@@ -0,0 +1,5 @@
1
+ class AutomobileModel < ActiveRecord::Base
2
+ set_primary_key :name
3
+
4
+ col :name
5
+ end
@@ -0,0 +1,19 @@
1
+ AutomobileModel.class_eval do
2
+ data_miner do
3
+ process "Start from scratch" do
4
+ delete_all
5
+ end
6
+
7
+ process "Ensure AutomobileMakeModelYearVariant is populated" do
8
+ AutomobileMakeModelYearVariant.run_data_miner!
9
+ end
10
+
11
+ process "Derive model names from automobile make model year variants" do
12
+ ::Earth::Utils.insert_ignore(
13
+ :src => AutomobileMakeModelYearVariant,
14
+ :dest => AutomobileModel,
15
+ :cols => { :model_name => :name }
16
+ )
17
+ end
18
+ end
19
+ end
@@ -1,6 +1,7 @@
1
1
  class AutomobileSizeClass < ActiveRecord::Base
2
2
  set_primary_key :name
3
3
 
4
+ # FIXME TODO clean up size class in MakeModelYearVariant, derive size class for MakeModelYear, and calculate this from MakeModelYear
4
5
  falls_back_on :hybrid_fuel_efficiency_city_multiplier => 1.651, # https://brighterplanet.sifterapp.com/issue/667
5
6
  :hybrid_fuel_efficiency_highway_multiplier => 1.213,
6
7
  :conventional_fuel_efficiency_city_multiplier => 0.987,
@@ -1,6 +1,5 @@
1
1
  AutomobileSizeClass.class_eval do
2
2
  data_miner do
3
- # FIXME TODO pull this from AutomobileSizeClassYear
4
3
  import "a list of size classes and pre-calculated fuel efficiencies",
5
4
  :url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdHlRUE5IcWlrRENhN0EtUldPTy1rX1E&gid=0&output=csv' do
6
5
  key 'name'
@@ -9,17 +8,44 @@ AutomobileSizeClass.class_eval do
9
8
  store 'fuel_efficiency_highway', :units_field_name => 'fuel_efficiency_highway_units'
10
9
  end
11
10
 
11
+ # FIXME TODO derive everything from AutomobileSizeClassYear and AutomobileTypeFuelYearAge
12
+ # process "Start from scratch" do
13
+ # delete_all
14
+ # end
15
+ #
16
+ # process "Ensure AutomobileSizeClassYear is populated" do
17
+ # AutomobileSizeClassYear.run_data_miner!
18
+ # AutomobileTypeFuelYearAge.run_data_miner!
19
+ # end
20
+ #
21
+ # process "Derive size classes from AutomobileSizeClassYear" do
22
+ # ::Earth::Utils.insert_ignore(
23
+ # :src => AutomobileSizeClassYear,
24
+ # :dest => AutomobileSizeClass,
25
+ # :cols => {
26
+ # :size_class_name => :name,
27
+ # :type_name => :type_name,
28
+ # }
29
+ # )
30
+ # end
31
+ #
32
+ # process "somehow calculate fuel efficiency from size class year and type fuel year age" do
33
+ #
34
+ # end
35
+
12
36
  process "Ensure AutomobileTypeFuelYearAge is populated" do
13
37
  AutomobileTypeFuelYearAge.run_data_miner!
14
38
  end
15
39
 
16
40
  # FIXME TODO make this a method on AutomobileSizeClass?
17
41
  process "Calculate annual distance from AutomobileTypeFuelYearAge" do
42
+ classes = arel_table
18
43
  ages = AutomobileTypeFuelYearAge.arel_table
19
- classes = AutomobileSizeClass.arel_table
20
44
  conditional_relation = ages[:type_name].eq(classes[:type_name])
21
- update_all "annual_distance = (#{AutomobileTypeFuelYearAge.weighted_average_relation(:annual_distance, :weighted_by => :vehicles).where(conditional_relation).to_sql})"
22
- update_all "annual_distance_units = 'kilometres'"
45
+ update_all(%{
46
+ annual_distance = (#{AutomobileTypeFuelYearAge.weighted_average_relation(:annual_distance, :weighted_by => :vehicles).where(conditional_relation).to_sql}),
47
+ annual_distance_units = 'kilometres'
48
+ })
23
49
  end
24
50
 
25
51
  import "pre-calculated fuel efficiency multipliers",
@@ -1,7 +1,7 @@
1
1
  class AutomobileTypeFuelYear < ActiveRecord::Base
2
2
  set_primary_key :name
3
3
 
4
- has_many :year_controls, :class_name => 'AutomobileTypeFuelYearControl', :foreign_key => 'type_fuel_year_name'
4
+ # FIXME TODO keep this until fix AutomobileFuel import so that it doesn't call type_fuel_year.type_year
5
5
  belongs_to :type_year, :class_name => 'AutomobileTypeYear', :foreign_key => 'type_year_name'
6
6
 
7
7
  col :name
@@ -50,12 +50,10 @@ AutomobileTypeFuelYear.class_eval do
50
50
 
51
51
  process "Convert total travel from billion miles to kilometres" do
52
52
  conversion_factor = 1_000_000_000.miles.to(:kilometres)
53
- connection.execute %{
54
- UPDATE automobile_type_fuel_years
55
- SET total_travel = 1.0 * total_travel * #{conversion_factor},
56
- total_travel_units = 'kilometres'
57
- WHERE total_travel_units = 'billion_miles'
58
- }
53
+ where(:total_travel_units => 'billion_miles').update_all(%{
54
+ total_travel = 1.0 * total_travel * #{conversion_factor},
55
+ total_travel_units = 'kilometres'
56
+ })
59
57
  end
60
58
 
61
59
  import "fuel consumption derived from the 2010 EPA GHG Inventory",
@@ -74,19 +72,32 @@ AutomobileTypeFuelYear.class_eval do
74
72
  end
75
73
 
76
74
  process "Calculate CH4 and N2O emision factors from AutomobileTypeFuelYearControl and AutomobileTypeFuelControl" do
77
- AutomobileTypeFuelYear.all.each do |record|
78
- record.ch4_emission_factor = record.year_controls.map do |year_control|
79
- year_control.total_travel_percent.to_f * year_control.control.ch4_emission_factor
80
- end.sum * record.total_travel / record.fuel_consumption
81
-
82
- record.n2o_emission_factor = record.year_controls.map do |year_control|
83
- year_control.total_travel_percent.to_f * year_control.control.n2o_emission_factor
84
- end.sum * record.total_travel / record.fuel_consumption
85
-
86
- record.ch4_emission_factor_units = 'kilograms_per_litre'
87
- record.n2o_emission_factor_units = 'kilograms_per_litre'
88
-
89
- record.save!
75
+ # FIXME TODO tried to do this with arel but '*' method is not defined
76
+ # fuel_years = arel_table
77
+ # year_controls = AutomobileTypeFuelYearControl.arel_table
78
+ # controls = AutomobileTypeFuelControl.arel_table
79
+ # year_controls.project((year_controls[:total_travel_percent] * controls[:ch4_emission_factor]).sum)
80
+ # .join(controls)
81
+ # .on(year_controls[:type_name].eq(controls[:type_name])
82
+ # .and(year_controls[:fuel_common_name].eq(controls[:fuel_common_name]))
83
+ # .and(year_controls[:control_name].eq(controls[:control_name])))
84
+ %w{ ch4 n2o }.each do |gas|
85
+ emission_factor = %{
86
+ ( SELECT SUM(1.0 * t1.total_travel_percent * t2.#{gas}_emission_factor)
87
+ FROM #{AutomobileTypeFuelYearControl.quoted_table_name} AS t1
88
+ INNER JOIN #{AutomobileTypeFuelControl.quoted_table_name} AS t2
89
+ ON t1.type_name = t2.type_name
90
+ AND t1.fuel_common_name = t2.fuel_common_name
91
+ AND t1.control_name = t2.control_name
92
+ WHERE
93
+ t1.type_name = #{quoted_table_name}.type_name
94
+ AND t1.fuel_common_name = #{quoted_table_name}.fuel_common_name
95
+ AND t1.year = #{quoted_table_name}.year )
96
+ }
97
+ update_all(%{
98
+ #{gas}_emission_factor = 1.0 * #{emission_factor} * total_travel / fuel_consumption,
99
+ #{gas}_emission_factor_units = 'kilograms_per_litre'
100
+ })
90
101
  end
91
102
  end
92
103
  end
@@ -1,14 +1,11 @@
1
1
  class AutomobileTypeFuelYearAge < ActiveRecord::Base
2
2
  set_primary_key :name
3
3
 
4
- belongs_to :type_fuel_year, :class_name => 'AutomobileTypeFuelYear', :foreign_key => 'type_fuel_year_name'
5
-
6
4
  col :name
7
5
  col :type_name
8
6
  col :fuel_common_name
9
7
  col :year, :type => :integer
10
8
  col :age, :type => :integer
11
- col :type_fuel_year_name
12
9
  col :total_travel_percent, :type => :float
13
10
  col :annual_distance, :type => :float
14
11
  col :annual_distance_units
@@ -90,16 +90,10 @@ AutomobileTypeFuelYearAge.class_eval do
90
90
 
91
91
  process "Convert annual distance from miles to kilometres" do
92
92
  conversion_factor = 1.miles.to(:kilometres)
93
- connection.execute %{
94
- UPDATE automobile_type_fuel_year_ages
95
- SET annual_distance = 1.0 * annual_distance * #{conversion_factor},
96
- annual_distance_units = 'kilometres'
97
- WHERE annual_distance_units = 'miles'
98
- }
99
- end
100
-
101
- process "Derive type fuel year name for association with AutomobileTypeFuelYear" do
102
- update_all "type_fuel_year_name = type_name || ' ' || fuel_common_name || ' ' || year"
93
+ where(:annual_distance_units => 'miles').update_all(%{
94
+ annual_distance = 1.0 * annual_distance * #{conversion_factor},
95
+ annual_distance_units = 'kilometres'
96
+ })
103
97
  end
104
98
 
105
99
  process "Ensure AutomobileTypeFuelYear is populated" do
@@ -107,11 +101,15 @@ AutomobileTypeFuelYearAge.class_eval do
107
101
  end
108
102
 
109
103
  process "Calculate number of vehicles from total travel percent and AutomobileTypeFuelYear" do
110
- total_travel = "(SELECT t1.total_travel FROM #{AutomobileTypeFuelYear.quoted_table_name} AS t1 WHERE t1.name = #{quoted_table_name}.type_fuel_year_name)"
111
- update_all(
112
- %{vehicles = 1.0 * total_travel_percent * #{total_travel} / annual_distance},
113
- %{annual_distance > 0}
114
- )
104
+ total_travel = %{
105
+ SELECT t1.total_travel
106
+ FROM #{AutomobileTypeFuelYear.quoted_table_name} AS t1
107
+ WHERE
108
+ t1.type_name = #{quoted_table_name}.type_name
109
+ AND t1.fuel_common_name = #{quoted_table_name}.fuel_common_name
110
+ AND t1.year = #{quoted_table_name}.year
111
+ }
112
+ where("annual_distance > 0").update_all "vehicles = 1.0 * total_travel_percent * (#{total_travel}) / annual_distance"
115
113
  end
116
114
  end
117
115
  end
@@ -1,15 +1,11 @@
1
1
  class AutomobileTypeFuelYearControl < ActiveRecord::Base
2
2
  set_primary_key :name
3
3
 
4
- belongs_to :control, :class_name => 'AutomobileTypeFuelControl', :foreign_key => 'type_fuel_control_name'
5
-
6
4
  col :name
7
5
  col :type_name
8
6
  col :fuel_common_name
9
7
  col :year, :type => :integer
10
8
  col :control_name
11
- col :type_fuel_control_name
12
- col :type_fuel_year_name
13
9
  col :total_travel_percent, :type => :float
14
10
 
15
11
  # %w{ type_name fuel_common_name control_name type_fuel_control_name type_fuel_year_name }.each do |attribute|
@@ -9,13 +9,5 @@ AutomobileTypeFuelYearControl.class_eval do
9
9
  store 'control_name'
10
10
  store 'total_travel_percent'
11
11
  end
12
-
13
- process "Derive type fuel control name for association with AutomobileTypeFuelControl" do
14
- update_all "type_fuel_control_name = type_name || ' ' || fuel_common_name || ' ' || control_name"
15
- end
16
-
17
- process "Derive type fuel year name for association with AutomobileTypeFuelYear" do
18
- update_all "type_fuel_year_name = type_name || ' ' || fuel_common_name || ' ' || year"
19
- end
20
12
  end
21
13
  end
@@ -1,8 +1,9 @@
1
1
  class AutomobileTypeYear < ActiveRecord::Base
2
2
  set_primary_key :name
3
3
 
4
+ # FIXME TODO keep this until fix AutomobileFuel fallback hfc emission factor so that it doesn't call type_year.type_fuel_year
4
5
  has_many :type_fuel_years, :class_name => 'AutomobileTypeFuelYear', :foreign_key => 'type_year_name'
5
-
6
+
6
7
  col :name
7
8
  col :type_name
8
9
  col :year, :type => :integer
@@ -12,16 +12,18 @@ AutomobileTypeYear.class_eval do
12
12
  AutomobileTypeFuelYear.run_data_miner!
13
13
  end
14
14
 
15
- process "Set units" do
16
- update_all :hfc_emission_factor_units => 'kilograms_co2e_per_litre'
17
- end
18
-
19
15
  process "Calculate HFC emission factor from AutomobileTypeFuelYear" do
20
- total_fuel_consumption = "(SELECT SUM(src.fuel_consumption) FROM #{AutomobileTypeFuelYear.quoted_table_name} AS src WHERE src.type_year_name = #{quoted_table_name}.name)"
21
- update_all(
22
- %{hfc_emission_factor = 1.0 * hfc_emissions / #{total_fuel_consumption}},
23
- %{#{total_fuel_consumption} > 0}
24
- )
25
- end
16
+ total_fuel_consumption = %{
17
+ SELECT SUM(src.fuel_consumption)
18
+ FROM #{AutomobileTypeFuelYear.quoted_table_name} AS src
19
+ WHERE
20
+ src.type_name = #{quoted_table_name}.type_name
21
+ AND src.year = #{quoted_table_name}.year
22
+ }
23
+ where("(#{total_fuel_consumption}) > 0").update_all(%{
24
+ hfc_emission_factor = 1.0 * hfc_emissions / (#{total_fuel_consumption}),
25
+ hfc_emission_factor_units = 'kilograms_co2e_per_litre'
26
+ })
27
+ end
26
28
  end
27
29
  end
@@ -0,0 +1,5 @@
1
+ class AutomobileYear < ActiveRecord::Base
2
+ set_primary_key :year
3
+
4
+ col :year, :type => :integer
5
+ end
@@ -0,0 +1,15 @@
1
+ AutomobileYear.class_eval do
2
+ data_miner do
3
+ process "Ensure AutomobileMakeModelYearVariant is populated" do
4
+ AutomobileMakeModelYearVariant.run_data_miner!
5
+ end
6
+
7
+ process "Derive year names from automobile make model year variants" do
8
+ ::Earth::Utils.insert_ignore(
9
+ :src => AutomobileMakeModelYearVariant,
10
+ :dest => AutomobileYear,
11
+ :cols => { :year => :year }
12
+ )
13
+ end
14
+ end
15
+ end
@@ -1,16 +1,18 @@
1
1
  require 'earth/automobile/automobile_fuel/data_miner'
2
2
  require 'earth/automobile/automobile_make/data_miner'
3
- require 'earth/automobile/automobile_make_fleet_year/data_miner'
4
3
  require 'earth/automobile/automobile_make_year/data_miner'
4
+ require 'earth/automobile/automobile_make_year_fleet/data_miner'
5
5
  require 'earth/automobile/automobile_make_model/data_miner'
6
6
  require 'earth/automobile/automobile_make_model_year/data_miner'
7
+ require 'earth/automobile/automobile_make_model_year_variant/data_miner'
7
8
  require 'earth/automobile/automobile_size_class/data_miner'
8
9
  require 'earth/automobile/automobile_size_class_year/data_miner'
9
- require 'earth/automobile/automobile_make_model_year_variant/data_miner'
10
10
  require 'earth/automobile/automobile_type_year/data_miner'
11
- require 'earth/automobile/automobile_type_fuel_age/data_miner'
12
11
  require 'earth/automobile/automobile_type_fuel_control/data_miner'
13
12
  require 'earth/automobile/automobile_type_fuel_year/data_miner'
14
13
  require 'earth/automobile/automobile_type_fuel_year_age/data_miner'
15
14
  require 'earth/automobile/automobile_type_fuel_year_control/data_miner'
15
+ require 'earth/automobile/automobile_model/data_miner'
16
+ require 'earth/automobile/automobile_year/data_miner'
17
+
16
18
  require 'earth/fuel/data_miner'