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,16 +1,31 @@
1
+ require 'earth/model'
2
+
3
+ require 'earth/shipping/carrier'
4
+ require 'earth/shipping/shipment_mode'
5
+
1
6
  class CarrierMode < ActiveRecord::Base
7
+ extend Earth::Model
8
+
9
+ TABLE_STRUCTURE = <<-EOS
10
+
11
+ CREATE TABLE carrier_modes
12
+ (
13
+ name CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
14
+ carrier_name CHARACTER VARYING(255),
15
+ mode_name CHARACTER VARYING(255),
16
+ package_volume FLOAT,
17
+ route_inefficiency_factor FLOAT,
18
+ transport_emission_factor FLOAT,
19
+ transport_emission_factor_units CHARACTER VARYING(255)
20
+ );
21
+
22
+ EOS
23
+
2
24
  self.primary_key = "name"
3
25
 
4
26
  belongs_to :carrier, :foreign_key => 'carrier_name', :primary_key => 'name'
5
27
  belongs_to :mode, :foreign_key => 'mode_name', :primary_key => 'name', :class_name => 'ShipmentMode'
6
28
 
7
- col :name
8
- col :carrier_name
9
- col :mode_name
10
- col :package_volume, :type => :float
11
- col :route_inefficiency_factor, :type => :float
12
- col :transport_emission_factor, :type => :float
13
- col :transport_emission_factor_units
14
29
 
15
30
  # Don't need to check that carrier_name appears in carriers b/c carriers is derived from carrier_modes.carrier_name
16
31
  # Don't need to check that mode_name appears in shipment_modes b/c shipment_modes is derived from carrier_modes.mode_name
@@ -1,12 +1,26 @@
1
+ require 'earth/model'
2
+
3
+ require 'earth/shipping/carrier_mode'
4
+
1
5
  class ShipmentMode < ActiveRecord::Base
6
+ extend Earth::Model
7
+
8
+ TABLE_STRUCTURE = <<-EOS
9
+
10
+ CREATE TABLE shipment_modes
11
+ (
12
+ name CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
13
+ route_inefficiency_factor FLOAT,
14
+ transport_emission_factor FLOAT,
15
+ transport_emission_factor_units CHARACTER VARYING(255)
16
+ );
17
+
18
+ EOS
19
+
2
20
  self.primary_key = "name"
3
21
 
4
22
  has_many :carrier_modes, :foreign_key => 'mode_name', :primary_key => 'name'
5
23
 
6
- col :name
7
- col :route_inefficiency_factor, :type => :float
8
- col :transport_emission_factor, :type => :float
9
- col :transport_emission_factor_units
10
24
 
11
25
  # verify "Route inefficiency factor should be one or more" do
12
26
  # ShipmentMode.all.each do |mode|
@@ -0,0 +1,62 @@
1
+ require 'earth'
2
+ require 'rake'
3
+ require 'active_record/connection_adapters/abstract/connection_specification'
4
+
5
+ module Earth
6
+ class Tasks
7
+ include Rake::DSL
8
+
9
+ def initialize
10
+ init_earth_tasks
11
+ init_bare unless Object.const_defined?('Rails')
12
+
13
+ namespace :db do
14
+ task :create => 'earth:db:create'
15
+ task :drop => 'earth:db:drop'
16
+ task :migrate => 'earth:db:migrate'
17
+ task :seed => 'earth:db:seed'
18
+ end
19
+ end
20
+
21
+ def init_bare
22
+ Object.const_set 'Rails', Earth
23
+
24
+ require 'active_record'
25
+ load 'active_record/railties/databases.rake'
26
+
27
+ Rake::Task['db:load_config'].clear
28
+ Rake::Task['db:create'].clear
29
+ Rake::Task['db:drop'].clear
30
+ Rake::Task['db:migrate'].clear
31
+ Rake::Task['db:seed'].clear
32
+ end
33
+
34
+ def config
35
+ spec = ENV['DATABASE_URL']
36
+ resolver = ActiveRecord::Base::ConnectionSpecification::Resolver.new spec, {}
37
+ resolver.spec.config.stringify_keys
38
+ end
39
+
40
+ def init_earth_tasks
41
+ namespace :earth do
42
+ namespace :db do
43
+ task :create do
44
+ create_database(config)
45
+ end
46
+ task :drop do
47
+ drop_database_and_rescue(config)
48
+ end
49
+ task :load_config do
50
+ Earth.connect
51
+ end
52
+ task :migrate => :load_config do
53
+ Earth.reset_schemas!
54
+ end
55
+ task :seed => :load_config do
56
+ Earth.run_data_miner!
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -1,3 +1,3 @@
1
1
  module Earth
2
- VERSION = "0.12.4"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -0,0 +1,12 @@
1
+ module Earth
2
+ module Warnings
3
+ def Warnings.check_mysql_ansi_mode
4
+ if ::ActiveRecord::Base.connection.adapter_name =~ /mysql/i
5
+ sql_mode = ::ActiveRecord::Base.connection.select_value("SELECT @@GLOBAL.sql_mode") + ::ActiveRecord::Base.connection.select_value("SELECT @@SESSION.sql_mode")
6
+ unless sql_mode.downcase.include? 'pipes_as_concat'
7
+ ::Kernel.warn "[earth gem] Warning: MySQL detected, but PIPES_AS_CONCAT not set. Importing from scratch will fail. Consider setting sql-mode=ANSI in my.cnf."
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+ require 'fileutils'
3
+ require 'earth'
4
+
5
+ describe 'Data Mining', :data_miner => true do
6
+ it 'is successful for each individual model' do
7
+ Earth.init :all
8
+ Earth.resource_models.each do |resource|
9
+ begin
10
+ puts resource.to_s
11
+ script_file = File.join(Dir.pwd, 'miner.rb')
12
+ File.open script_file, 'w' do |f|
13
+ f.puts <<-RUBY
14
+ require 'earth'
15
+ require 'conversions'
16
+ DataMiner.unit_converter = :conversions
17
+ Earth.init :mine_original_sources => true, :connect => true
18
+ require #{File.join(File.dirname(resource.source_file), File.basename(resource.source_file,'.rb')).inspect}
19
+ #{resource.to_s}.run_data_miner!
20
+ RUBY
21
+ end
22
+
23
+ `bundle exec ruby #{script_file}`
24
+ #$?.to_i.should == 0
25
+ ensure
26
+ FileUtils.rm_f script_file
27
+ end
28
+ end
29
+ end
30
+ end
31
+
@@ -2,16 +2,6 @@ require 'spec_helper'
2
2
  require 'earth/air/aircraft'
3
3
 
4
4
  describe Aircraft do
5
- describe 'import', :data_miner => true do
6
- before do
7
- Earth.init :air, :load_data_miner => true, :skip_parent_associations => :true
8
- end
9
-
10
- it 'should import data' do
11
- Aircraft.run_data_miner!
12
- end
13
- end
14
-
15
5
  describe "verify imported data", :sanity => true do
16
6
  it "should have all the data" do
17
7
  Aircraft.count.should == 437
@@ -2,19 +2,9 @@ require 'spec_helper'
2
2
  require 'earth/air/airline'
3
3
 
4
4
  describe Airline do
5
- before :all do
6
- Earth.init :air, :load_data_miner => true, :skip_parent_associations => :true
7
- end
8
-
9
- describe 'import', :data_miner => true do
10
- it 'should import data' do
11
- Airline.run_data_miner!
12
- end
13
- end
14
-
15
5
  describe "verify imported data", :sanity => true do
16
6
  it "should have all the data" do
17
- Airline.count.should == 1523
7
+ Airline.count.should be_within(10).of(1523)
18
8
  end
19
9
  end
20
10
  end
@@ -4,16 +4,6 @@ require 'spec_helper'
4
4
  require 'earth/air/airport'
5
5
 
6
6
  describe Airport do
7
- describe "when importing data", :data_miner => true do
8
- before do
9
- Earth.init :air, :load_data_miner => true, :skip_parent_associations => :true
10
- end
11
-
12
- it "imports all airports" do
13
- Airport.run_data_miner!
14
- end
15
- end
16
-
17
7
  describe "verify imported data", :sanity => true do
18
8
  it "should have all the data" do
19
9
  Airport.count.should == 5324
@@ -2,16 +2,6 @@ require 'spec_helper'
2
2
  require 'earth/air/bts_aircraft'
3
3
 
4
4
  describe BtsAircraft do
5
- describe 'import', :data_miner => true do
6
- before do
7
- Earth.init :air, :load_data_miner => true, :skip_parent_associations => :true
8
- end
9
-
10
- it 'should import data' do
11
- BtsAircraft.run_data_miner!
12
- end
13
- end
14
-
15
5
  describe 'verify imported data', :sanity => true do
16
6
  it 'should have all the data' do
17
7
  BtsAircraft.count.should == 379
@@ -2,16 +2,6 @@ require 'spec_helper'
2
2
  require 'earth/air/flight_distance_class'
3
3
 
4
4
  describe FlightDistanceClass do
5
- describe "when importing data", :data_miner => true do
6
- before do
7
- Earth.init :air, :load_data_miner => true, :skip_parent_associations => :true
8
- end
9
-
10
- it "imports all naics codes" do
11
- FlightDistanceClass.run_data_miner!
12
- end
13
- end
14
-
15
5
  describe "verify imported data", :sanity => true do
16
6
  it "should have all the data" do
17
7
  FlightDistanceClass.count.should == 2
@@ -1,17 +1,9 @@
1
1
  require 'spec_helper'
2
2
  require 'earth/air/flight_segment'
3
+ require 'factories/flight_segment'
4
+ require 'factories/airline'
3
5
 
4
6
  describe FlightSegment do
5
- describe 'import', :data_miner => true do
6
- before do
7
- Earth.init :air, :load_data_miner => true, :skip_parent_associations => :true
8
- end
9
-
10
- it 'should import data' do
11
- FlightSegment.run_data_miner!
12
- end
13
- end
14
-
15
7
  describe "verify imported data", :sanity => true, :flight_segment => true do
16
8
  it "should have all the data" do
17
9
  FlightSegment.where(:year => 2009).count.should == 403_980
@@ -62,9 +54,34 @@ describe FlightSegment do
62
54
  Airline.exists?(:name => name).should == true
63
55
  end
64
56
  end
57
+
58
+ it 'should relate to airline' do
59
+ FlightSegment.any? { |fs| !fs.airline.nil? }.should be_true
60
+ end
65
61
 
66
62
  it "should have aircraft description" do
67
63
  FlightSegment.where(:aircraft_description => nil).count.should == 0
68
64
  end
69
65
  end
66
+
67
+ describe '#airline' do
68
+ it 'finds an airline by BTS code' do
69
+ FactoryGirl.create :airline, :delta
70
+ FactoryGirl.create :airline, :united
71
+
72
+ fs = FactoryGirl.build :flight_segment, :delta
73
+ fs.airline.bts_code.should == 'DL'
74
+ end
75
+ it 'finds an airline by ICAO code' do
76
+ FactoryGirl.create :airline, :delta
77
+ FactoryGirl.create :airline, :united
78
+
79
+ fs = FactoryGirl.build :flight_segment, :delta_icao
80
+ fs.airline.bts_code.should == 'DL'
81
+ end
82
+ it 'returns nil if there is no airline' do
83
+ fs = FactoryGirl.build :flight_segment
84
+ fs.airline.should be_nil
85
+ end
86
+ end
70
87
  end
@@ -3,16 +3,9 @@ require 'earth/automobile/automobile_activity_year'
3
3
 
4
4
  describe AutomobileActivityYear do
5
5
  before :all do
6
- Earth.init :automobile, :load_data_miner => true
7
6
  require 'earth/acronyms'
8
7
  end
9
8
 
10
- describe 'import', :data_miner => true do
11
- it 'should import data' do
12
- AAY.run_data_miner!
13
- end
14
- end
15
-
16
9
  describe 'verify', :sanity => true do
17
10
  it { AAY.count.should == 15 }
18
11
  it { AAY.where("hfc_emission_factor > 0").count.should == AAY.count }
@@ -3,16 +3,9 @@ require 'earth/automobile/automobile_activity_year_type_fuel'
3
3
 
4
4
  describe AutomobileActivityYearTypeFuel do
5
5
  before :all do
6
- Earth.init :automobile, :load_data_miner => true
7
6
  require 'earth/acronyms'
8
7
  end
9
8
 
10
- describe 'import', :data_miner => true do
11
- it 'should import data' do
12
- AAYTF.run_data_miner!
13
- end
14
- end
15
-
16
9
  describe 'verify', :sanity => true do
17
10
  it { AAYTF.count.should == 120 }
18
11
  it { AAYTF.where(:distance => nil).count.should == 0 }
@@ -3,16 +3,9 @@ require 'earth/automobile/automobile_activity_year_type'
3
3
 
4
4
  describe AutomobileActivityYearType do
5
5
  before :all do
6
- Earth.init :automobile, :load_data_miner => true
7
6
  require 'earth/acronyms'
8
7
  end
9
8
 
10
- describe 'import', :data_miner => true do
11
- it 'should import data' do
12
- AAYT.run_data_miner!
13
- end
14
- end
15
-
16
9
  describe 'verify', :sanity => true do
17
10
  it { AAYT.count.should == 30 }
18
11
  it { AAYT.where("hfc_emissions > 0").count.should == AAYT.count }
@@ -4,16 +4,6 @@ require 'earth/automobile'
4
4
  describe AutomobileFuel do
5
5
  let(:fallback) { AutomobileFuel.fallback }
6
6
 
7
- describe 'import', :data_miner => true do
8
- before do
9
- Earth.init :automobile, :load_data_miner => true
10
- end
11
-
12
- it 'should import data without problems' do
13
- AutomobileFuel.run_data_miner!
14
- end
15
- end
16
-
17
7
  describe 'verify imported data', :sanity => true do
18
8
  it { AutomobileFuel.count.should == 12 }
19
9
  it { AutomobileFuel.where(:distance_key => nil).count.should == 0 }
@@ -12,17 +12,9 @@ describe AutomobileMakeModel do
12
12
  let(:f150_ffv_years) { AMMY.where(:make_name => 'Ford', :model_name => 'F150 FFV') }
13
13
 
14
14
  before :all do
15
- Earth.init :automobile, :load_data_miner => true, :skip_parent_associations => true
16
15
  require 'earth/acronyms'
17
16
  end
18
17
 
19
- describe 'import', :data_miner => true do
20
- it 'should import data' do
21
- AMM.run_data_miner!
22
- AMM.count.should == AMM.connection.select_value("SELECT COUNT(DISTINCT make_name, model_name) FROM #{AMMY.quoted_table_name}")
23
- end
24
- end
25
-
26
18
  describe 'verify', :sanity => true do
27
19
  it { AMM.where(:fuel_code => nil).count.should == 0 }
28
20
  it { AMM.where("fuel_efficiency_city > 0").count.should == AMM.count }
@@ -3,17 +3,9 @@ require 'earth/automobile/automobile_make_model_year'
3
3
 
4
4
  describe AutomobileMakeModelYear do
5
5
  before :all do
6
- Earth.init :automobile, :load_data_miner => true, :skip_parent_associations => :true
7
6
  require 'earth/acronyms'
8
7
  end
9
8
 
10
- describe 'import', :data_miner => true do
11
- it 'should import data' do
12
- AMMY.run_data_miner!
13
- AMMY.count.should == AMMY.connection.select_value("SELECT COUNT(DISTINCT make_name, model_name, year) FROM #{AMMYV.quoted_table_name}")
14
- end
15
- end
16
-
17
9
  describe 'verify imported data', :sanity => true do
18
10
  it 'has data from all years' do
19
11
  (1985..2012).each do |year|
@@ -4,17 +4,9 @@ require 'earth/automobile/automobile_make_model_year_variant'
4
4
 
5
5
  describe AutomobileMakeModelYearVariant do
6
6
  before :all do
7
- Earth.init :automobile, :load_data_miner => true
8
7
  require 'earth/acronyms'
9
8
  end
10
9
 
11
- describe 'import', :data_miner => true do
12
- it 'should import data' do
13
- AMMYV.run_data_miner!
14
- AMMYV.count.should == 28433
15
- end
16
- end
17
-
18
10
  describe 'verify imported data', :sanity => true do
19
11
  # confirm we have right data from all years
20
12
  it { AMMYV.where(:year => 1985).count.should == 1152 }