earth 0.12.0 → 0.12.1

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 (59) hide show
  1. data/bin/earth_tester.rb +1 -0
  2. data/data/automobile/annual_emission_controls.csv +1 -1
  3. data/data/automobile/annual_fuel_consumption.csv +1 -1
  4. data/data/automobile/auto_fuel_data.csv +1 -1
  5. data/data/automobile/emission_control_techs.csv +1 -1
  6. data/data/automobile/trip_distances.csv +5 -0
  7. data/data/locality/country_flight_data.csv +18 -0
  8. data/data/locality/egrid_relationships.csv +27 -0
  9. data/data/locality/misc_zip_data.csv +1 -0
  10. data/data/locality/us_auto_data.csv +2 -0
  11. data/data/locality/wri_hdd_cdd_data.csv +174 -0
  12. data/data/locality/zip_climate_divisions.csv +41359 -0
  13. data/errata/country/wri_errata.csv +24 -24
  14. data/lib/earth/automobile/automobile_activity_year/data_miner.rb +4 -3
  15. data/lib/earth/automobile/automobile_activity_year_type/data_miner.rb +4 -3
  16. data/lib/earth/automobile/automobile_activity_year_type_fuel.rb +1 -1
  17. data/lib/earth/automobile/automobile_activity_year_type_fuel/data_miner.rb +4 -4
  18. data/lib/earth/automobile/automobile_fuel.rb +5 -5
  19. data/lib/earth/automobile/automobile_fuel/data_miner.rb +18 -13
  20. data/lib/earth/automobile/automobile_make/data_miner.rb +4 -3
  21. data/lib/earth/automobile/automobile_make_model/data_miner.rb +6 -7
  22. data/lib/earth/automobile/automobile_make_model_year/data_miner.rb +1 -2
  23. data/lib/earth/automobile/automobile_make_model_year_variant/data_miner.rb +5 -10
  24. data/lib/earth/automobile/automobile_type_fuel.rb +2 -2
  25. data/lib/earth/automobile/automobile_type_fuel/data_miner.rb +8 -7
  26. data/lib/earth/automobile/automobile_type_fuel_control.rb +1 -1
  27. data/lib/earth/automobile/automobile_type_fuel_control/data_miner.rb +1 -1
  28. data/lib/earth/automobile/automobile_type_fuel_year.rb +5 -5
  29. data/lib/earth/automobile/automobile_type_fuel_year/data_miner.rb +7 -6
  30. data/lib/earth/automobile/automobile_type_fuel_year_control.rb +4 -4
  31. data/lib/earth/automobile/automobile_type_fuel_year_control/data_miner.rb +2 -2
  32. data/lib/earth/conversions_ext.rb +2 -0
  33. data/lib/earth/industry/industry.rb +0 -2
  34. data/lib/earth/industry/industry/data_miner.rb +5 -2
  35. data/lib/earth/locality/census_division.rb +2 -1
  36. data/lib/earth/locality/country.rb +3 -7
  37. data/lib/earth/locality/country/data_miner.rb +54 -75
  38. data/lib/earth/locality/egrid_country.rb +9 -3
  39. data/lib/earth/locality/egrid_country/data_miner.rb +14 -8
  40. data/lib/earth/locality/egrid_region.rb +15 -6
  41. data/lib/earth/locality/egrid_region/data_miner.rb +14 -18
  42. data/lib/earth/locality/egrid_subregion.rb +21 -19
  43. data/lib/earth/locality/egrid_subregion/data_miner.rb +27 -47
  44. data/lib/earth/locality/zip_code.rb +5 -4
  45. data/lib/earth/locality/zip_code/data_miner.rb +25 -14
  46. data/lib/earth/rail/rail_company/data_miner.rb +1 -1
  47. data/lib/earth/version.rb +1 -1
  48. data/spec/earth/automobile/automobile_activity_year_type_fuel_spec.rb +1 -1
  49. data/spec/earth/automobile/automobile_fuel_spec.rb +1 -1
  50. data/spec/earth/automobile/automobile_type_fuel_spec.rb +1 -1
  51. data/spec/earth/automobile/automobile_type_fuel_year_control_spec.rb +6 -6
  52. data/spec/earth/automobile/automobile_type_fuel_year_spec.rb +6 -6
  53. data/spec/earth/industry/industry_spec.rb +1 -3
  54. data/spec/earth/locality/country_spec.rb +67 -34
  55. data/spec/earth/locality/egrid_country_spec.rb +26 -0
  56. data/spec/earth/locality/egrid_region_spec.rb +27 -0
  57. data/spec/earth/locality/egrid_subregion_spec.rb +49 -0
  58. data/spec/earth/locality/zip_code_spec.rb +13 -24
  59. metadata +17 -4
@@ -1,25 +1,25 @@
1
1
  date,name,email,type,section,action,x,y,condition,notes
2
- 1/25/2012,Ian Hough,ian@brighterplanet.com,meta,Intended use,,Country degree days import
3
- 1/25/2012,Ian Hough,ian@brighterplanet.com,technical,country,replace,Bolivia,"Bolivia, Plurinational State of",,match iso country names
4
- 1/25/2012,Ian Hough,ian@brighterplanet.com,technical,country,replace,Bosnia & Herzegovina,Bosnia and Herzegovina,,match iso country names
5
- 1/25/2012,Ian Hough,ian@brighterplanet.com,technical,country,replace,Brunei*,Brunei Darussalam,,match iso country names
6
- 1/25/2012,Ian Hough,ian@brighterplanet.com,technical,country,replace,"Congo, Dem. Republic","Congo, The Democratic Republic of the",,match iso country names
7
- 3/15/2012,Ian Hough,ian@brighterplanet.com,technical,country,replace,Cote d'Ivoire,Côte d'Ivoire,,be sure to include utf8 chars
8
- 1/25/2012,Ian Hough,ian@brighterplanet.com,technical,country,replace,Iran,"Iran, Islamic Republic of",,match iso country names
9
- 1/25/2012,Ian Hough,ian@brighterplanet.com,technical,country,replace,Iraq*,Iraq,,match iso country names
10
- 1/25/2012,Ian Hough,ian@brighterplanet.com,technical,country,replace,Korea (North),"Korea, Democratic People's Republic of ",,match iso country names
11
- 1/25/2012,Ian Hough,ian@brighterplanet.com,technical,country,replace,Korea (South),"Korea, Republic of ",,match iso country names
12
- 1/25/2012,Ian Hough,ian@brighterplanet.com,technical,country,replace,Laos,Lao People's Democratic Republic,,match iso country names
13
- 1/25/2012,Ian Hough,ian@brighterplanet.com,technical,country,replace,Libya,Libyan Arab Jamahiriya,,match iso country names
14
- 1/25/2012,Ian Hough,ian@brighterplanet.com,technical,country,replace,"Macedonia, FYR","Macedonia, The Former Yugoslav Republic of",,match iso country names
15
- 1/25/2012,Ian Hough,ian@brighterplanet.com,technical,country,replace,Moldova,"Moldova, Republic of",,match iso country names
16
- 1/25/2012,Ian Hough,ian@brighterplanet.com,technical,country,replace,Saint Kitts & Nevis,Saint Kitts and Nevis,,match iso country names
17
- 1/25/2012,Ian Hough,ian@brighterplanet.com,technical,country,replace,Sao Tome & Principe,Sao Tome and Principe,,match iso country names
18
- 1/25/2012,Ian Hough,ian@brighterplanet.com,technical,country,replace,Serbia & Montenegro,Serbia,,match iso country names
19
- 1/25/2012,Ian Hough,ian@brighterplanet.com,technical,country,replace,Syria,Syrian Arab Republic,,match iso country names
20
- 1/25/2012,Ian Hough,ian@brighterplanet.com,technical,country,replace,Taiwan*,"Taiwan, Province of China",,match iso country names
21
- 1/25/2012,Ian Hough,ian@brighterplanet.com,technical,country,replace,Tanzania,"Tanzania, United Republic of",,match iso country names
22
- 1/25/2012,Ian Hough,ian@brighterplanet.com,technical,country,replace,Trinidad & Tobago,Trinidad and Tobago,,match iso country names
23
- 1/25/2012,Ian Hough,ian@brighterplanet.com,technical,country,replace,United States of America,United States,,match iso country names
24
- 1/25/2012,Ian Hough,ian@brighterplanet.com,technical,country,replace,Venezuela,"Venezuela, Bolivarian Republic of",,match iso country names
25
- 1/25/2012,Ian Hough,ian@brighterplanet.com,technical,country,replace,Vietnam,Viet Nam,,match iso country names
2
+ 1/25/12,Ian Hough,ian@brighterplanet.com,meta,Intended use,,Country degree days import,,,
3
+ 1/25/12,Ian Hough,ian@brighterplanet.com,technical,country,replace,Bolivia,"Bolivia, Plurinational State of",,match iso country names
4
+ 1/25/12,Ian Hough,ian@brighterplanet.com,technical,country,replace,Bosnia & Herzegovina,Bosnia and Herzegovina,,match iso country names
5
+ 1/25/12,Ian Hough,ian@brighterplanet.com,technical,country,replace,Brunei*,Brunei Darussalam,,match iso country names
6
+ 1/25/12,Ian Hough,ian@brighterplanet.com,technical,country,replace,"Congo, Dem. Republic","Congo, The Democratic Republic of the",,match iso country names
7
+ 3/15/12,Ian Hough,ian@brighterplanet.com,technical,country,replace,Cote d'Ivoire,Côte d'Ivoire,,be sure to include utf8 chars
8
+ 1/25/12,Ian Hough,ian@brighterplanet.com,technical,country,replace,Iran,"Iran, Islamic Republic of",,match iso country names
9
+ 1/25/12,Ian Hough,ian@brighterplanet.com,technical,country,replace,Iraq*,Iraq,,match iso country names
10
+ 1/25/12,Ian Hough,ian@brighterplanet.com,technical,country,replace,Korea (North),"Korea, Democratic People's Republic of ",,match iso country names
11
+ 1/25/12,Ian Hough,ian@brighterplanet.com,technical,country,replace,Korea (South),"Korea, Republic of ",,match iso country names
12
+ 1/25/12,Ian Hough,ian@brighterplanet.com,technical,country,replace,Laos,Lao People's Democratic Republic,,match iso country names
13
+ 1/25/12,Ian Hough,ian@brighterplanet.com,technical,country,replace,Libya,Libyan Arab Jamahiriya,,match iso country names
14
+ 1/25/12,Ian Hough,ian@brighterplanet.com,technical,country,replace,"Macedonia, FYR","Macedonia, The Former Yugoslav Republic of",,match iso country names
15
+ 1/25/12,Ian Hough,ian@brighterplanet.com,technical,country,replace,Moldova,"Moldova, Republic of",,match iso country names
16
+ 1/25/12,Ian Hough,ian@brighterplanet.com,technical,country,replace,Saint Kitts & Nevis,Saint Kitts and Nevis,,match iso country names
17
+ 1/25/12,Ian Hough,ian@brighterplanet.com,technical,country,replace,Sao Tome & Principe,Sao Tome and Principe,,match iso country names
18
+ 1/25/12,Ian Hough,ian@brighterplanet.com,technical,country,replace,Serbia & Montenegro,Serbia,,match iso country names
19
+ 1/25/12,Ian Hough,ian@brighterplanet.com,technical,country,replace,Syria,Syrian Arab Republic,,match iso country names
20
+ 1/25/12,Ian Hough,ian@brighterplanet.com,technical,country,replace,Taiwan*,"Taiwan, Province of China",,match iso country names
21
+ 1/25/12,Ian Hough,ian@brighterplanet.com,technical,country,replace,Tanzania,"Tanzania, United Republic of",,match iso country names
22
+ 1/25/12,Ian Hough,ian@brighterplanet.com,technical,country,replace,Trinidad & Tobago,Trinidad and Tobago,,match iso country names
23
+ 1/25/12,Ian Hough,ian@brighterplanet.com,technical,country,replace,United States of America,United States,,match iso country names
24
+ 1/25/12,Ian Hough,ian@brighterplanet.com,technical,country,replace,Venezuela,"Venezuela, Bolivarian Republic of",,match iso country names
25
+ 1/25/12,Ian Hough,ian@brighterplanet.com,technical,country,replace,Vietnam,Viet Nam,,match iso country names
@@ -18,9 +18,10 @@ AutomobileActivityYear.class_eval do
18
18
 
19
19
  process "Derive hfc emission factor from AutomobileActivityYearType" do
20
20
  find_each do |ay|
21
- ay.hfc_emission_factor = ay.activity_year_types.sum(&:hfc_emissions) / ay.activity_year_types.sum{ |ayt| ayt.activity_year_type_fuels.sum(&:distance) }
22
- ay.hfc_emission_factor_units = ay.activity_year_types.first.hfc_emission_factor_units
23
- ay.save!
21
+ ay.update_attributes!(
22
+ :hfc_emission_factor => ay.activity_year_types.sum(&:hfc_emissions) / ay.activity_year_types.sum{ |ayt| ayt.activity_year_type_fuels.sum(&:distance) },
23
+ :hfc_emission_factor_units => ay.activity_year_types.first.hfc_emission_factor_units
24
+ )
24
25
  end
25
26
  end
26
27
  end
@@ -18,9 +18,10 @@ AutomobileActivityYearType.class_eval do
18
18
 
19
19
  process "Derive hfc emission factor from AutomobileActivityYearTypeFuel" do
20
20
  find_each do |ayt|
21
- ayt.hfc_emission_factor = ayt.hfc_emissions / ayt.activity_year_type_fuels.sum(:distance)
22
- ayt.hfc_emission_factor_units = ayt.hfc_emissions_units + '_per_' + ayt.activity_year_type_fuels.first.distance_units.singularize
23
- ayt.save!
21
+ ayt.update_attributes!(
22
+ :hfc_emission_factor => ayt.hfc_emissions / ayt.activity_year_type_fuels.sum(:distance),
23
+ :hfc_emission_factor_units => ayt.hfc_emissions_units + '_per_' + ayt.activity_year_type_fuels.first.distance_units.singularize
24
+ )
24
25
  end
25
26
  end
26
27
  end
@@ -9,7 +9,7 @@ class AutomobileActivityYearTypeFuel < ActiveRecord::Base
9
9
  col :name
10
10
  col :activity_year, :type => :integer
11
11
  col :type_name
12
- col :fuel_common_name
12
+ col :fuel_group
13
13
  col :distance, :type => :float
14
14
  col :distance_units
15
15
  col :fuel_consumption, :type => :float
@@ -14,7 +14,7 @@ AutomobileActivityYearTypeFuel.class_eval do
14
14
  key 'name', :synthesize => proc { |row| "#{row['Year']} #{type} gasoline" }
15
15
  store 'activity_year', :field_name => 'Year'
16
16
  store 'type_name', :static => type
17
- store 'fuel_common_name', :static => 'gasoline'
17
+ store 'fuel_group', :static => 'gasoline'
18
18
  store 'distance', :field_name => type, :from_units => :billion_miles, :to_units => :kilometres
19
19
  end
20
20
 
@@ -27,7 +27,7 @@ AutomobileActivityYearTypeFuel.class_eval do
27
27
  key 'name', :synthesize => proc { |row| "#{row['Year']} #{type} diesel" }
28
28
  store 'activity_year', :field_name => 'Year'
29
29
  store 'type_name', :static => type
30
- store 'fuel_common_name', :static => 'diesel'
30
+ store 'fuel_group', :static => 'diesel'
31
31
  store 'distance', :field_name => type, :from_units => :billion_miles, :to_units => :kilometres
32
32
  end
33
33
 
@@ -40,7 +40,7 @@ AutomobileActivityYearTypeFuel.class_eval do
40
40
  key 'name', :synthesize => proc { |row| "#{row['Year']} #{type} alternative" }
41
41
  store 'activity_year', :field_name => 'Year'
42
42
  store 'type_name', :static => type
43
- store 'fuel_common_name', :static => 'alternative'
43
+ store 'fuel_group', :static => 'alternative'
44
44
  store 'distance', :field_name => type, :from_units => :billion_miles, :to_units => :kilometres
45
45
  end
46
46
  end
@@ -50,7 +50,7 @@ AutomobileActivityYearTypeFuel.class_eval do
50
50
  key 'name'
51
51
  store 'activity_year'
52
52
  store 'type_name'
53
- store 'fuel_common_name'
53
+ store 'fuel_group'
54
54
  store 'fuel_consumption', :from_units => :million_gallons, :to_units => :litres
55
55
  end
56
56
  end
@@ -8,16 +8,16 @@ class AutomobileFuel < ActiveRecord::Base
8
8
  belongs_to :blend_fuel, :class_name => 'Fuel', :foreign_key => 'blend_fuel_name'
9
9
 
10
10
  # for calculating gas and diesel annual distance and ch4 + n2o efs
11
- has_many :type_fuels, :foreign_key => :fuel_common_name, :primary_key => :common_name, :class_name => 'AutomobileTypeFuel'
11
+ has_many :type_fuels, :foreign_key => :fuel_group, :primary_key => :group, :class_name => 'AutomobileTypeFuel'
12
12
 
13
13
  # for fallback
14
14
  class << self
15
15
  def diesel
16
- AutomobileFuel.find 'diesel'
16
+ find 'diesel'
17
17
  end
18
18
 
19
19
  def gasoline
20
- AutomobileFuel.find 'gasoline'
20
+ find 'gasoline'
21
21
  end
22
22
 
23
23
  def fallback_blend_portion
@@ -68,7 +68,7 @@ class AutomobileFuel < ActiveRecord::Base
68
68
 
69
69
  col :name
70
70
  col :code
71
- col :common_name
71
+ col :group
72
72
  col :distance_key
73
73
  col :base_fuel_name
74
74
  col :blend_fuel_name
@@ -89,7 +89,7 @@ class AutomobileFuel < ActiveRecord::Base
89
89
  col :total_consumption_units
90
90
 
91
91
  warn_unless_size 12
92
- warn_if_blanks :code, :common_name, :distance_key
92
+ warn_if_blanks :code, :group, :distance_key
93
93
  warn_if do
94
94
  if exists?("name != 'electricity' AND base_fuel_name IS NULL")
95
95
  "Records missing #{col}"
@@ -10,7 +10,7 @@ AutomobileFuel.class_eval do
10
10
  :url => "file://#{Earth::DATA_DIR}/automobile/auto_fuel_data.csv" do
11
11
  key 'name'
12
12
  store 'code'
13
- store 'common_name'
13
+ store 'group'
14
14
  store 'distance_key'
15
15
  store 'base_fuel_name', :nullify => true
16
16
  store 'blend_fuel_name', :nullify => true
@@ -22,10 +22,10 @@ AutomobileFuel.class_eval do
22
22
  end
23
23
 
24
24
  process "Derive energy content and co2 emission factors from Fuel" do
25
- elec = AutomobileFuel.find 'electricity'
26
- elec.energy_content = 1.kilowatt_hours.to(:megajoules)
27
- elec.energy_content_units = 'megajoules_per_kilowatt_hour'
28
- elec.save!
25
+ AutomobileFuel.find('electricity').update_attributes!(
26
+ :energy_content => 1.kilowatt_hours.to(:megajoules),
27
+ :energy_content_units => 'megajoules_per_kilowatt_hour'
28
+ )
29
29
 
30
30
  where("name != 'electricity'").each do |auto_fuel|
31
31
  %w{ energy_content co2_emission_factor co2_biogenic_emission_factor }.each do |method|
@@ -34,10 +34,12 @@ AutomobileFuel.class_eval do
34
34
  else
35
35
  auto_fuel.base_fuel.send method
36
36
  end
37
- auto_fuel.send("#{method}=", value)
38
- auto_fuel.send("#{method}_units=", auto_fuel.base_fuel.send("#{method}_units"))
37
+
38
+ auto_fuel.update_attributes!(
39
+ :"#{method}" => value,
40
+ :"#{method}_units" => auto_fuel.base_fuel.send("#{method}_units")
41
+ )
39
42
  end
40
- auto_fuel.save!
41
43
  end
42
44
  end
43
45
 
@@ -56,14 +58,17 @@ AutomobileFuel.class_eval do
56
58
  find_each do |record|
57
59
  if (type_fuels = record.type_fuels).any?
58
60
  %w{ annual_distance ch4_emission_factor n2o_emission_factor }.each do |item|
59
- record.send("#{item}=", type_fuels.weighted_average(item, :weighted_by => :vehicles))
60
- record.send("#{item}_units=", type_fuels.first.send("#{item}_units"))
61
+ record.update_attributes!(
62
+ :"#{item}" => type_fuels.weighted_average(item, :weighted_by => :vehicles),
63
+ :"#{item}_units" => type_fuels.first.send("#{item}_units")
64
+ )
61
65
  end
62
66
  unless record.name =~ / gasoline/
63
- record.total_consumption = record.type_fuels.sum(:fuel_consumption)
64
- record.total_consumption_units = record.type_fuels.first.fuel_consumption_units
67
+ record.update_attributes!(
68
+ :total_consumption => record.type_fuels.sum(:fuel_consumption),
69
+ :total_consumption_units => record.type_fuels.first.fuel_consumption_units
70
+ )
65
71
  end
66
- record.save!
67
72
  end
68
73
  end
69
74
  end
@@ -18,9 +18,10 @@ AutomobileMake.class_eval do
18
18
 
19
19
  process "Derive fuel efficiency from AutomobileMakeYear" do
20
20
  find_each do |make|
21
- make.fuel_efficiency = make.make_years.weighted_average(:fuel_efficiency)
22
- make.fuel_efficiency_units = make.make_years.first.fuel_efficiency_units
23
- make.save!
21
+ make.update_attributes!(
22
+ :fuel_efficiency => make.make_years.weighted_average(:fuel_efficiency),
23
+ :fuel_efficiency_units => make.make_years.first.fuel_efficiency_units
24
+ )
24
25
  end
25
26
  end
26
27
  end
@@ -25,18 +25,17 @@ AutomobileMakeModel.class_eval do
25
25
  find_each do |amm|
26
26
  codes = amm.model_years.map(&:fuel_code).uniq
27
27
  if codes.count == 1
28
- amm.fuel_code = codes.first
28
+ amm.update_attributes! :fuel_code => codes.first
29
29
  elsif codes.all?{ |code| ['R', 'P', 'G'].include? code }
30
- amm.fuel_code = 'G'
30
+ amm.update_attributes! :fuel_code => 'G'
31
31
  end
32
32
 
33
33
  alt_codes = amm.model_years.map(&:alt_fuel_code).uniq
34
- amm.alt_fuel_code = (alt_codes.first if alt_codes.count == 1)
35
-
36
34
  type_names = amm.model_years.map(&:type_name).uniq
37
- amm.type_name = (type_names.one? ? type_names.first : nil)
38
-
39
- amm.save!
35
+ amm.update_attributes!(
36
+ :alt_fuel_code => (alt_codes.first if alt_codes.count == 1),
37
+ :type_name => (type_names.first if type_names.one?)
38
+ )
40
39
  end
41
40
  end
42
41
 
@@ -63,8 +63,7 @@ AutomobileMakeModelYear.class_eval do
63
63
  process "Derive type name from AutomobileMakeModelYearVariant" do
64
64
  find_each do |ammy|
65
65
  type_names = AutomobileMakeModelYearVariant.where(:make_name => ammy.make_name, :model_name => ammy.model_name, :year => ammy.year).map(&:type_name).uniq
66
- ammy.type_name = (type_names.one? ? type_names.first : nil)
67
- ammy.save!
66
+ ammy.update_attributes! :type_name => (type_names.first if type_names.one?)
68
67
  end
69
68
  end
70
69
 
@@ -391,8 +391,7 @@ AutomobileMakeModelYearVariant.class_eval do
391
391
  hybrids << where(:make_name => 'Buick', :model_name => 'REGAL', :year => 2012, :alt_fuel_code => nil).sort_by!(&:fuel_efficiency_city).last
392
392
  end
393
393
  hybrids.each do |hybrid|
394
- hybrid.model_name += ' HYBRID'
395
- hybrid.save!
394
+ hybrid.update_attributes! :model_name => hybrid.model_name + ' HYBRID'
396
395
  end
397
396
  end
398
397
 
@@ -400,9 +399,8 @@ AutomobileMakeModelYearVariant.class_eval do
400
399
  where(:make_name => 'Chevrolet', :model_name => 'CAVALIER DUAL-FUEL', :fuel_code => 'C').each do |cng_variant|
401
400
  gasoline_variant = where(:make_name => 'Chevrolet', :model_name => 'CAVALIER DUAL-FUEL', :fuel_code => ['R', 'P'], :alt_fuel_code => nil).find_by_year(cng_variant.year)
402
401
  %w{ fuel_code fuel_efficiency_city fuel_efficiency_city_units fuel_efficiency_highway fuel_efficiency_highway_units }.each do |attribute|
403
- gasoline_variant.send("alt_#{attribute}=", cng_variant.send(attribute))
402
+ gasoline_variant.update_attributes! :"alt_#{attribute}" => cng_variant.send(attribute)
404
403
  end
405
- gasoline_variant.save!
406
404
  cng_variant.destroy
407
405
  end
408
406
  end
@@ -439,9 +437,8 @@ AutomobileMakeModelYearVariant.class_eval do
439
437
 
440
438
  if gasoline_variant.present?
441
439
  %w{ fuel_code fuel_efficiency_city fuel_efficiency_city_units fuel_efficiency_highway fuel_efficiency_highway_units }.each do |attribute|
442
- gasoline_variant.send("alt_#{attribute}=", ethanol_variant.send(attribute))
440
+ gasoline_variant.update_attributes! :"alt_#{attribute}" => ethanol_variant.send(attribute)
443
441
  end
444
- gasoline_variant.save!
445
442
  ethanol_variant.destroy
446
443
  end
447
444
  end
@@ -450,8 +447,7 @@ AutomobileMakeModelYearVariant.class_eval do
450
447
  process "Update model name to indicate flex-fuel variants of models where variants in some years are not flex-fuel" do
451
448
  where("alt_fuel_code = 'E' AND model_name NOT LIKE '% FFV'").each do |variant|
452
449
  if where(:make_name => variant.make_name, :model_name => variant.model_name, :alt_fuel_code => nil).any?
453
- variant.model_name += ' FFV'
454
- variant.save!
450
+ variant.update_attributes! :model_name => variant.model_name + ' FFV'
455
451
  end
456
452
  end
457
453
  end
@@ -459,8 +455,7 @@ AutomobileMakeModelYearVariant.class_eval do
459
455
  process "Update model name to indicate diesel variants of models where variants in some years are not diesel" do
460
456
  where("fuel_code = 'D' AND model_name NOT LIKE '% DIESEL'").each do |variant|
461
457
  if where("make_name = ? AND model_name = ? AND fuel_code != 'D'", variant.make_name, variant.model_name).any?
462
- variant.model_name += ' DIESEL'
463
- variant.save!
458
+ variant.update_attributes! :model_name => variant.model_name + ' DIESEL'
464
459
  end
465
460
  end
466
461
  end
@@ -3,12 +3,12 @@ class AutomobileTypeFuel < ActiveRecord::Base
3
3
 
4
4
  # for calculating vehicles
5
5
  def latest_activity_year_type_fuel
6
- AutomobileActivityYearTypeFuel.latest.where(:type_name => type_name, :fuel_common_name => fuel_common_name).first
6
+ AutomobileActivityYearTypeFuel.latest.where(:type_name => type_name, :fuel_group => fuel_group).first
7
7
  end
8
8
 
9
9
  col :name
10
10
  col :type_name
11
- col :fuel_common_name
11
+ col :fuel_group
12
12
  col :annual_distance, :type => :float
13
13
  col :annual_distance_units
14
14
  col :fuel_consumption, :type => :float
@@ -13,9 +13,9 @@ AutomobileTypeFuel.class_eval do
13
13
  :src => AutomobileTypeFuelYear,
14
14
  :dest => AutomobileTypeFuel,
15
15
  :cols => {
16
- [:type_name, :fuel_common_name] => :name,
16
+ [:type_name, :fuel_group] => :name,
17
17
  :type_name => :type_name,
18
- :fuel_common_name => :fuel_common_name
18
+ :fuel_group => :fuel_group
19
19
  }
20
20
  )
21
21
  end
@@ -23,7 +23,7 @@ AutomobileTypeFuel.class_eval do
23
23
  process "Derive annual distance and emission factors from AutomobileTypeFuelYear" do
24
24
  type_fuels = arel_table
25
25
  type_fuel_years = AutomobileTypeFuelYear.arel_table
26
- join_relation = type_fuel_years[:type_name].eq(type_fuels[:type_name]).and(type_fuel_years[:fuel_common_name].eq(type_fuels[:fuel_common_name]))
26
+ join_relation = type_fuel_years[:type_name].eq(type_fuels[:type_name]).and(type_fuel_years[:fuel_group].eq(type_fuels[:fuel_group]))
27
27
 
28
28
  %w{ annual_distance ch4_emission_factor n2o_emission_factor }.each do |item|
29
29
  item_sql = AutomobileTypeFuelYear.where(join_relation).weighted_average_relation(:"#{item}", :weighted_by => :share_of_type).to_sql
@@ -42,10 +42,11 @@ AutomobileTypeFuel.class_eval do
42
42
 
43
43
  process "Derive number of vehicles and fuel consumption from AutomobileActivityYearTypeFuel" do
44
44
  find_each do |atf|
45
- atf.vehicles = atf.latest_activity_year_type_fuel.distance / atf.annual_distance
46
- atf.fuel_consumption = atf.latest_activity_year_type_fuel.fuel_consumption
47
- atf.fuel_consumption_units = atf.latest_activity_year_type_fuel.fuel_consumption_units
48
- atf.save!
45
+ atf.update_attributes!(
46
+ :vehicles => atf.latest_activity_year_type_fuel.distance / atf.annual_distance,
47
+ :fuel_consumption => atf.latest_activity_year_type_fuel.fuel_consumption,
48
+ :fuel_consumption_units => atf.latest_activity_year_type_fuel.fuel_consumption_units
49
+ )
49
50
  end
50
51
  end
51
52
  end
@@ -3,7 +3,7 @@ class AutomobileTypeFuelControl < ActiveRecord::Base
3
3
 
4
4
  col :name
5
5
  col :type_name
6
- col :fuel_common_name
6
+ col :fuel_group
7
7
  col :control_name
8
8
  col :ch4_emission_factor, :type => :float
9
9
  col :ch4_emission_factor_units
@@ -7,7 +7,7 @@ AutomobileTypeFuelControl.class_eval do
7
7
  :url => "file://#{Earth::DATA_DIR}/automobile/emission_control_techs.csv" do
8
8
  key 'name'
9
9
  store 'type_name'
10
- store 'fuel_common_name'
10
+ store 'fuel_group'
11
11
  store 'control_name'
12
12
  store 'ch4_emission_factor', :from_units => :grams_per_mile, :to_units => :kilograms_per_kilometre
13
13
  store 'n2o_emission_factor', :from_units => :grams_per_mile, :to_units => :kilograms_per_kilometre
@@ -2,22 +2,22 @@ class AutomobileTypeFuelYear < ActiveRecord::Base
2
2
  self.primary_key = "name"
3
3
 
4
4
  # Used by Automobile and AutomobileTrip
5
- def self.find_by_type_name_and_fuel_common_name_and_closest_year(type_name, fuel_common_name, year)
5
+ def self.find_by_type_name_and_fuel_group_and_closest_year(type_name, fuel_group, year)
6
6
  if year > maximum(:year)
7
- where(:type_name => type_name, :fuel_common_name => fuel_common_name, :year => maximum(:year)).first
7
+ where(:type_name => type_name, :fuel_group => fuel_group, :year => maximum(:year)).first
8
8
  else
9
- where(:type_name => type_name, :fuel_common_name => fuel_common_name, :year => [year, minimum(:year)].max).first
9
+ where(:type_name => type_name, :fuel_group => fuel_group, :year => [year, minimum(:year)].max).first
10
10
  end
11
11
  end
12
12
 
13
13
  # for calculating ch4 and n2o ef
14
14
  def type_fuel_year_controls
15
- AutomobileTypeFuelYearControl.find_all_by_type_name_and_fuel_common_name_and_closest_year(type_name, fuel_common_name, year)
15
+ AutomobileTypeFuelYearControl.find_all_by_type_name_and_fuel_group_and_closest_year(type_name, fuel_group, year)
16
16
  end
17
17
 
18
18
  col :name
19
19
  col :type_name
20
- col :fuel_common_name
20
+ col :fuel_group
21
21
  col :year, :type => :integer
22
22
  col :share_of_type, :type => :float
23
23
  col :annual_distance, :type => :float
@@ -16,7 +16,7 @@ AutomobileTypeFuelYear.class_eval do
16
16
  :select => proc { |row| row['age'].to_i.to_s == row['age'] } do
17
17
  key 'name', :synthesize => proc { |row| "#{type} #{fuel} #{2009 - row['age'].to_i}" }
18
18
  store 'type_name', :static => type
19
- store 'fuel_common_name', :static => fuel
19
+ store 'fuel_group', :static => fuel
20
20
  store 'year', :synthesize => proc { |row| 2009 - row['age'].to_i }
21
21
  store 'share_of_type', :synthesize => proc { |row| row[code].to_f / (code == 'LDDV' ? 57.5 : 100) } # total percent only sums to 57.5 for diesel cars
22
22
  end
@@ -40,11 +40,12 @@ AutomobileTypeFuelYear.class_eval do
40
40
  # Can't use an update all here b/c efs are methods defined on ATFYC that look up the ef from ATFC
41
41
  process "Derive ch4 and n2o emission factor from AutomobileTypeFuelYearControl" do
42
42
  find_each do |atfy|
43
- atfy.ch4_emission_factor = atfy.type_fuel_year_controls.sum{ |atfyc| atfyc.total_travel_percent * atfyc.ch4_emission_factor }
44
- atfy.n2o_emission_factor = atfy.type_fuel_year_controls.sum{ |atfyc| atfyc.total_travel_percent * atfyc.n2o_emission_factor }
45
- atfy.ch4_emission_factor_units = atfy.type_fuel_year_controls.first.ch4_emission_factor_units
46
- atfy.n2o_emission_factor_units = atfy.type_fuel_year_controls.first.n2o_emission_factor_units
47
- atfy.save!
43
+ atfy.update_attributes!(
44
+ :ch4_emission_factor => atfy.type_fuel_year_controls.sum{ |atfyc| atfyc.total_travel_percent * atfyc.ch4_emission_factor },
45
+ :n2o_emission_factor => atfy.type_fuel_year_controls.sum{ |atfyc| atfyc.total_travel_percent * atfyc.n2o_emission_factor },
46
+ :ch4_emission_factor_units => atfy.type_fuel_year_controls.first.ch4_emission_factor_units,
47
+ :n2o_emission_factor_units => atfy.type_fuel_year_controls.first.n2o_emission_factor_units
48
+ )
48
49
  end
49
50
  end
50
51
  end