earth 0.5.4 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -5,9 +5,13 @@ Urbanity.class_eval do
5
5
  end
6
6
 
7
7
  process "Derive from ResidentialEnergyConsumptionSurveyResponse" do
8
- INSERT_IGNORE %{INTO urbanities(name)
9
- SELECT DISTINCT recs_responses.urbanity_id FROM recs_responses WHERE LENGTH(recs_responses.urbanity_id) > 0
10
- }
8
+ ::Earth::Utils.insert_ignore(
9
+ :src => ResidentialEnergyConsumptionSurveyResponse,
10
+ :dest => Urbanity,
11
+ :cols => {
12
+ :urbanity_id => :name
13
+ }
14
+ )
11
15
  end
12
16
  end
13
17
  end
@@ -11,13 +11,11 @@ class ZipCode < ActiveRecord::Base
11
11
  :lat_column_name => :latitude,
12
12
  :lng_column_name => :longitude
13
13
 
14
- force_schema do
15
- string 'name'
16
- string 'state_postal_abbreviation'
17
- string 'description'
18
- string 'latitude'
19
- string 'longitude'
20
- string 'egrid_subregion_abbreviation'
21
- string 'climate_division_name'
22
- end
23
- end
14
+ col :name
15
+ col :state_postal_abbreviation
16
+ col :description
17
+ col :latitude
18
+ col :longitude
19
+ col :egrid_subregion_abbreviation
20
+ col :climate_division_name
21
+ end
@@ -4,10 +4,8 @@ class Breed < ActiveRecord::Base
4
4
  has_many :breed_genders, :foreign_key => 'breed_name'
5
5
  belongs_to :species, :foreign_key => 'species_name'
6
6
 
7
- force_schema do
8
- string 'name'
9
- string 'species_name'
10
- float 'weight'
11
- string 'weight_units'
12
- end
13
- end
7
+ col :name
8
+ col :species_name
9
+ col :weight, :type => :float
10
+ col :weight_units
11
+ end
@@ -4,11 +4,9 @@ class BreedGender < ActiveRecord::Base
4
4
  belongs_to :breed, :foreign_key => 'breed_name'
5
5
  belongs_to :gender, :foreign_key => 'gender_name'
6
6
 
7
- force_schema do
8
- string 'name'
9
- string 'breed_name'
10
- string 'gender_name'
11
- float 'weight'
12
- string 'weight_units'
13
- end
14
- end
7
+ col :name
8
+ col :breed_name
9
+ col :gender_name
10
+ col :weight, :type => :float
11
+ col :weight_units
12
+ end
@@ -3,7 +3,5 @@ class Gender < ActiveRecord::Base
3
3
 
4
4
  has_many :breed_genders, :foreign_key => 'gender_name'
5
5
 
6
- force_schema do
7
- string 'name'
8
- end
9
- end
6
+ col :name
7
+ end
@@ -1,22 +1,20 @@
1
1
  class Species < ActiveRecord::Base
2
2
  set_primary_key :name
3
3
 
4
- force_schema do
5
- string 'name'
6
- integer 'population'
7
- float 'diet_emission_intensity'
8
- string 'diet_emission_intensity_units'
9
- float 'weight'
10
- string 'weight_units'
11
- float 'marginal_dietary_requirement'
12
- string 'marginal_dietary_requirement_units'
13
- float 'fixed_dietary_requirement'
14
- string 'fixed_dietary_requirement_units'
15
- float 'minimum_weight'
16
- string 'minimum_weight_units'
17
- float 'maximum_weight'
18
- string 'maximum_weight_units'
19
- end
4
+ col :name
5
+ col :population, :type => :integer
6
+ col :diet_emission_intensity, :type => :float
7
+ col :diet_emission_intensity_units
8
+ col :weight, :type => :float
9
+ col :weight_units
10
+ col :marginal_dietary_requirement, :type => :float
11
+ col :marginal_dietary_requirement_units
12
+ col :fixed_dietary_requirement, :type => :float
13
+ col :fixed_dietary_requirement_units
14
+ col :minimum_weight, :type => :float
15
+ col :minimum_weight_units
16
+ col :maximum_weight, :type => :float
17
+ col :maximum_weight_units
20
18
 
21
19
  scope :thoroughly_researched, :conditions => 'marginal_dietary_requirement IS NOT NULL'
22
20
 
@@ -57,4 +55,4 @@ class Species < ActiveRecord::Base
57
55
  def cat?
58
56
  eql? self.class[:cat]
59
57
  end
60
- end
58
+ end
@@ -1,16 +1,66 @@
1
1
  class RailClass < ActiveRecord::Base
2
2
  set_primary_key :name
3
- force_schema do
4
- string 'name'
5
- string 'description'
6
- float 'passengers'
7
- float 'distance'
8
- string 'distance_units'
9
- float 'speed'
10
- string 'speed_units'
11
- float 'electricity_intensity'
12
- string 'electricity_intensity_units'
13
- float 'diesel_intensity'
14
- string 'diesel_intensity_units'
15
- end
16
- end
3
+ col :name
4
+ col :description
5
+ col :passengers, :type => :float
6
+ col :distance, :type => :float
7
+ col :distance_units
8
+ col :speed, :type => :float
9
+ col :speed_units
10
+ col :electricity_intensity, :type => :float
11
+ col :electricity_intensity_units
12
+ col :diesel_intensity, :type => :float
13
+ col :diesel_intensity_units
14
+
15
+ # verify "Passengers, distance, speed, and electricity intensity should be greater than zero" do
16
+ # RailClass.all.each do |rail_class|
17
+ # %w{ passengers distance speed electricity_intensity }.each do |attribute|
18
+ # value = rail_class.send(:"#{attribute}")
19
+ # unless value > 0
20
+ # raise "Invalid #{attribute} for RailClass #{rail_class.name}: #{value} (should be > 0)"
21
+ # end
22
+ # end
23
+ # end
24
+ # end
25
+ #
26
+ # verify "Distance units should be kilometres" do
27
+ # RailClass.all.each do |rail_class|
28
+ # unless rail_class.distance_units == "kilometres"
29
+ # raise "Invalid distance units for RailClass #{rail_class.name}: #{rail_class.distance_units} (should be kilometres)"
30
+ # end
31
+ # end
32
+ # end
33
+ #
34
+ # verify "Speed units should be kilometres per hour" do
35
+ # RailClass.all.each do |rail_class|
36
+ # unless rail_class.speed_units == "kilometres_per_hour"
37
+ # raise "Invalid speed units for RailClass #{rail_class.name}: #{rail_class.speed_units} (should be kilometres_per_hour)"
38
+ # end
39
+ # end
40
+ # end
41
+ #
42
+ # verify "Electricity intensity units should be kilowatt hours per kilometre" do
43
+ # RailClass.all.each do |rail_class|
44
+ # unless rail_class.electricity_intensity_units == "kilowatt_hours_per_kilometre"
45
+ # raise "Invalid electricity intensity units for RailClass #{rail_class.name}: #{rail_class.electricity_intensity_units} (should be kilowatt_hours_per_kilometre)"
46
+ # end
47
+ # end
48
+ # end
49
+ #
50
+ # verify "Diesel intensity should be zero or more" do
51
+ # RailClass.all.each do |rail_class|
52
+ # unless rail_class.diesel_intensity >= 0
53
+ # raise "Invalid diesel intensity for RailClass #{rail_class.name}: #{rail_class.diesel_intensity} (should be > 0)"
54
+ # end
55
+ # end
56
+ # end
57
+ #
58
+ # verify "Diesel intensity units should be litres per kilometre" do
59
+ # RailClass.all.each do |rail_class|
60
+ # unless rail_class.diesel_intensity_units == "litres_per_kilometre"
61
+ # raise "Invalid distance units for RailClass #{rail_class.name}: #{rail_class.diesel_intensity_units} (should be litres_per_kilometre)"
62
+ # end
63
+ # end
64
+ # end
65
+
66
+ end
@@ -14,56 +14,5 @@ RailClass.class_eval do
14
14
  store 'electricity_intensity', :units_field_name => 'electricity_intensity_units'
15
15
  store 'diesel_intensity', :units_field_name => 'diesel_intensity_units'
16
16
  end
17
-
18
- verify "Passengers, distance, speed, and electricity intensity should be greater than zero" do
19
- RailClass.all.each do |rail_class|
20
- %w{ passengers distance speed electricity_intensity }.each do |attribute|
21
- value = rail_class.send(:"#{attribute}")
22
- unless value > 0
23
- raise "Invalid #{attribute} for RailClass #{rail_class.name}: #{value} (should be > 0)"
24
- end
25
- end
26
- end
27
- end
28
-
29
- verify "Distance units should be kilometres" do
30
- RailClass.all.each do |rail_class|
31
- unless rail_class.distance_units == "kilometres"
32
- raise "Invalid distance units for RailClass #{rail_class.name}: #{rail_class.distance_units} (should be kilometres)"
33
- end
34
- end
35
- end
36
-
37
- verify "Speed units should be kilometres per hour" do
38
- RailClass.all.each do |rail_class|
39
- unless rail_class.speed_units == "kilometres_per_hour"
40
- raise "Invalid speed units for RailClass #{rail_class.name}: #{rail_class.speed_units} (should be kilometres_per_hour)"
41
- end
42
- end
43
- end
44
-
45
- verify "Electricity intensity units should be kilowatt hours per kilometre" do
46
- RailClass.all.each do |rail_class|
47
- unless rail_class.electricity_intensity_units == "kilowatt_hours_per_kilometre"
48
- raise "Invalid electricity intensity units for RailClass #{rail_class.name}: #{rail_class.electricity_intensity_units} (should be kilowatt_hours_per_kilometre)"
49
- end
50
- end
51
- end
52
-
53
- verify "Diesel intensity should be zero or more" do
54
- RailClass.all.each do |rail_class|
55
- unless rail_class.diesel_intensity >= 0
56
- raise "Invalid diesel intensity for RailClass #{rail_class.name}: #{rail_class.diesel_intensity} (should be > 0)"
57
- end
58
- end
59
- end
60
-
61
- verify "Diesel intensity units should be litres per kilometre" do
62
- RailClass.all.each do |rail_class|
63
- unless rail_class.diesel_intensity_units == "litres_per_kilometre"
64
- raise "Invalid distance units for RailClass #{rail_class.name}: #{rail_class.diesel_intensity_units} (should be litres_per_kilometre)"
65
- end
66
- end
67
- end
68
17
  end
69
18
  end
@@ -6,9 +6,7 @@ class AirConditionerUse < ActiveRecord::Base
6
6
  falls_back_on :fugitive_emission => 0.102295.pounds_per_square_foot.to(:kilograms_per_square_metre), # https://brighterplanet.sifterapp.com/projects/30/issues/430
7
7
  :fugitive_emission_units => 'kilograms_per_square_metre'
8
8
 
9
- force_schema do
10
- string 'name'
11
- float 'fugitive_emission'
12
- string 'fugitive_emission_units'
13
- end
14
- end
9
+ col :name
10
+ col :fugitive_emission, :type => :float
11
+ col :fugitive_emission_units
12
+ end
@@ -5,9 +5,13 @@ AirConditionerUse.class_eval do
5
5
  end
6
6
 
7
7
  process "Derive from ResidentialEnergyConsumptionSurveyResponse" do
8
- INSERT_IGNORE %{INTO air_conditioner_uses(name)
9
- SELECT DISTINCT recs_responses.central_ac_use FROM recs_responses WHERE LENGTH(recs_responses.central_ac_use) > 0
10
- }
8
+ ::Earth::Utils.insert_ignore(
9
+ :src => ResidentialEnergyConsumptionSurveyResponse,
10
+ :dest => AirConditionerUse,
11
+ :cols => {
12
+ :central_ac_use => :name
13
+ }
14
+ )
11
15
  end
12
16
 
13
17
  import "Ian's precalculated fugitive emissions values", :url => 'http://spreadsheets.google.com/pub?key=ri_380yQZAqBKeqie_TECgg&gid=0&output=csv' do
@@ -3,9 +3,7 @@ class ClothesMachineUse < ActiveRecord::Base
3
3
 
4
4
  has_many :residential_energy_consumption_survey_responses
5
5
 
6
- force_schema do
7
- string 'name'
8
- float 'annual_energy_from_electricity_for_clothes_driers'
9
- string 'annual_energy_from_electricity_for_clothes_driers_units'
10
- end
11
- end
6
+ col :name
7
+ col :annual_energy_from_electricity_for_clothes_driers, :type => :float
8
+ col :annual_energy_from_electricity_for_clothes_driers_units
9
+ end
@@ -5,19 +5,21 @@ ClothesMachineUse.class_eval do
5
5
  end
6
6
 
7
7
  process "Derive from ResidentialEnergyConsumptionSurveyResponse" do
8
- INSERT_IGNORE %{INTO clothes_machine_uses(name)
9
- SELECT DISTINCT recs_responses.clothes_washer_use FROM recs_responses WHERE LENGTH(recs_responses.clothes_washer_use) > 0
10
- }
8
+ ::Earth::Utils.insert_ignore(
9
+ :src => ResidentialEnergyConsumptionSurveyResponse,
10
+ :dest => ClothesMachineUse,
11
+ :cols => {
12
+ :clothes_washer_use => :name
13
+ }
14
+ )
11
15
  end
12
16
 
13
17
  # sabshere 5/20/10 weird that this uses cohort
14
18
  process "precalculate annual energy use" do
15
- find_in_batches do |batch|
16
- batch.each do |record|
17
- record.annual_energy_from_electricity_for_clothes_driers = ResidentialEnergyConsumptionSurveyResponse.big_cohort(:clothes_machine_use_id => record.name).weighted_average :annual_energy_from_electricity_for_clothes_driers
18
- record.annual_energy_from_electricity_for_clothes_driers_units = 'joules'
19
- record.save!
20
- end
19
+ find_each do |record|
20
+ record.annual_energy_from_electricity_for_clothes_driers = ResidentialEnergyConsumptionSurveyResponse.big_cohort(:clothes_machine_use_id => record.name).weighted_average :annual_energy_from_electricity_for_clothes_driers
21
+ record.annual_energy_from_electricity_for_clothes_driers_units = 'joules'
22
+ record.save!
21
23
  end
22
24
  end
23
25
  end
@@ -3,9 +3,7 @@ class DishwasherUse < ActiveRecord::Base
3
3
 
4
4
  has_many :residential_energy_consumption_survey_responses
5
5
 
6
- force_schema do
7
- string 'name'
8
- float 'annual_energy_from_electricity_for_dishwashers'
9
- string 'annual_energy_from_electricity_for_dishwashers_units'
10
- end
11
- end
6
+ col :name
7
+ col :annual_energy_from_electricity_for_dishwashers, :type => :float
8
+ col :annual_energy_from_electricity_for_dishwashers_units
9
+ end
@@ -5,19 +5,21 @@ DishwasherUse.class_eval do
5
5
  end
6
6
 
7
7
  process "Derive from ResidentialEnergyConsumptionSurveyResponse" do
8
- INSERT_IGNORE %{INTO dishwasher_uses(name)
9
- SELECT DISTINCT recs_responses.dishwasher_use_id FROM recs_responses WHERE LENGTH(recs_responses.dishwasher_use_id) > 0
10
- }
8
+ ::Earth::Utils.insert_ignore(
9
+ :src => ResidentialEnergyConsumptionSurveyResponse,
10
+ :dest => DishwasherUse,
11
+ :cols => {
12
+ :dishwasher_use_id => :name
13
+ }
14
+ )
11
15
  end
12
16
 
13
17
  # sabshere 5/25/10 weird that this uses cohort
14
18
  process "precalculate annual energy" do
15
- find_in_batches do |batch|
16
- batch.each do |record|
17
- record.annual_energy_from_electricity_for_dishwashers = ResidentialEnergyConsumptionSurveyResponse.big_cohort(:dishwasher_use_id => record.name).weighted_average :annual_energy_from_electricity_for_dishwashers
18
- record.annual_energy_from_electricity_for_dishwashers_units = 'joules'
19
- record.save!
20
- end
19
+ find_each do |record|
20
+ record.annual_energy_from_electricity_for_dishwashers = ResidentialEnergyConsumptionSurveyResponse.big_cohort(:dishwasher_use_id => record.name).weighted_average :annual_energy_from_electricity_for_dishwashers
21
+ record.annual_energy_from_electricity_for_dishwashers_units = 'joules'
22
+ record.save!
21
23
  end
22
24
  end
23
25
  end
@@ -10,9 +10,7 @@ class ResidenceAppliance < ActiveRecord::Base
10
10
  end
11
11
  end
12
12
 
13
- force_schema do
14
- string 'name'
15
- float 'annual_energy_from_electricity'
16
- string 'annual_energy_from_electricity_units'
17
- end
18
- end
13
+ col :name
14
+ col :annual_energy_from_electricity, :type => :float
15
+ col :annual_energy_from_electricity_units
16
+ end
@@ -9,7 +9,5 @@ class ResidenceClass < ActiveRecord::Base
9
9
  CLASSIFICATIONS.detect { |c| name.downcase.include? c }
10
10
  end
11
11
 
12
- force_schema do
13
- string :name
14
- end
15
- end
12
+ col :name
13
+ end
@@ -5,9 +5,13 @@ ResidenceClass.class_eval do
5
5
  end
6
6
 
7
7
  process "Derive from ResidentialEnergyConsumptionSurveyResponse" do
8
- INSERT_IGNORE %{INTO residence_classes(name)
9
- SELECT DISTINCT recs_responses.residence_class_id FROM recs_responses WHERE LENGTH(recs_responses.residence_class_id) > 0
10
- }
8
+ ::Earth::Utils.insert_ignore(
9
+ :src => ResidentialEnergyConsumptionSurveyResponse,
10
+ :dest => ResidenceClass,
11
+ :cols => {
12
+ :residence_class_id => :name
13
+ }
14
+ )
11
15
  end
12
16
  end
13
17
  end
@@ -7,17 +7,15 @@ class ResidenceFuelPrice < ActiveRecord::Base
7
7
  belongs_to :fuel, :class_name => 'ResidenceFuelType', :foreign_key => 'residence_fuel_type_name'
8
8
  belongs_to :locatable, :polymorphic => true
9
9
 
10
- force_schema do
11
- string 'row_hash'
12
- string 'residence_fuel_type_name'
13
- integer 'year'
14
- integer 'month'
15
- float 'price'
16
- string 'price_units'
17
- string 'price_description'
18
- string 'locatable_id'
19
- string 'locatable_type'
20
- index ['price', 'residence_fuel_type_name', 'month', 'year', 'locatable_type', 'locatable_id']
21
- index ['price', 'residence_fuel_type_name']
22
- end
23
- end
10
+ col :row_hash
11
+ col :residence_fuel_type_name
12
+ col :year, :type => :integer
13
+ col :month, :type => :integer
14
+ col :price, :type => :float
15
+ col :price_units
16
+ col :price_description
17
+ col :locatable_id
18
+ col :locatable_type
19
+ add_index [:price, :residence_fuel_type_name, :month, :year, :locatable_type, :locatable_id]
20
+ add_index [:price, :residence_fuel_type_name]
21
+ end