earth 0.12.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (257) hide show
  1. data/.gitignore +4 -1
  2. data/Gemfile +0 -5
  3. data/README.markdown +32 -19
  4. data/Rakefile +4 -0
  5. data/bin/earth_tester.rb +66 -54
  6. data/earth.gemspec +6 -3
  7. data/lib/earth.rb +67 -114
  8. data/lib/earth/air.rb +1 -1
  9. data/lib/earth/air/aircraft.rb +37 -21
  10. data/lib/earth/air/aircraft/data_miner.rb +0 -4
  11. data/lib/earth/air/airline.rb +19 -5
  12. data/lib/earth/air/airline/data_miner.rb +0 -4
  13. data/lib/earth/air/airport.rb +23 -9
  14. data/lib/earth/air/airport/data_miner.rb +1 -5
  15. data/lib/earth/air/bts_aircraft.rb +14 -2
  16. data/lib/earth/air/flight_distance_class.rb +19 -7
  17. data/lib/earth/air/flight_distance_class_seat_class.rb +21 -4
  18. data/lib/earth/air/flight_seat_class.rb +13 -1
  19. data/lib/earth/air/flight_seat_class/data_miner.rb +2 -0
  20. data/lib/earth/air/flight_segment.rb +64 -59
  21. data/lib/earth/air/flight_segment/data_miner.rb +4 -5
  22. data/lib/earth/all.rb +1 -1
  23. data/lib/earth/automobile.rb +1 -1
  24. data/lib/earth/automobile/automobile_activity_year.rb +17 -3
  25. data/lib/earth/automobile/automobile_activity_year/data_miner.rb +0 -4
  26. data/lib/earth/automobile/automobile_activity_year_type.rb +21 -7
  27. data/lib/earth/automobile/automobile_activity_year_type/data_miner.rb +0 -4
  28. data/lib/earth/automobile/automobile_activity_year_type_fuel.rb +20 -8
  29. data/lib/earth/automobile/automobile_activity_year_type_fuel/data_miner.rb +0 -4
  30. data/lib/earth/automobile/automobile_fuel.rb +37 -23
  31. data/lib/earth/automobile/automobile_fuel/data_miner.rb +3 -5
  32. data/lib/earth/automobile/automobile_make.rb +17 -3
  33. data/lib/earth/automobile/automobile_make/data_miner.rb +0 -4
  34. data/lib/earth/automobile/automobile_make_model.rb +29 -14
  35. data/lib/earth/automobile/automobile_make_model/data_miner.rb +2 -5
  36. data/lib/earth/automobile/automobile_make_model_year.rb +31 -18
  37. data/lib/earth/automobile/automobile_make_model_year/data_miner.rb +3 -4
  38. data/lib/earth/automobile/automobile_make_model_year_variant.rb +43 -31
  39. data/lib/earth/automobile/automobile_make_model_year_variant/data_miner.rb +0 -4
  40. data/lib/earth/automobile/automobile_make_year.rb +18 -7
  41. data/lib/earth/automobile/automobile_make_year/data_miner.rb +4 -4
  42. data/lib/earth/automobile/automobile_make_year_fleet.rb +19 -7
  43. data/lib/earth/automobile/automobile_make_year_fleet/data_miner.rb +0 -4
  44. data/lib/earth/automobile/automobile_model.rb +13 -1
  45. data/lib/earth/automobile/automobile_model/data_miner.rb +2 -4
  46. data/lib/earth/automobile/automobile_size_class.rb +24 -10
  47. data/lib/earth/automobile/automobile_size_class/data_miner.rb +0 -4
  48. data/lib/earth/automobile/automobile_type_fuel.rb +26 -12
  49. data/lib/earth/automobile/automobile_type_fuel/data_miner.rb +2 -4
  50. data/lib/earth/automobile/automobile_type_fuel_control.rb +20 -8
  51. data/lib/earth/automobile/automobile_type_fuel_control/data_miner.rb +0 -1
  52. data/lib/earth/automobile/automobile_type_fuel_year.rb +25 -11
  53. data/lib/earth/automobile/automobile_type_fuel_year/data_miner.rb +2 -4
  54. data/lib/earth/automobile/automobile_type_fuel_year_control.rb +21 -7
  55. data/lib/earth/automobile/automobile_type_fuel_year_control/data_miner.rb +0 -4
  56. data/lib/earth/automobile/automobile_year.rb +13 -1
  57. data/lib/earth/automobile/automobile_year/data_miner.rb +2 -0
  58. data/lib/earth/bus.rb +1 -1
  59. data/lib/earth/bus/bus_class.rb +38 -25
  60. data/lib/earth/bus/bus_class/data_miner.rb +0 -1
  61. data/lib/earth/bus/bus_fuel.rb +27 -13
  62. data/lib/earth/bus/bus_fuel/data_miner.rb +5 -1
  63. data/lib/earth/bus/bus_fuel_control.rb +19 -7
  64. data/lib/earth/bus/bus_fuel_control/data_miner.rb +0 -1
  65. data/lib/earth/bus/bus_fuel_year_control.rb +20 -7
  66. data/lib/earth/bus/bus_fuel_year_control/data_miner.rb +2 -1
  67. data/lib/earth/computation.rb +1 -1
  68. data/lib/earth/computation/computation_carrier.rb +16 -3
  69. data/lib/earth/computation/computation_carrier/data_miner.rb +0 -1
  70. data/lib/earth/computation/computation_carrier_instance_class.rb +21 -6
  71. data/lib/earth/computation/computation_carrier_instance_class/data_miner.rb +0 -1
  72. data/lib/earth/computation/computation_carrier_region.rb +18 -5
  73. data/lib/earth/computation/computation_carrier_region/data_miner.rb +0 -1
  74. data/lib/earth/diet.rb +1 -1
  75. data/lib/earth/diet/diet_class.rb +25 -13
  76. data/lib/earth/diet/food_group.rb +18 -7
  77. data/lib/earth/electricity.rb +1 -1
  78. data/lib/earth/electricity/electric_market.rb +17 -5
  79. data/lib/earth/electricity/electric_market/data_miner.rb +0 -2
  80. data/lib/earth/electricity/electric_utility.rb +22 -7
  81. data/lib/earth/electricity/electric_utility/data_miner.rb +1 -1
  82. data/lib/earth/electricity/green_button_adoption.rb +15 -3
  83. data/lib/earth/fuel.rb +1 -1
  84. data/lib/earth/fuel/fuel.rb +32 -19
  85. data/lib/earth/fuel/fuel/data_miner.rb +2 -4
  86. data/lib/earth/fuel/fuel_price.rb +17 -3
  87. data/lib/earth/fuel/fuel_type.rb +23 -12
  88. data/lib/earth/fuel/fuel_year.rb +27 -13
  89. data/lib/earth/fuel/greenhouse_gas.rb +18 -6
  90. data/lib/earth/hospitality.rb +1 -1
  91. data/lib/earth/hospitality/commercial_building_energy_consumption_survey_response.rb +68 -56
  92. data/lib/earth/hospitality/commercial_building_energy_consumption_survey_response/data_miner.rb +0 -4
  93. data/lib/earth/hospitality/lodging_class.rb +13 -1
  94. data/lib/earth/industry.rb +1 -1
  95. data/lib/earth/industry/cbecs_energy_intensity.rb +43 -32
  96. data/lib/earth/industry/cbecs_energy_intensity/data_miner.rb +0 -1
  97. data/lib/earth/industry/industry.rb +20 -2
  98. data/lib/earth/industry/industry/data_miner.rb +0 -4
  99. data/lib/earth/industry/industry_product.rb +20 -6
  100. data/lib/earth/industry/industry_product_line.rb +19 -5
  101. data/lib/earth/industry/industry_sector.rb +19 -6
  102. data/lib/earth/industry/mecs_energy.rb +34 -22
  103. data/lib/earth/industry/mecs_ratio.rb +17 -6
  104. data/lib/earth/industry/mecs_ratio/data_miner.rb +1 -1
  105. data/lib/earth/industry/merchant_category.rb +17 -2
  106. data/lib/earth/industry/merchant_category/data_miner.rb +0 -4
  107. data/lib/earth/industry/merchant_category_industry.rb +19 -4
  108. data/lib/earth/industry/naics_2002.rb +20 -3
  109. data/lib/earth/industry/naics_2002_naics_2007_concordance.rb +19 -4
  110. data/lib/earth/industry/naics_2002_sic_1987_concordance.rb +19 -4
  111. data/lib/earth/industry/naics_2007.rb +17 -2
  112. data/lib/earth/industry/product_line.rb +20 -5
  113. data/lib/earth/industry/product_line_industry_product.rb +19 -5
  114. data/lib/earth/industry/sector.rb +18 -5
  115. data/lib/earth/industry/sic_1987.rb +17 -2
  116. data/lib/earth/loader.rb +47 -0
  117. data/lib/earth/locality.rb +1 -1
  118. data/lib/earth/locality/census_division.rb +32 -13
  119. data/lib/earth/locality/census_division/data_miner.rb +0 -1
  120. data/lib/earth/locality/census_region.rb +18 -5
  121. data/lib/earth/locality/climate_division.rb +21 -6
  122. data/lib/earth/locality/country.rb +68 -56
  123. data/lib/earth/locality/country/data_miner.rb +8 -8
  124. data/lib/earth/locality/egrid_country.rb +22 -10
  125. data/lib/earth/locality/egrid_region.rb +25 -10
  126. data/lib/earth/locality/egrid_region/data_miner.rb +0 -4
  127. data/lib/earth/locality/egrid_subregion.rb +31 -16
  128. data/lib/earth/locality/egrid_subregion/data_miner.rb +7 -6
  129. data/lib/earth/locality/electricity_mix.rb +27 -13
  130. data/lib/earth/locality/electricity_mix/data_miner.rb +8 -8
  131. data/lib/earth/locality/petroleum_administration_for_defense_district.rb +17 -5
  132. data/lib/earth/locality/state.rb +36 -16
  133. data/lib/earth/locality/state/data_miner.rb +0 -4
  134. data/lib/earth/locality/zip_code.rb +34 -15
  135. data/lib/earth/locality/zip_code/data_miner.rb +0 -4
  136. data/lib/earth/model.rb +90 -0
  137. data/lib/earth/pet.rb +1 -1
  138. data/lib/earth/pet/breed.rb +19 -4
  139. data/lib/earth/pet/breed_gender.rb +20 -5
  140. data/lib/earth/pet/gender.rb +15 -1
  141. data/lib/earth/pet/species.rb +30 -14
  142. data/lib/earth/rail.rb +1 -1
  143. data/lib/earth/rail/country_rail_class.rb +26 -15
  144. data/lib/earth/rail/country_rail_class/data_miner.rb +0 -1
  145. data/lib/earth/rail/country_rail_traction.rb +21 -11
  146. data/lib/earth/rail/country_rail_traction/data_miner.rb +2 -2
  147. data/lib/earth/rail/country_rail_traction_class.rb +22 -12
  148. data/lib/earth/rail/country_rail_traction_class/data_miner.rb +2 -2
  149. data/lib/earth/rail/national_transit_database_company.rb +20 -6
  150. data/lib/earth/rail/national_transit_database_company/data_miner.rb +0 -1
  151. data/lib/earth/rail/national_transit_database_mode.rb +15 -3
  152. data/lib/earth/rail/national_transit_database_record.rb +45 -31
  153. data/lib/earth/rail/national_transit_database_record/data_miner.rb +0 -1
  154. data/lib/earth/rail/rail_class.rb +13 -1
  155. data/lib/earth/rail/rail_company.rb +34 -22
  156. data/lib/earth/rail/rail_company/data_miner.rb +7 -2
  157. data/lib/earth/rail/rail_company_traction.rb +21 -10
  158. data/lib/earth/rail/rail_company_traction/data_miner.rb +0 -1
  159. data/lib/earth/rail/rail_company_traction_class.rb +22 -11
  160. data/lib/earth/rail/rail_company_traction_class/data_miner.rb +0 -1
  161. data/lib/earth/rail/rail_fuel.rb +20 -7
  162. data/lib/earth/rail/rail_fuel/data_miner.rb +3 -1
  163. data/lib/earth/rail/rail_traction.rb +13 -1
  164. data/lib/earth/rail/rail_traction/data_miner.rb +5 -0
  165. data/lib/earth/residence.rb +1 -1
  166. data/lib/earth/residence/air_conditioner_use.rb +19 -3
  167. data/lib/earth/residence/clothes_machine_use.rb +17 -3
  168. data/lib/earth/residence/dishwasher_use.rb +17 -3
  169. data/lib/earth/residence/residence_appliance.rb +15 -3
  170. data/lib/earth/residence/residence_appliance/data_miner.rb +2 -0
  171. data/lib/earth/residence/residence_class.rb +15 -1
  172. data/lib/earth/residence/residence_fuel_price.rb +25 -12
  173. data/lib/earth/residence/residence_fuel_price/data_miner.rb +0 -1
  174. data/lib/earth/residence/residence_fuel_type.rb +17 -6
  175. data/lib/earth/residence/residential_energy_consumption_survey_response.rb +110 -91
  176. data/lib/earth/residence/residential_energy_consumption_survey_response/data_miner.rb +0 -1
  177. data/lib/earth/residence/urbanity.rb +15 -1
  178. data/lib/earth/shipping.rb +1 -1
  179. data/lib/earth/shipping/carrier.rb +24 -8
  180. data/lib/earth/shipping/carrier_mode.rb +22 -7
  181. data/lib/earth/shipping/shipment_mode.rb +18 -4
  182. data/lib/earth/tasks.rb +62 -0
  183. data/lib/earth/version.rb +1 -1
  184. data/lib/earth/warnings.rb +12 -0
  185. data/spec/data_mining_spec.rb +31 -0
  186. data/spec/earth/air/aircraft_spec.rb +0 -10
  187. data/spec/earth/air/airline_spec.rb +1 -11
  188. data/spec/earth/air/airport_spec.rb +0 -10
  189. data/spec/earth/air/bts_aircraft_spec.rb +0 -10
  190. data/spec/earth/air/flight_distance_class_spec.rb +0 -10
  191. data/spec/earth/air/flight_segment_spec.rb +27 -10
  192. data/spec/earth/automobile/automobile_activity_year_spec.rb +0 -7
  193. data/spec/earth/automobile/automobile_activity_year_type_fuel_spec.rb +0 -7
  194. data/spec/earth/automobile/automobile_activity_year_type_spec.rb +0 -7
  195. data/spec/earth/automobile/automobile_fuel_spec.rb +0 -10
  196. data/spec/earth/automobile/automobile_make_model_spec.rb +0 -8
  197. data/spec/earth/automobile/automobile_make_model_year_spec.rb +0 -8
  198. data/spec/earth/automobile/automobile_make_model_year_variant_spec.rb +0 -8
  199. data/spec/earth/automobile/automobile_make_spec.rb +0 -11
  200. data/spec/earth/automobile/automobile_make_year_fleet_spec.rb +0 -11
  201. data/spec/earth/automobile/automobile_make_year_spec.rb +0 -8
  202. data/spec/earth/automobile/automobile_model_spec.rb +0 -10
  203. data/spec/earth/automobile/automobile_size_class_spec.rb +0 -10
  204. data/spec/earth/automobile/automobile_type_fuel_control_spec.rb +0 -7
  205. data/spec/earth/automobile/automobile_type_fuel_spec.rb +0 -10
  206. data/spec/earth/automobile/automobile_type_fuel_year_control_spec.rb +0 -7
  207. data/spec/earth/automobile/automobile_type_fuel_year_spec.rb +1 -8
  208. data/spec/earth/automobile/automobile_year_spec.rb +2 -11
  209. data/spec/earth/bus/bus_fuel_control_spec.rb +0 -10
  210. data/spec/earth/bus/bus_fuel_spec.rb +0 -10
  211. data/spec/earth/bus/bus_fuel_year_control_spec.rb +0 -10
  212. data/spec/earth/electricity/electric_market_spec.rb +0 -10
  213. data/spec/earth/electricity/electric_utility_spec.rb +0 -10
  214. data/spec/earth/electricity/green_button_adoption_spec.rb +0 -10
  215. data/spec/earth/fuel/fuel_spec.rb +1 -10
  216. data/spec/earth/hospitality/commercial_building_energy_consumption_survey_response_spec.rb +0 -10
  217. data/spec/earth/hospitality/lodging_class_spec.rb +0 -10
  218. data/spec/earth/industry/cbecs_energy_intensity_spec.rb +3 -11
  219. data/spec/earth/industry/industry_spec.rb +0 -10
  220. data/spec/earth/industry/mecs_energy_spec.rb +0 -9
  221. data/spec/earth/industry/mecs_ratio_spec.rb +0 -9
  222. data/spec/earth/industry/merchant_category_spec.rb +2 -7
  223. data/spec/earth/industry/naics_2002_naics_2007_concordance_spec.rb +1 -12
  224. data/spec/earth/industry/naics_2002_sic_1987_concordance_spec.rb +3 -13
  225. data/spec/earth/industry/naics_2002_spec.rb +0 -10
  226. data/spec/earth/industry/naics_2007_spec.rb +0 -10
  227. data/spec/earth/industry/sic_1987_spec.rb +0 -10
  228. data/spec/earth/locality/country_spec.rb +0 -10
  229. data/spec/earth/locality/egrid_country_spec.rb +0 -11
  230. data/spec/earth/locality/egrid_region_spec.rb +0 -10
  231. data/spec/earth/locality/egrid_subregion_spec.rb +0 -10
  232. data/spec/earth/locality/electricity_mix_spec.rb +0 -10
  233. data/spec/earth/locality/state_spec.rb +0 -10
  234. data/spec/earth/locality/zip_code_spec.rb +7 -15
  235. data/spec/earth/model_spec.rb +27 -0
  236. data/spec/earth/pet/species_spec.rb +1 -1
  237. data/spec/earth_spec.rb +1 -30
  238. data/spec/factories/airline.rb +10 -0
  239. data/spec/factories/airport.rb +12 -0
  240. data/spec/factories/flight_segment.rb +38 -0
  241. data/spec/spec_helper.rb +27 -36
  242. metadata +249 -223
  243. data/lib/earth/active_record_base_class_methods.rb +0 -25
  244. data/lib/earth/air/data_miner.rb +0 -3
  245. data/lib/earth/automobile/data_miner.rb +0 -3
  246. data/lib/earth/bus/data_miner.rb +0 -3
  247. data/lib/earth/computation/data_miner.rb +0 -3
  248. data/lib/earth/data_miner.rb +0 -3
  249. data/lib/earth/diet/data_miner.rb +0 -3
  250. data/lib/earth/fuel/data_miner.rb +0 -3
  251. data/lib/earth/hospitality/data_miner.rb +0 -3
  252. data/lib/earth/industry/data_miner.rb +0 -3
  253. data/lib/earth/locality/data_miner.rb +0 -3
  254. data/lib/earth/pet/data_miner.rb +0 -3
  255. data/lib/earth/rail/data_miner.rb +0 -3
  256. data/lib/earth/residence/data_miner.rb +0 -3
  257. data/lib/earth/shipping/data_miner.rb +0 -3
@@ -1,4 +1,22 @@
1
+ require 'earth/model'
2
+
1
3
  class FoodGroup < ActiveRecord::Base
4
+ extend Earth::Model
5
+
6
+ TABLE_STRUCTURE = <<-EOS
7
+
8
+ CREATE TABLE food_groups
9
+ (
10
+ name CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
11
+ intensity FLOAT,
12
+ intensity_units CHARACTER VARYING(255),
13
+ energy FLOAT,
14
+ energy_units CHARACTER VARYING(255),
15
+ suggested_imperial_measurement CHARACTER VARYING(255)
16
+ );
17
+
18
+ EOS
19
+
2
20
  self.primary_key = "name"
3
21
 
4
22
  class << self
@@ -11,12 +29,5 @@ class FoodGroup < ActiveRecord::Base
11
29
  end
12
30
  end
13
31
 
14
- col :name
15
- col :intensity, :type => :float
16
- col :intensity_units
17
- col :energy, :type => :float
18
- col :energy_units
19
- col :suggested_imperial_measurement # ?
20
-
21
32
  warn_unless_size 10
22
33
  end
@@ -1,3 +1,3 @@
1
1
  # lib/earth/electricity.rb
2
2
  require 'earth'
3
- Earth.require_related __FILE__
3
+ Earth::Loader.require_related __FILE__
@@ -1,12 +1,24 @@
1
- require 'earth/locality'
1
+ require 'earth/model'
2
+
3
+ require 'earth/electricity/electric_utility'
4
+ require 'earth/locality/zip_code'
2
5
 
3
6
  class ElectricMarket < ActiveRecord::Base
7
+ extend Earth::Model
8
+
9
+ TABLE_STRUCTURE = <<-EOS
10
+
11
+ CREATE TABLE electric_markets
12
+ (
13
+ id CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
14
+ electric_utility_eia_id INTEGER,
15
+ zip_code_name CHARACTER VARYING(255)
16
+ );
17
+
18
+ EOS
19
+
4
20
  self.primary_key = "id" # string
5
21
 
6
22
  belongs_to :electric_utility, :foreign_key => 'electric_utility_eia_id'
7
23
  belongs_to :zip_code, :foreign_key => 'zip_code_name'
8
-
9
- col :id
10
- col :electric_utility_eia_id, :type => :integer
11
- col :zip_code_name
12
24
  end
@@ -1,5 +1,3 @@
1
- require 'earth/locality/data_miner'
2
-
3
1
  ElectricMarket.class_eval do
4
2
  data_miner do
5
3
  import 'IOU markets',
@@ -1,18 +1,33 @@
1
- require 'earth/locality'
1
+ require 'earth/model'
2
+
3
+ require 'earth/electricity/electric_market'
4
+ require 'earth/electricity/green_button_adoption'
5
+ require 'earth/locality/state'
6
+ require 'earth/locality/zip_code'
2
7
 
3
8
  class ElectricUtility < ActiveRecord::Base
9
+ extend Earth::Model
10
+
11
+ TABLE_STRUCTURE = <<-EOS
12
+
13
+ CREATE TABLE electric_utilities
14
+ (
15
+ eia_id INTEGER NOT NULL PRIMARY KEY,
16
+ name CHARACTER VARYING(255),
17
+ nickname CHARACTER VARYING(255),
18
+ state_postal_abbreviation CHARACTER VARYING(255),
19
+ nerc_region_abbreviation CHARACTER VARYING(255),
20
+ second_nerc_region_abbreviation CHARACTER VARYING(255)
21
+ );
22
+
23
+ EOS
24
+
4
25
  self.primary_key = "eia_id"
5
26
 
6
27
  belongs_to :state, :foreign_key => 'state_postal_abbreviation'
7
28
  has_many :electric_markets, :foreign_key => :electric_utility_eia_id
8
29
  has_many :zip_codes, :through => :electric_markets
9
30
 
10
- col :eia_id, :type => :integer
11
- col :name
12
- col :nickname
13
- col :state_postal_abbreviation
14
- col :nerc_region_abbreviation
15
- col :second_nerc_region_abbreviation
16
31
 
17
32
  def green_button_implementer?
18
33
  GreenButtonAdoption.implemented? name, nickname
@@ -1,4 +1,4 @@
1
- require 'earth/locality/data_miner'
1
+ require 'earth/electricity/green_button_adoption'
2
2
 
3
3
  ElectricUtility.class_eval do
4
4
  data_miner do
@@ -1,9 +1,21 @@
1
+ require 'earth/model'
2
+
1
3
  class GreenButtonAdoption < ActiveRecord::Base
4
+ extend Earth::Model
5
+
6
+ TABLE_STRUCTURE = <<-EOS
7
+
8
+ CREATE TABLE green_button_adoptions
9
+ (
10
+ electric_utility_name CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
11
+ implemented BOOLEAN,
12
+ committed BOOLEAN
13
+ );
14
+
15
+ EOS
16
+
2
17
  self.primary_key = "electric_utility_name"
3
18
 
4
- col :electric_utility_name
5
- col :implemented, :type => :boolean
6
- col :committed, :type => :boolean
7
19
 
8
20
  class << self
9
21
  def implemented?(*names)
@@ -1,3 +1,3 @@
1
1
  # lib/earth/fuel.rb
2
2
  require 'earth'
3
- Earth.require_related __FILE__
3
+ Earth::Loader.require_related __FILE__
@@ -1,23 +1,8 @@
1
+ require 'earth/model'
2
+
3
+ require 'earth/fuel/fuel_year'
4
+
1
5
  class Fuel < ActiveRecord::Base
2
- self.primary_key = "name"
3
-
4
- has_many :fuel_years, :foreign_key => 'fuel_name'
5
-
6
- col :name
7
- col :physical_units
8
- col :density, :type => :float
9
- col :density_units
10
- col :energy_content, :type => :float
11
- col :energy_content_units
12
- col :carbon_content, :type => :float
13
- col :carbon_content_units
14
- col :oxidation_factor, :type => :float
15
- col :biogenic_fraction, :type => :float
16
- col :co2_emission_factor, :type => :float
17
- col :co2_emission_factor_units
18
- col :co2_biogenic_emission_factor, :type => :float
19
- col :co2_biogenic_emission_factor_units
20
-
21
6
  # Need to ensure FuelYear gets data_mined even when pulling with taps
22
7
  # b/c Fuel has instance methods to look up missing values from FuelYear
23
8
  data_miner do
@@ -26,6 +11,34 @@ class Fuel < ActiveRecord::Base
26
11
  end
27
12
  end
28
13
 
14
+ extend Earth::Model
15
+
16
+ TABLE_STRUCTURE = <<-EOS
17
+
18
+ CREATE TABLE fuels
19
+ (
20
+ name CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
21
+ physical_units CHARACTER VARYING(255),
22
+ density FLOAT,
23
+ density_units CHARACTER VARYING(255),
24
+ energy_content FLOAT,
25
+ energy_content_units CHARACTER VARYING(255),
26
+ carbon_content FLOAT,
27
+ carbon_content_units CHARACTER VARYING(255),
28
+ oxidation_factor FLOAT,
29
+ biogenic_fraction FLOAT,
30
+ co2_emission_factor FLOAT,
31
+ co2_emission_factor_units CHARACTER VARYING(255),
32
+ co2_biogenic_emission_factor FLOAT,
33
+ co2_biogenic_emission_factor_units CHARACTER VARYING(255)
34
+ );
35
+
36
+ EOS
37
+
38
+ self.primary_key = "name"
39
+
40
+ has_many :fuel_years, :foreign_key => 'fuel_name'
41
+
29
42
  def latest_fuel_year
30
43
  fuel_years.find_by_year(fuel_years.maximum('year'))
31
44
  end
@@ -1,9 +1,7 @@
1
+ require 'earth/fuel/fuel_year'
2
+
1
3
  Fuel.class_eval do
2
4
  data_miner do
3
- process "Start from scratch" do
4
- delete_all
5
- end
6
-
7
5
  process "Ensure FuelYear is populated" do
8
6
  FuelYear.run_data_miner!
9
7
  end
@@ -1,11 +1,25 @@
1
+ require 'earth/model'
2
+
3
+ require 'earth/fuel/fuel_type'
4
+
1
5
  class FuelPrice < ActiveRecord::Base
6
+ extend Earth::Model
7
+
8
+ TABLE_STRUCTURE = <<-EOS
9
+
10
+ CREATE TABLE fuel_prices
11
+ (
12
+ name CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
13
+ price FLOAT,
14
+ price_units CHARACTER VARYING(255)
15
+ );
16
+
17
+ EOS
18
+
2
19
  self.primary_key = "name"
3
20
 
4
21
  belongs_to :fuel_type, :foreign_key => 'name' # weird
5
22
 
6
- col :name
7
- col :price, :type => :float
8
- col :price_units
9
23
 
10
24
  warn_unless_size 34
11
25
  end
@@ -1,5 +1,28 @@
1
+ require 'falls_back_on'
2
+
3
+ require 'earth/model'
4
+
5
+ require 'earth/fuel/fuel_price'
6
+
1
7
  # DEPRECATED but FuelPurchase still uses this
2
8
  class FuelType < ActiveRecord::Base
9
+ extend Earth::Model
10
+
11
+ TABLE_STRUCTURE = <<-EOS
12
+
13
+ CREATE TABLE fuel_types
14
+ (
15
+ name CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
16
+ emission_factor FLOAT,
17
+ emission_factor_units CHARACTER VARYING(255),
18
+ density FLOAT,
19
+ density_units CHARACTER VARYING(255),
20
+ average_purchase_volume FLOAT,
21
+ average_purchase_volume_units CHARACTER VARYING(255)
22
+ );
23
+
24
+ EOS
25
+
3
26
  self.primary_key = "name"
4
27
 
5
28
  has_many :prices, :class_name => 'FuelPrice', :foreign_key => 'name' # weird
@@ -13,17 +36,5 @@ class FuelType < ActiveRecord::Base
13
36
  prices.average :price
14
37
  end
15
38
 
16
- col :name
17
- col :emission_factor, :type => :float
18
- col :emission_factor_units
19
- col :density, :type => :float
20
- col :density_units
21
- col :average_purchase_volume, :type => :float
22
- col :average_purchase_volume_units
23
- # col :energy_content, :type => :float
24
- # col :energy_content_units
25
- # col :carbon_content, :type => :float
26
- # col :carbon_content_units
27
-
28
39
  warn_unless_size 36
29
40
  end
@@ -1,21 +1,35 @@
1
+ require 'earth/model'
2
+
3
+ require 'earth/fuel/fuel'
4
+
1
5
  class FuelYear < ActiveRecord::Base
6
+ extend Earth::Model
7
+
8
+ TABLE_STRUCTURE = <<-EOS
9
+
10
+ CREATE TABLE fuel_years
11
+ (
12
+ name CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
13
+ fuel_name CHARACTER VARYING(255),
14
+ year INTEGER,
15
+ energy_content FLOAT,
16
+ energy_content_units CHARACTER VARYING(255),
17
+ carbon_content FLOAT,
18
+ carbon_content_units CHARACTER VARYING(255),
19
+ oxidation_factor FLOAT,
20
+ biogenic_fraction FLOAT,
21
+ co2_emission_factor FLOAT,
22
+ co2_emission_factor_units CHARACTER VARYING(255),
23
+ co2_biogenic_emission_factor FLOAT,
24
+ co2_biogenic_emission_factor_units CHARACTER VARYING(255)
25
+ );
26
+
27
+ EOS
28
+
2
29
  self.primary_key = "name"
3
30
 
4
31
  belongs_to :fuel, :foreign_key => 'fuel_name'
5
32
 
6
- col :name
7
- col :fuel_name
8
- col :year, :type => :integer
9
- col :energy_content, :type => :float
10
- col :energy_content_units
11
- col :carbon_content, :type => :float
12
- col :carbon_content_units
13
- col :oxidation_factor, :type => :float
14
- col :biogenic_fraction, :type => :float
15
- col :co2_emission_factor, :type => :float
16
- col :co2_emission_factor_units
17
- col :co2_biogenic_emission_factor, :type => :float
18
- col :co2_biogenic_emission_factor_units
19
33
 
20
34
  # FIXME TODO verify fuel name is in Fuel
21
35
  # verify "Fuel name should never be missing" do
@@ -1,4 +1,22 @@
1
+ require 'earth/model'
2
+
1
3
  class GreenhouseGas < ActiveRecord::Base
4
+ extend Earth::Model
5
+
6
+ TABLE_STRUCTURE = <<-EOS
7
+
8
+ CREATE TABLE greenhouse_gases
9
+ (
10
+ name CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
11
+ abbreviation CHARACTER VARYING(255),
12
+ ipcc_report CHARACTER VARYING(255),
13
+ time_horizon INTEGER,
14
+ time_horizon_units CHARACTER VARYING(255),
15
+ global_warming_potential INTEGER
16
+ );
17
+
18
+ EOS
19
+
2
20
  self.primary_key = "name"
3
21
 
4
22
  class << self
@@ -7,12 +25,6 @@ class GreenhouseGas < ActiveRecord::Base
7
25
  end
8
26
  end
9
27
 
10
- col :name
11
- col :abbreviation
12
- col :ipcc_report
13
- col :time_horizon, :type => :integer
14
- col :time_horizon_units
15
- col :global_warming_potential, :type => :integer
16
28
 
17
29
  # verify "Abbreviation and IPCC report should never be missing" do
18
30
  # GreenhouseGas.all.each do |record|
@@ -1,3 +1,3 @@
1
1
  # lib/earth/hospitality.rb
2
2
  require 'earth'
3
- Earth.require_related __FILE__
3
+ Earth::Loader.require_related __FILE__
@@ -1,64 +1,76 @@
1
+ require 'earth/model'
2
+
1
3
  class CommercialBuildingEnergyConsumptionSurveyResponse < ActiveRecord::Base
4
+ extend Earth::Model
5
+
6
+ TABLE_STRUCTURE = <<-EOS
7
+
8
+ CREATE TABLE cbecs_responses
9
+ (
10
+ id INTEGER NOT NULL PRIMARY KEY,
11
+ census_region_number INTEGER,
12
+ census_division_number INTEGER,
13
+ climate_zone_number INTEGER,
14
+ heating_degree_days FLOAT,
15
+ heating_degree_days_units CHARACTER VARYING(255),
16
+ cooling_degree_days FLOAT,
17
+ cooling_degree_days_units CHARACTER VARYING(255),
18
+ construction_year INTEGER,
19
+ area FLOAT,
20
+ area_units CHARACTER VARYING(255),
21
+ floors INTEGER,
22
+ lodging_rooms INTEGER,
23
+ percent_cooled FLOAT,
24
+ food_prep_room BOOLEAN,
25
+ laundry_onsite BOOLEAN,
26
+ indoor_pool BOOLEAN,
27
+ principal_activity CHARACTER VARYING(255),
28
+ detailed_activity CHARACTER VARYING(255),
29
+ first_activity CHARACTER VARYING(255),
30
+ second_activity CHARACTER VARYING(255),
31
+ third_activity CHARACTER VARYING(255),
32
+ first_activity_share FLOAT,
33
+ second_activity_share FLOAT,
34
+ third_activity_share FLOAT,
35
+ months_used INTEGER,
36
+ weekly_hours INTEGER,
37
+ electricity_use FLOAT,
38
+ electricity_use_units CHARACTER VARYING(255),
39
+ electricity_energy FLOAT,
40
+ electricity_energy_units CHARACTER VARYING(255),
41
+ natural_gas_use FLOAT,
42
+ natural_gas_use_units CHARACTER VARYING(255),
43
+ natural_gas_energy FLOAT,
44
+ natural_gas_energy_units CHARACTER VARYING(255),
45
+ fuel_oil_use FLOAT,
46
+ fuel_oil_use_units CHARACTER VARYING(255),
47
+ fuel_oil_energy FLOAT,
48
+ fuel_oil_energy_units CHARACTER VARYING(255),
49
+ district_heat_use FLOAT,
50
+ district_heat_use_units CHARACTER VARYING(255),
51
+ district_heat_energy FLOAT,
52
+ district_heat_energy_units CHARACTER VARYING(255),
53
+ stratum INTEGER,
54
+ pair INTEGER,
55
+ weighting FLOAT,
56
+ room_nights FLOAT,
57
+ /* what follow are for lodging fuzzy weighting */
58
+ electricity_per_room_night FLOAT,
59
+ electricity_per_room_night_units CHARACTER VARYING(255),
60
+ natural_gas_per_room_night FLOAT,
61
+ natural_gas_per_room_night_units CHARACTER VARYING(255),
62
+ fuel_oil_per_room_night FLOAT,
63
+ fuel_oil_per_room_night_units CHARACTER VARYING(255),
64
+ district_heat_per_room_night FLOAT,
65
+ district_heat_per_room_night_units CHARACTER VARYING(255)
66
+ );
67
+
68
+ EOS
69
+
2
70
  self.primary_key = "id"
3
71
  self.table_name = :cbecs_responses
4
72
 
5
73
  def self.lodging_records
6
74
  where(:detailed_activity => ['Hotel', 'Motel or inn'], :first_activity => nil)
7
75
  end
8
-
9
- col :id, :type => :integer
10
- col :census_region_number, :type => :integer
11
- col :census_division_number, :type => :integer
12
- col :climate_zone_number, :type => :integer
13
- col :heating_degree_days, :type => :float
14
- col :heating_degree_days_units
15
- col :cooling_degree_days, :type => :float
16
- col :cooling_degree_days_units
17
- col :construction_year, :type => :integer
18
- col :area, :type => :float
19
- col :area_units
20
- col :floors, :type => :integer
21
- col :lodging_rooms, :type => :integer
22
- col :percent_cooled, :type => :float
23
- col :food_prep_room, :type => :boolean
24
- col :laundry_onsite, :type => :boolean
25
- col :indoor_pool, :type => :boolean
26
- col :principal_activity
27
- col :detailed_activity
28
- col :first_activity
29
- col :second_activity
30
- col :third_activity
31
- col :first_activity_share, :type => :float
32
- col :second_activity_share, :type => :float
33
- col :third_activity_share, :type => :float
34
- col :months_used, :type => :integer
35
- col :weekly_hours, :type => :integer
36
- col :electricity_use, :type => :float
37
- col :electricity_use_units
38
- col :electricity_energy, :type => :float
39
- col :electricity_energy_units
40
- col :natural_gas_use, :type => :float
41
- col :natural_gas_use_units
42
- col :natural_gas_energy, :type => :float
43
- col :natural_gas_energy_units
44
- col :fuel_oil_use, :type => :float
45
- col :fuel_oil_use_units
46
- col :fuel_oil_energy, :type => :float
47
- col :fuel_oil_energy_units
48
- col :district_heat_use, :type => :float
49
- col :district_heat_use_units
50
- col :district_heat_energy, :type => :float
51
- col :district_heat_energy_units
52
- col :stratum, :type => :integer
53
- col :pair, :type => :integer
54
- col :weighting, :type => :float
55
- col :room_nights, :type => :float
56
- col :electricity_per_room_night, :type => :float # for lodging fuzzy weighting
57
- col :electricity_per_room_night_units # for lodging fuzzy weighting
58
- col :natural_gas_per_room_night, :type => :float # for lodging fuzzy weighting
59
- col :natural_gas_per_room_night_units # for lodging fuzzy weighting
60
- col :fuel_oil_per_room_night, :type => :float # for lodging fuzzy weighting
61
- col :fuel_oil_per_room_night_units # for lodging fuzzy weighting
62
- col :district_heat_per_room_night, :type => :float # for lodging fuzzy weighting
63
- col :district_heat_per_room_night_units # for lodging fuzzy weighting
64
76
  end