earth 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (239) hide show
  1. data/Rakefile +9 -21
  2. data/data/rail/ntd_companies.csv +1 -0
  3. data/data/rail/ntd_fuel_consumption.csv +1 -0
  4. data/data/rail/ntd_modes.csv +1 -0
  5. data/data/rail/ntd_service.csv +1 -0
  6. data/errata/flight_segment/bts_errata.csv +6 -0
  7. data/lib/earth.rb +1 -0
  8. data/lib/earth/air/aircraft.rb +3 -5
  9. data/lib/earth/air/airline.rb +2 -3
  10. data/lib/earth/air/airport.rb +4 -5
  11. data/lib/earth/air/bts_aircraft.rb +1 -1
  12. data/lib/earth/air/flight_distance_class.rb +0 -1
  13. data/lib/earth/air/flight_distance_class/data_miner.rb +0 -4
  14. data/lib/earth/air/flight_distance_class_seat_class.rb +0 -1
  15. data/lib/earth/air/flight_segment.rb +12 -13
  16. data/lib/earth/air/flight_segment/data_miner.rb +13 -0
  17. data/lib/earth/automobile/automobile_activity_year.rb +0 -1
  18. data/lib/earth/automobile/automobile_activity_year_type.rb +4 -4
  19. data/lib/earth/automobile/automobile_activity_year_type_fuel.rb +1 -2
  20. data/lib/earth/automobile/automobile_fuel.rb +1 -2
  21. data/lib/earth/automobile/automobile_make.rb +0 -1
  22. data/lib/earth/automobile/automobile_make/data_miner.rb +2 -0
  23. data/lib/earth/automobile/automobile_make_model.rb +1 -2
  24. data/lib/earth/automobile/automobile_make_model_year_variant.rb +0 -1
  25. data/lib/earth/automobile/automobile_make_model_year_variant/data_miner.rb +2 -223
  26. data/lib/earth/automobile/automobile_make_model_year_variant/parser.rb +224 -0
  27. data/lib/earth/automobile/automobile_make_year_fleet.rb +0 -1
  28. data/lib/earth/automobile/automobile_model.rb +0 -1
  29. data/lib/earth/automobile/automobile_size_class.rb +0 -1
  30. data/lib/earth/automobile/automobile_type_fuel.rb +0 -1
  31. data/lib/earth/automobile/automobile_type_fuel_control.rb +0 -1
  32. data/lib/earth/automobile/automobile_type_fuel_year.rb +4 -4
  33. data/lib/earth/automobile/automobile_type_fuel_year_control.rb +7 -15
  34. data/lib/earth/automobile/automobile_year.rb +0 -1
  35. data/lib/earth/bus/bus_class.rb +0 -1
  36. data/lib/earth/bus/bus_fuel.rb +1 -72
  37. data/lib/earth/bus/bus_fuel_control.rb +0 -1
  38. data/lib/earth/bus/bus_fuel_control/data_miner.rb +0 -2
  39. data/lib/earth/bus/bus_fuel_year_control.rb +0 -1
  40. data/lib/earth/bus/bus_fuel_year_control/data_miner.rb +0 -2
  41. data/lib/earth/computation/computation_carrier.rb +1 -11
  42. data/lib/earth/computation/computation_carrier_instance_class.rb +4 -25
  43. data/lib/earth/computation/computation_carrier_region.rb +0 -1
  44. data/lib/earth/computation/computation_carrier_region/data_miner.rb +0 -3
  45. data/lib/earth/diet/diet_class.rb +0 -1
  46. data/lib/earth/diet/food_group.rb +1 -1
  47. data/lib/earth/electricity/electric_market.rb +2 -0
  48. data/lib/earth/electricity/electric_utility.rb +11 -4
  49. data/lib/earth/electricity/electric_utility/data_miner.rb +2 -8
  50. data/lib/earth/electricity/green_button_adoption.rb +2 -1
  51. data/lib/earth/fuel/fuel.rb +20 -81
  52. data/lib/earth/fuel/fuel_year.rb +0 -44
  53. data/lib/earth/fuel/greenhouse_gas.rb +0 -40
  54. data/lib/earth/hospitality/lodging_class.rb +0 -1
  55. data/lib/earth/industry/cbecs_energy_intensity.rb +25 -29
  56. data/lib/earth/industry/cbecs_energy_intensity/data_miner.rb +1 -1
  57. data/lib/earth/industry/industry.rb +1 -2
  58. data/lib/earth/industry/mecs_energy.rb +9 -10
  59. data/lib/earth/industry/mecs_ratio.rb +2 -1
  60. data/lib/earth/industry/merchant_category.rb +1 -0
  61. data/lib/earth/industry/naics_2002.rb +2 -0
  62. data/lib/earth/industry/naics_2002_naics_2007_concordance.rb +1 -0
  63. data/lib/earth/industry/naics_2002_sic_1987_concordance.rb +1 -0
  64. data/lib/earth/industry/naics_2007.rb +1 -0
  65. data/lib/earth/industry/sic_1987.rb +1 -0
  66. data/lib/earth/locality/census_division.rb +1 -3
  67. data/lib/earth/locality/climate_division.rb +0 -1
  68. data/lib/earth/locality/country.rb +1 -2
  69. data/lib/earth/locality/country/data_miner.rb +4 -0
  70. data/lib/earth/locality/egrid_country.rb +0 -1
  71. data/lib/earth/locality/egrid_region.rb +1 -3
  72. data/lib/earth/locality/egrid_subregion.rb +1 -3
  73. data/lib/earth/locality/electricity_mix.rb +2 -4
  74. data/lib/earth/locality/petroleum_administration_for_defense_district.rb +0 -1
  75. data/lib/earth/locality/state.rb +0 -1
  76. data/lib/earth/locality/zip_code.rb +0 -1
  77. data/lib/earth/model.rb +1 -1
  78. data/lib/earth/pet/breed.rb +0 -1
  79. data/lib/earth/pet/breed_gender.rb +0 -1
  80. data/lib/earth/pet/gender.rb +0 -1
  81. data/lib/earth/pet/species.rb +1 -3
  82. data/lib/earth/rail/country_rail_class.rb +0 -1
  83. data/lib/earth/rail/country_rail_traction.rb +0 -1
  84. data/lib/earth/rail/country_rail_traction_class.rb +0 -1
  85. data/lib/earth/rail/national_transit_database_company.rb +1 -3
  86. data/lib/earth/rail/national_transit_database_company/data_miner.rb +1 -1
  87. data/lib/earth/rail/national_transit_database_mode.rb +0 -1
  88. data/lib/earth/rail/national_transit_database_mode/data_miner.rb +1 -1
  89. data/lib/earth/rail/national_transit_database_record.rb +0 -1
  90. data/lib/earth/rail/national_transit_database_record/data_miner.rb +2 -2
  91. data/lib/earth/rail/rail_class.rb +0 -1
  92. data/lib/earth/rail/rail_class/data_miner.rb +5 -4
  93. data/lib/earth/rail/rail_company.rb +0 -1
  94. data/lib/earth/rail/rail_fuel.rb +0 -1
  95. data/lib/earth/rail/rail_traction.rb +0 -1
  96. data/lib/earth/rail/rail_traction/data_miner.rb +2 -8
  97. data/lib/earth/residence/air_conditioner_use.rb +0 -1
  98. data/lib/earth/residence/clothes_machine_use.rb +0 -1
  99. data/lib/earth/residence/dishwasher_use.rb +0 -1
  100. data/lib/earth/residence/residence_appliance.rb +0 -1
  101. data/lib/earth/residence/residence_class.rb +0 -1
  102. data/lib/earth/residence/residence_fuel_price.rb +1 -2
  103. data/lib/earth/residence/urbanity.rb +0 -1
  104. data/lib/earth/shipping/carrier.rb +1 -52
  105. data/lib/earth/shipping/carrier_mode.rb +0 -34
  106. data/lib/earth/shipping/shipment_mode.rb +0 -26
  107. data/lib/earth/tasks.rb +14 -4
  108. data/lib/earth/version.rb +1 -1
  109. data/spec/earth/air/aircraft_spec.rb +9 -1
  110. data/spec/earth/air/airline_spec.rb +2 -2
  111. data/spec/earth/air/airport_spec.rb +1 -2
  112. data/spec/earth/air/bts_aircraft_spec.rb +2 -2
  113. data/spec/earth/air/flight_distance_class_seat_class_spec.rb +22 -0
  114. data/spec/earth/air/flight_distance_class_spec.rb +26 -18
  115. data/spec/earth/air/flight_seat_class_spec.rb +12 -0
  116. data/spec/earth/air/flight_segment_spec.rb +38 -33
  117. data/spec/earth/automobile/automobile_activity_year_spec.rb +20 -14
  118. data/spec/earth/automobile/automobile_activity_year_type_fuel_spec.rb +14 -10
  119. data/spec/earth/automobile/automobile_activity_year_type_spec.rb +28 -20
  120. data/spec/earth/automobile/automobile_fuel_spec.rb +106 -52
  121. data/spec/earth/automobile/automobile_make_model_spec.rb +103 -62
  122. data/spec/earth/automobile/automobile_make_model_year_spec.rb +69 -46
  123. data/spec/earth/automobile/automobile_make_model_year_variant_spec.rb +108 -109
  124. data/spec/earth/automobile/automobile_make_spec.rb +8 -8
  125. data/spec/earth/automobile/automobile_make_year_fleet_spec.rb +10 -6
  126. data/spec/earth/automobile/automobile_make_year_spec.rb +10 -9
  127. data/spec/earth/automobile/automobile_model_spec.rb +3 -0
  128. data/spec/earth/automobile/automobile_size_class_spec.rb +12 -11
  129. data/spec/earth/automobile/automobile_type_fuel_control_spec.rb +9 -9
  130. data/spec/earth/automobile/automobile_type_fuel_spec.rb +23 -18
  131. data/spec/earth/automobile/automobile_type_fuel_year_control_spec.rb +37 -29
  132. data/spec/earth/automobile/automobile_type_fuel_year_spec.rb +35 -36
  133. data/spec/earth/automobile/automobile_year_spec.rb +4 -2
  134. data/spec/earth/bus/bus_class_spec.rb +10 -0
  135. data/spec/earth/bus/bus_fuel_control_spec.rb +3 -5
  136. data/spec/earth/bus/bus_fuel_spec.rb +16 -8
  137. data/spec/earth/bus/bus_fuel_year_control_spec.rb +7 -7
  138. data/spec/earth/computation/computation_carrrier_instance_class_spec.rb +17 -0
  139. data/spec/earth/computation/computation_carrrier_region_spec.rb +10 -0
  140. data/spec/earth/computation/computation_carrrier_spec.rb +17 -0
  141. data/spec/earth/diet/diet_class_spec.rb +14 -0
  142. data/spec/earth/diet/food_group_spec.rb +26 -0
  143. data/spec/earth/electricity/electric_market_spec.rb +4 -5
  144. data/spec/earth/electricity/electric_utility_spec.rb +30 -19
  145. data/spec/earth/electricity/green_button_adoption_spec.rb +29 -7
  146. data/spec/earth/fuel/fuel_spec.rb +88 -14
  147. data/spec/earth/fuel/fuel_year_spec.rb +21 -0
  148. data/spec/earth/fuel/greenhouse_gas_spec.rb +23 -0
  149. data/spec/earth/hospitality/commercial_building_energy_consumption_survey_response_spec.rb +13 -10
  150. data/spec/earth/hospitality/lodging_class_spec.rb +1 -1
  151. data/spec/earth/industry/cbecs_energy_intensity_spec.rb +72 -72
  152. data/spec/earth/industry/industry_spec.rb +16 -9
  153. data/spec/earth/industry/mecs_energy_spec.rb +76 -72
  154. data/spec/earth/industry/mecs_ratio_spec.rb +35 -31
  155. data/spec/earth/industry/merchant_category_spec.rb +7 -5
  156. data/spec/earth/industry/naics_2002_naics_2007_concordance_spec.rb +10 -19
  157. data/spec/earth/industry/naics_2002_sic_1987_concordance_spec.rb +9 -19
  158. data/spec/earth/industry/naics_2002_spec.rb +1 -11
  159. data/spec/earth/industry/naics_2007_spec.rb +2 -11
  160. data/spec/earth/industry/sic_1987_spec.rb +3 -14
  161. data/spec/earth/locality/census_division_spec.rb +25 -0
  162. data/spec/earth/locality/census_region_spec.rb +8 -0
  163. data/spec/earth/locality/climate_division_spec.rb +13 -0
  164. data/spec/earth/locality/country_spec.rb +24 -23
  165. data/spec/earth/locality/egrid_country_spec.rb +7 -6
  166. data/spec/earth/locality/egrid_region_spec.rb +6 -6
  167. data/spec/earth/locality/egrid_subregion_spec.rb +14 -14
  168. data/spec/earth/locality/electricity_mix_spec.rb +17 -17
  169. data/spec/earth/locality/padd_spec.rb +21 -0
  170. data/spec/earth/locality/state_spec.rb +8 -11
  171. data/spec/earth/locality/zip_code_spec.rb +29 -22
  172. data/spec/earth/pet/breed_gender_spec.rb +8 -0
  173. data/spec/earth/pet/breed_spec.rb +8 -0
  174. data/spec/earth/pet/gender_spec.rb +8 -0
  175. data/spec/earth/pet/species_spec.rb +11 -5
  176. data/spec/earth/rail/country_rail_class_spec.rb +16 -0
  177. data/spec/earth/rail/country_rail_traction_class_spec.rb +14 -0
  178. data/spec/earth/rail/country_rail_traction_spec.rb +14 -0
  179. data/spec/earth/rail/national_transit_database_company_spec.rb +103 -0
  180. data/spec/earth/rail/national_transit_database_mode_spec.rb +21 -0
  181. data/spec/earth/rail/national_transit_database_record_spec.rb +31 -0
  182. data/spec/earth/rail/rail_class_spec.rb +8 -0
  183. data/spec/earth/rail/rail_company_spec.rb +20 -0
  184. data/spec/earth/rail/rail_fuel_spec.rb +19 -0
  185. data/spec/earth/rail/rail_traction_spec.rb +8 -0
  186. data/spec/earth/residence/air_conditioner_use_spec.rb +17 -0
  187. data/spec/earth/residence/clothes_machine_use_spec.rb +11 -0
  188. data/spec/earth/residence/dishwasher_use_spec.rb +11 -0
  189. data/spec/earth/residence/residence_appliance_spec.rb +19 -0
  190. data/spec/earth/residence/residence_class_spec.rb +15 -0
  191. data/spec/earth/residence/residence_fuel_price_spec.rb +12 -0
  192. data/spec/earth/residence/residence_fuel_type_spec.rb +18 -0
  193. data/spec/earth/residence/residential_energy_consumption_survey_response_spec.rb +13 -0
  194. data/spec/earth/residence/urbanity_spec.rb +8 -0
  195. data/spec/earth/shipping/carrier_mode_spec.rb +18 -0
  196. data/spec/earth/shipping/carrier_spec.rb +27 -0
  197. data/spec/earth/shipping/shipment_mode_spec.rb +16 -0
  198. data/spec/earth_spec.rb +1 -1
  199. data/spec/factories/airline.rb +0 -1
  200. data/spec/factories/airport.rb +0 -1
  201. data/spec/factories/automobile_activity_year.rb +8 -0
  202. data/spec/factories/automobile_activity_year_type.rb +8 -0
  203. data/spec/factories/automobile_activity_year_type_fuel.rb +9 -0
  204. data/spec/factories/automobile_fuel.rb +15 -0
  205. data/spec/factories/automobile_make.rb +9 -0
  206. data/spec/factories/automobile_make_model.rb +10 -0
  207. data/spec/factories/automobile_make_model_year.rb +9 -0
  208. data/spec/factories/automobile_model.rb +9 -0
  209. data/spec/factories/automobile_type_fuel.rb +7 -0
  210. data/spec/factories/automobile_type_fuel_control.rb +16 -0
  211. data/spec/factories/automobile_type_fuel_year.rb +9 -0
  212. data/spec/factories/automobile_type_fuel_year_control.rb +11 -0
  213. data/spec/factories/bus_fuel.rb +7 -0
  214. data/spec/factories/bus_fuel_year_control.rb +9 -0
  215. data/spec/factories/cbecs_energy_intensity.rb +15 -0
  216. data/spec/factories/commercial_building_energy_consumption_survey_response.rb +10 -0
  217. data/spec/factories/electric_utility.rb +8 -0
  218. data/spec/factories/flight_distance_class.rb +8 -0
  219. data/spec/factories/flight_segment.rb +0 -1
  220. data/spec/factories/food_group.rb +8 -0
  221. data/spec/factories/fuel.rb +8 -0
  222. data/spec/factories/fuel_year.rb +8 -0
  223. data/spec/factories/green_button_adoption.rb +8 -0
  224. data/spec/factories/greenhouse_gas.rb +7 -0
  225. data/spec/factories/industry.rb +9 -0
  226. data/spec/factories/mecs_energy.rb +15 -0
  227. data/spec/factories/mecs_ratio.rb +15 -0
  228. data/spec/factories/national_transit_database_company.rb +8 -0
  229. data/spec/factories/national_transit_database_mode.rb +8 -0
  230. data/spec/factories/national_transit_database_record.rb +9 -0
  231. data/spec/factories/residence_appliance.rb +7 -0
  232. data/spec/factories/zip_code.rb +9 -0
  233. data/spec/spec_helper.rb +36 -19
  234. metadata +346 -66
  235. data/lib/earth/acronyms.rb +0 -12
  236. data/lib/earth/rail/rail_company_traction.rb +0 -24
  237. data/lib/earth/rail/rail_company_traction/data_miner.rb +0 -4
  238. data/lib/earth/rail/rail_company_traction_class.rb +0 -26
  239. data/lib/earth/rail/rail_company_traction_class/data_miner.rb +0 -4
data/Rakefile CHANGED
@@ -5,32 +5,22 @@ Bundler::GemHelper.install_tasks
5
5
  require 'bueller'
6
6
  Bueller::Tasks.new
7
7
 
8
- desc "Load a console and connect to the test db"
8
+ desc "Load a console"
9
9
  task :console do
10
+ ENV['EARTH_ENV'] ||= 'test'
10
11
  require 'earth'
11
- logger = Logger.new('log/test.log')
12
- DataMiner.logger = ActiveRecord::Base.logger = logger
13
-
14
- case ENV['EARTH_DB_ADAPTER']
15
- when 'mysql'
16
- adapter = 'mysql2'
17
- username = 'root'
18
- password = 'password'
19
- else
20
- adapter = 'postgresql'
21
- username = nil
22
- password = nil
23
- end
24
- ActiveRecord::Base.establish_connection :adapter => adapter, :username => username, :password => password, :database => 'test_earth'
25
- Earth.init :all
26
-
12
+
13
+ DataMiner.logger = ActiveRecord::Base.logger = Logger.new('log/test.log')
14
+ DataMiner.unit_converter = :conversions
15
+
16
+ Earth.init :all, :connect => true
17
+
27
18
  require 'irb'
28
19
  ARGV.clear
29
20
  IRB.start
30
21
  end
31
22
 
32
23
  require 'rspec/core/rake_task'
33
- desc "Run all examples"
34
24
  RSpec::Core::RakeTask.new(:examples) do |c|
35
25
  if ENV['RSPEC_FORMAT']
36
26
  c.rspec_opts = "-Ispec --format #{ENV['RSPEC_FORMAT']}"
@@ -48,10 +38,8 @@ if RUBY_VERSION =~ /^1\.8/
48
38
  end
49
39
  end
50
40
 
51
- desc "Run tests with RSpec"
41
+ desc "Run tests with RSpec - see spec/spec_helper for configuration options e.g. data sanity-checking"
52
42
  task :test => :examples
53
-
54
- desc "Run tests with RSpec"
55
43
  task :default => :test
56
44
 
57
45
  require 'earth/version'
@@ -0,0 +1 @@
1
+ trs_id,name,acronym,zip_code_name,duns_number,source,source_url
@@ -0,0 +1 @@
1
+ trs_id,mode_code,service_code,electricity_kwh,battery_kwh,diesel_gallons,gasoline_gallons,lpg_gallons,lng_gallons,cng_gallons,kerosene_gallons,biodiesel_gallons,other_fuel,other_fuel_description,source,source_url
@@ -0,0 +1 @@
1
+ code,name,rail_mode,source,source_url
@@ -0,0 +1 @@
1
+ trs_id,mode_code,service_code,vehicle_or_train_revenue_miles,vehicle_or_train_revenue_hours,passenger_car_revenue_miles,passenger_car_revenue_hours,passengers,passenger_miles,source,source_url
@@ -2,3 +2,9 @@ date,name,email,type,section,action,x,y,condition,notes
2
2
  6/7/11,Ian Hough,ian@brighterplanet.com,meta,Intended use,,http://www.transtats.bts.gov/DL_SelectFields.asp?Table_ID=293
3
3
  6/7/11,Ian Hough,ian@brighterplanet.com,technical,UNIQUE_CARRIER,replace,/^$/i,0OQ,in may 2009,unique carrier code for OpenSkies is missing in May 2009
4
4
  6/7/11,Ian Hough,ian@brighterplanet.com,technical,UNIQUE_CARRIER,replace,/^$/i,0OQ,in july 2009,unique carrier code for OpenSkies is missing in July 2009
5
+ 8/6/12,Ian Hough,ian@brighterplanet.com,technical,ORIGIN_COUNTRY,replace,/^an$/i,CW,origin iata CUR,deal with netherlands antilles
6
+ 8/6/12,Ian Hough,ian@brighterplanet.com,technical,ORIGIN_COUNTRY,replace,/^an$/i,NL,origin iata BON,deal with netherlands antilles
7
+ 8/6/12,Ian Hough,ian@brighterplanet.com,technical,ORIGIN_COUNTRY,replace,/^an$/i,SX,origin iata SXM,deal with netherlands antilles
8
+ 8/6/12,Ian Hough,ian@brighterplanet.com,technical,DEST_COUNTRY,replace,/^an$/i,CW,destination iata CUR,deal with netherlands antilles
9
+ 8/6/12,Ian Hough,ian@brighterplanet.com,technical,DEST_COUNTRY,replace,/^an$/i,NL,destination iata BON,deal with netherlands antilles
10
+ 8/6/12,Ian Hough,ian@brighterplanet.com,technical,DEST_COUNTRY,replace,/^an$/i,SX,destination iata SXM,deal with netherlands antilles
data/lib/earth.rb CHANGED
@@ -20,6 +20,7 @@ module Earth
20
20
  LIB_DIR = ::File.expand_path '../earth', __FILE__
21
21
  DATA_DIR = ::File.expand_path '../../data', __FILE__
22
22
  ERRATA_DIR = ::File.expand_path '../../errata', __FILE__
23
+ FACTORY_DIR = ::File.expand_path '../../spec/factories', __FILE__
23
24
 
24
25
  mattr_accessor :mine_original_sources
25
26
  mattr_accessor :database_configurations
@@ -1,7 +1,6 @@
1
- require 'fuzzy_match/cached_result'
2
- require 'falls_back_on'
3
-
4
1
  require 'earth/model'
2
+ require 'falls_back_on'
3
+ require 'fuzzy_match/cached_result'
5
4
 
6
5
  require 'earth/air/flight_segment'
7
6
 
@@ -159,7 +158,6 @@ EOS
159
158
  :m1_units => 'kilograms_per_nautical_mile',
160
159
  :b_units => 'kilograms'
161
160
 
162
-
163
161
  warn_if_nulls_except(
164
162
  :passengers,
165
163
  :seats,
@@ -174,6 +172,6 @@ EOS
174
172
  :b_units,
175
173
  :fuel_use_specificity
176
174
  )
177
-
175
+
178
176
  warn_unless_size 437
179
177
  end
@@ -19,11 +19,10 @@ CREATE TABLE airlines
19
19
  EOS
20
20
 
21
21
  self.primary_key = "name"
22
-
22
+
23
23
  has_many :flight_segments,
24
24
  :primary_key => :bts_code,
25
25
  :foreign_key => :airline_bts_code
26
26
 
27
-
28
- warn_unless_size 1523 # note: this is overridden in data1, which imports extra airlines from proprietary data
27
+ warn_unless_size 1524 # this is overridden in data1, which imports extra airlines from proprietary data
29
28
  end
@@ -22,23 +22,22 @@ CREATE TABLE airports
22
22
  );
23
23
 
24
24
  EOS
25
-
25
+
26
26
  self.primary_key = "iata_code"
27
27
 
28
28
  belongs_to :country,
29
29
  :foreign_key => 'country_iso_3166_code',
30
30
  :primary_key => 'iso_3166_code'
31
- has_many :departing_flight_segments,
31
+ has_many :departing_flight_segments, # FIXME TODO consider replacing with a method that also matches ICAO segments by city
32
32
  :class_name => 'FlightSegment',
33
33
  :foreign_key => :origin_airport_iata_code
34
- has_many :arriving_flight_segments,
34
+ has_many :arriving_flight_segments, # FIXME TODO consider replacing with a method that also matches ICAO segments by city
35
35
  :class_name => 'FlightSegment',
36
36
  :foreign_key => :destination_airport_iata_code
37
37
 
38
38
  acts_as_mappable :default_units => :nms,
39
39
  :lat_column_name => :latitude,
40
40
  :lng_column_name => :longitude
41
-
42
-
41
+
43
42
  warn_unless_size 5324
44
43
  end
@@ -15,5 +15,5 @@ EOS
15
15
 
16
16
  self.primary_key = "bts_code"
17
17
 
18
- warn_unless_size 379
18
+ warn_unless_size 378
19
19
  end
@@ -24,6 +24,5 @@ EOS
24
24
  first :conditions => arel_table[:min_distance].lt(distance.to_f).and(arel_table[:max_distance].gteq(distance.to_f))
25
25
  end
26
26
 
27
-
28
27
  warn_unless_size 2
29
28
  end
@@ -7,9 +7,5 @@ FlightDistanceClass.class_eval do
7
7
  store 'min_distance', :units_field_name => 'min_distance_units', :nullify => true
8
8
  store 'max_distance', :units_field_name => 'max_distance_units', :nullify => true
9
9
  end
10
-
11
- # FIXME TODO verify that min_distance >= 0
12
- # FIXME TODO verify that max_distance > 0
13
- # FIXME TODO verify that distance class distance bounds don't overlap
14
10
  end
15
11
  end
@@ -28,6 +28,5 @@ EOS
28
28
  falls_back_on :name => 'fallback',
29
29
  :multiplier => 1.0
30
30
 
31
-
32
31
  warn_unless_size 7
33
32
  end
@@ -1,8 +1,7 @@
1
+ require 'earth/model'
1
2
  require 'falls_back_on'
2
3
  require 'fuzzy_match/cached_result'
3
4
 
4
- require 'earth/model'
5
-
6
5
  require 'earth/air/aircraft'
7
6
  require 'earth/air/airline'
8
7
 
@@ -78,6 +77,14 @@ EOS
78
77
  end
79
78
  end
80
79
 
80
+ def airline
81
+ if airline_bts_code
82
+ Airline.where(:bts_code => airline_bts_code).first
83
+ else
84
+ Airline.where(:icao_code => airline_icao_code).first
85
+ end
86
+ end
87
+
81
88
  falls_back_on :distance => lambda { weighted_average(:distance, :weighted_by => :passengers) }, # 2077.1205 data1 10-12-2010
82
89
  :seats_per_flight => lambda { weighted_average(:seats_per_flight, :weighted_by => :passengers) }, # 144.15653537046 data1 10-12-2010
83
90
  :load_factor => lambda { weighted_average(:load_factor, :weighted_by => :passengers) }, # 0.78073233770097 data1 10-12-2010
@@ -85,7 +92,7 @@ EOS
85
92
 
86
93
  # FIXME remove this - wherever you're trying to create a flight segment, just don't use mass-assignment for the primary key
87
94
  attr_accessible :row_hash
88
-
95
+
89
96
  warn_if_nulls_except(
90
97
  :origin_airport_city,
91
98
  :destination_airport_city,
@@ -93,14 +100,6 @@ EOS
93
100
  :load_factor,
94
101
  :freight_share
95
102
  )
96
-
97
- warn_unless_size 1_254_412
98
-
99
- def airline
100
- if airline_bts_code
101
- Airline.where(:bts_code => airline_bts_code).first
102
- else
103
- Airline.where(:icao_code => airline_icao_code).first
104
- end
105
- end
103
+
104
+ warn_unless_size 1_288_493
106
105
  end
@@ -14,6 +14,19 @@ FlightSegment.class_eval do
14
14
  def in_july_2009?(row)
15
15
  row ['MONTH'].to_i == 7 and row['YEAR'].to_i == 2009
16
16
  end
17
+
18
+ def method_missing(method_id, *args, &block)
19
+ if method_id.to_s =~ /^(origin|destination)_iata_([a-z]{3})\?$/
20
+ regexp = Regexp.new($2, Regexp::IGNORECASE)
21
+ if $1 == "origin"
22
+ args.first['ORIGIN'] =~ regexp
23
+ else
24
+ args.first['DEST'] =~ regexp
25
+ end
26
+ else
27
+ super
28
+ end
29
+ end
17
30
  end
18
31
 
19
32
  URL = 'http://www.transtats.bts.gov/DownLoad_Table.asp'
@@ -30,6 +30,5 @@ EOS
30
30
  end
31
31
  end
32
32
 
33
-
34
33
  warn_unless_size 15
35
34
  end
@@ -24,10 +24,11 @@ EOS
24
24
 
25
25
  # Used by Automobile and AutomobileTrip
26
26
  def self.find_by_type_name_and_closest_year(type_name, year)
27
- if year > maximum(:activity_year)
28
- where(:type_name => type_name, :activity_year => maximum(:activity_year)).first
27
+ candidates = where(:type_name => type_name)
28
+ if year > (max_year = candidates.maximum(:activity_year))
29
+ candidates.where(:activity_year => max_year).first
29
30
  else
30
- where(:type_name => type_name, :activity_year => [year, minimum(:activity_year)].max).first
31
+ candidates.where(:activity_year => [year, candidates.minimum(:activity_year)].max).first
31
32
  end
32
33
  end
33
34
 
@@ -36,6 +37,5 @@ EOS
36
37
  AutomobileActivityYearTypeFuel.where(:activity_year => activity_year, :type_name => type_name)
37
38
  end
38
39
 
39
-
40
40
  warn_unless_size 30
41
41
  end
@@ -23,9 +23,8 @@ EOS
23
23
 
24
24
  # Used by AutomobileFuel to get records from latest activity year
25
25
  def self.latest
26
- where(:activity_year => maximum(:activity_year))
26
+ where :activity_year => maximum(:activity_year)
27
27
  end
28
28
 
29
-
30
29
  warn_unless_size 120
31
30
  end
@@ -1,6 +1,5 @@
1
- require 'falls_back_on'
2
-
3
1
  require 'earth/model'
2
+ require 'falls_back_on'
4
3
 
5
4
  require 'earth/automobile/automobile_type_fuel'
6
5
  require 'earth/fuel/fuel'
@@ -21,6 +21,5 @@ EOS
21
21
  # for calculating fuel efficiency
22
22
  has_many :make_years, :foreign_key => :make_name, :primary_key => :name, :class_name => 'AutomobileMakeYear'
23
23
 
24
-
25
24
  warn_unless_size 81
26
25
  end
@@ -1,3 +1,5 @@
1
+ require 'earth/automobile/automobile_make_year'
2
+
1
3
  AutomobileMake.class_eval do
2
4
  data_miner do
3
5
  process "Ensure AutomobileMakeYear is populated" do
@@ -43,7 +43,7 @@ EOS
43
43
  end
44
44
 
45
45
  # use original model name if fuel suffix didn't help
46
- make_model ? make_model : AutomobileMakeModel.find_by_make_name_and_model_name(characteristics[:make].name, characteristics[:model].name)
46
+ make_model ? make_model : find_by_make_name_and_model_name(characteristics[:make].name, characteristics[:model].name)
47
47
  end
48
48
  end
49
49
 
@@ -52,7 +52,6 @@ EOS
52
52
  AutomobileMakeModelYear.where(:make_name => make_name, :model_name => model_name)
53
53
  end
54
54
 
55
-
56
55
  warn_unless_size 2353
57
56
  warn_if_nulls_except :alt_fuel_code
58
57
  warn_if_nulls /alt_fuel_efficiency/, :conditions => 'alt_fuel_code IS NOT NULL'
@@ -51,7 +51,6 @@ EOS
51
51
  # because it will be a bunch of work to include all the columns and the names will be really long and obtuse
52
52
  # -Ian 10/18/2011
53
53
 
54
-
55
54
  warn_unless_size 28433
56
55
  warn_unless_size 1152, :conditions => { :year => 1985 }
57
56
  warn_unless_size 1183, :conditions => { :year => 1986 }
@@ -1,3 +1,5 @@
1
+ require 'earth/automobile/automobile_make_model_year_variant/parser'
2
+
1
3
  AutomobileMakeModelYearVariant.class_eval do
2
4
  # For errata
3
5
  class AutomobileMakeModelYearVariant::Guru
@@ -79,229 +81,6 @@ AutomobileMakeModelYearVariant.class_eval do
79
81
  end
80
82
  end
81
83
 
82
- # To parse the FEG files
83
- class AutomobileMakeModelYearVariant::Parser
84
- attr_reader :year
85
-
86
- TRANSMISSIONS = {
87
- 'A' => 'Automatic',
88
- 'L' => 'Automatic',
89
- 'M' => 'Manual',
90
- 'S' => 'Semi-Automatic',
91
- 'C' => 'Continuously Variable',
92
- 'AM' => 'Automated Manual',
93
- 'SA' => 'Semi-Automatic',
94
- 'CVT' => 'Continuously Variable',
95
- 'SCV' => 'Selectable Continuously Variable',
96
- 'OT' => 'Other'
97
- }
98
-
99
- ENGINE_TYPES = {
100
- '(GUZZLER)' => nil, # "gas guzzler"
101
- '(POLICE)' => nil, # police automobile_variant
102
- '(MPFI)' => 'injection',
103
- '(MPI*)' => 'injection',
104
- '(SPFI)' => 'injection',
105
- '(FFS)' => nil, # doesn't necessarily mean fuel injection
106
- '(TURBO)' => 'turbo',
107
- '(TRBO)' => 'turbo',
108
- '(TC*)' => 'turbo',
109
- '(FFS,TRBO)' => 'turbo',
110
- '(S-CHARGE)' => 'supercharger',
111
- '(SC*)' => 'supercharger',
112
- '(DIESEL)' => nil, # diesel
113
- '(DSL)' => nil, # diesel
114
- '(ROTARY)' => nil, # rotary
115
- '(VARIABLE)' => nil, # variable displacement
116
- '(NO-CAT)' => nil, # no catalytic converter
117
- '(OHC)' => nil, # overhead camshaft
118
- '(OHV)' => nil, # overhead valves
119
- '(16-VALVE)' => nil, # 16V
120
- '(305)' => nil, # 305 cubic inch displacement
121
- '(307)' => nil, # 307 cubic inch displacement
122
- '(M-ENG)' => nil,
123
- '(W-ENG)' => nil,
124
- '(GM-BUICK)' => nil,
125
- '(GM-CHEV)' => nil,
126
- '(GM-OLDS)' => nil,
127
- '(GM-PONT)' => nil
128
- }
129
-
130
- FUEL_CODES = {
131
- 'BE' => 'EL', # battery electric
132
- 'CNG' => 'C', # CNG
133
- 'DU' => 'D', # diesel (ultra-low sulphur)
134
- 'E' => 'E', # ethanol
135
- 'EL' => 'EL', # electric
136
- 'G' => 'R', # regular gasoline
137
- 'GP' => 'P', # premium gasoline recommended
138
- 'GPR' => 'P', # premium gasoline required
139
- 'GM' => 'P', # midgrade gasoline recommended
140
- 'H' => 'H', # hydrogen
141
- 'PE' => 'EL' # plug-in electric
142
- }
143
-
144
- CLASS_CODES = {
145
- '1' => 'Two seaters',
146
- '2' => 'Minicompact cars',
147
- '3' => 'Subcompact cars',
148
- '4' => 'Compact cars',
149
- '5' => 'Midsize cars',
150
- '6' => 'Large cars',
151
- '7' => 'Small station wagons',
152
- '8' => 'Midsize station wagons',
153
- '9' => 'Large station wagons',
154
- '10' => 'Small pickup trucks 2WD',
155
- '11' => 'Small pickup trucks 4WD',
156
- '12' => 'Standard pickup trucks 2WD',
157
- '13' => 'Standard pickup trucks 4WD',
158
- '14' => 'Cargo vans',
159
- '15' => 'Passenger vans',
160
- '16' => nil,
161
- '17' => 'Special purpose vehicles 2WD',
162
- '18' => 'Special purpose vehicles 4WD',
163
- '19' => 'Special purpose vehicles'
164
- }
165
-
166
- def initialize(options = {})
167
- options = options.stringify_keys
168
- @year = options['year']
169
- end
170
-
171
- def apply(row)
172
- # Pre-2010 fuel efficiencies need to be adjusted downwards to reflect real-world driving
173
- # We do this by applying equations to the *unadjusted* city and highway fuel efficiency
174
- # Source for the equations is EPA Fuel Economy Trends report Appendix A
175
- # Starting in 2008 we could use the *adjusted* values from the FEG but this would require writing a new case for 2008 and 2009
176
- # Starting in 2010 we use the *adjusted* fuel efficiencies from the FEG
177
- case year
178
- when (1985..1997)
179
- row.merge!({
180
- 'make_name' => row['carline_mfr_name'],
181
- 'model_name' => row['carline_name'],
182
- 'year' => year,
183
- 'transmission' => TRANSMISSIONS[row['model_trans'][0,1].to_s],
184
- 'speeds' => (row['model_trans'][1,1] == 'V') ? 'variable' : row['model_trans'][1,1],
185
- 'drive' => row['drive_system'],
186
- 'fuel_code' => row['fuel_type'],
187
- 'fuel_efficiency_city' => 1.0 / (0.003259 + (1.1805 / row['unadj_city_mpg'].to_f)), # adjust for real-world driving
188
- 'fuel_efficiency_highway' => 1.0 / (0.001376 + (1.3466 / row['unadj_hwy_mpg'].to_f)), # adjust for real-world driving
189
- 'cylinders' => row['no_cyl'],
190
- 'displacement' => _displacement(row),
191
- 'turbo' => _turbo(row),
192
- 'supercharger' => [ENGINE_TYPES[row['engine_desc1'].to_s], ENGINE_TYPES[row['engine_desc2'].to_s]].flatten.include?('supercharger'),
193
- 'injection' => (row['fuel_system'] == 'FI') ? true : false,
194
- 'size_class' => CLASS_CODES[row['size_class']]
195
- })
196
- when (1998..2009)
197
- row.merge!({
198
- 'make_name' => row['Manufacturer'] || row['MFR'],
199
- 'model_name' => (row['carline name'] || row['CAR LINE']).upcase,
200
- 'year' => year,
201
- 'transmission' => TRANSMISSIONS[(row['trans'] || row['TRANS'])[-3,1]],
202
- 'speeds' => ((row['trans'] || row['TRANS'])[-2,1] == 'V') ? 'variable' : (row['trans'] || row['TRANS'])[-2,1],
203
- 'drive' => ((row['drv'] || row['DRIVE SYS']) + 'WD').gsub('.0', ''),
204
- 'fuel_code' => row['fl'] || row['FUEL TYPE'],
205
- 'fuel_efficiency_city' => 1.0 / (0.003259 + (1.1805 / (row['ucty'] || row['UNRND CITY (EPA)']).to_f)), # adjust for real-world driving
206
- 'fuel_efficiency_highway' => 1.0 / (0.001376 + (1.3466 / (row['uhwy'] || row['UNRND HWY (EPA)']).to_f)), # adjust for real-world driving
207
- 'cylinders' => row['cyl'] || row['NUMB CYL'],
208
- 'displacement' => row['displ'] || row['DISPLACEMENT'],
209
- 'turbo' => ((row['T'] || row['TURBO']) == 'T' || (row['carline name'] || row['CAR LINE']).downcase.include?('turbo')) ? true : false,
210
- 'supercharger' => (row['S'] || row['SPCHGR']) == 'S',
211
- 'injection' => true,
212
- 'size_class' => row['Class'] || row['CLASS']
213
- })
214
- else # 2010..present
215
- row.merge!({
216
- 'make_name' => row['Division'],
217
- 'model_name' => row['Carline'].upcase,
218
- 'year' => year,
219
- 'transmission' => TRANSMISSIONS[row['Trans']],
220
- 'speeds' => row['# Gears'].to_i,
221
- 'drive' => row['Drive Sys'] + 'WD',
222
- 'fuel_code' => FUEL_CODES[row['Fuel Usage - Conventional Fuel']],
223
- 'fuel_efficiency_city' => row['City FE (Guide) - Conventional Fuel'],
224
- 'fuel_efficiency_highway' => row['Hwy FE (Guide) - Conventional Fuel'],
225
- 'alt_fuel_code' => FUEL_CODES[row[' Fuel2 Usage - Alternative Fuel']],
226
- 'alt_fuel_efficiency_city' => row['City2 FE (Guide) - Alternative Fuel'],
227
- 'alt_fuel_efficiency_highway' => row['Hwy2 Fuel FE (Guide) - Alternative Fuel'],
228
- 'cylinders' => row['# Cyl'],
229
- 'displacement' => row['Eng Displ'],
230
- 'turbo' => row['Air Aspir Method'] == 'TC',
231
- 'supercharger' => row['Air Aspir Method'] == 'SC',
232
- 'injection' => row['# Cyl'].present? ? true : false,
233
- 'size_class' => row['Carline Class Desc']
234
- })
235
- end
236
- end
237
-
238
- def _displacement(row)
239
- optional_displacement = row['opt_disp'].gsub(/[\(\)]/, '').strip.to_s
240
- if optional_displacement =~ /^(\d\.\d)L$/
241
- $1.to_f
242
- elsif optional_displacement =~ /^(\d{4})CC$/
243
- ($1.to_f / 1000).round(1)
244
- else
245
- row['disp_cub_in'].to_f.cubic_inches.to(:litres).round(1)
246
- end
247
- end
248
-
249
- def _turbo(row)
250
- engine_types = [ENGINE_TYPES[row['engine_desc1'].to_s], ENGINE_TYPES[row['engine_desc2'].to_s]]
251
- engine_types << (row['model_name'].to_s.downcase.include?('turbo') ? 'turbo' : nil)
252
- engine_types.flatten.include?('turbo')
253
- end
254
-
255
- # for the 1985-1997 fuel economy guides
256
- ::FixedWidth.define :fuel_economy_guide do |d|
257
- d.rows do |row|
258
- row.trap { true } # there's only one section
259
- row.column 'active_year', 4, :type => :integer # ACTIVE YEAR
260
- row.column 'state_code', 1, :type => :string # STATE CODE: F=49-STATE,C=CALIFORNIA
261
- row.column 'size_class', 2, :type => :integer # CARLINE CLASS CODE
262
- row.column 'carline_mfr_code', 3, :type => :integer # CARLINE MANUFACTURER CODE
263
- row.column 'carline_name', 28, :type => :string # CARLINE NAME
264
- row.column 'disp_cub_in', 4, :type => :integer # DISP CUBIC INCHES
265
- row.column 'fuel_system', 2, :type => :string # FUEL SYSTEM: 'FI' FOR FUEL INJECTION, 2-DIGIT INTEGER VALUE FOR #OF VENTURIES IF CARBURETOR SYSTEM.
266
- row.column 'model_trans', 6, :type => :string # TRANSMISSION TYPE
267
- row.column 'no_cyl', 2, :type => :integer # NUMBER OF ENGINE CYLINDERS
268
- row.column 'date_time', 12, :type => :string # DATE AND TIME RECORD ENTERED -YYMMDDHHMMSS (YEAR, MONTH, DAY, HOUR, MINUTE, SECOND)
269
- row.column 'release_date', 6, :type => :string # RELEASE DATE - YYMMDD (YEAR, MONTH, DAY)
270
- row.column 'vi_mfr_code', 3, :type => :integer # VI MANUFACTURER CODE
271
- row.column 'carline_code', 5, :type => :integer # CARLINE CODE
272
- row.column 'basic_eng_id', 5, :type => :integer # BASIC ENGINE INDEX
273
- row.column 'carline_mfr_name', 32, :type => :string # CARLINE MANUFACTURER NAME
274
- row.column 'suppress_code', 1, :type => :integer # SUPPRESSION CODE (NO SUPPRESSED RECORD IF FOR PUBLIC ACCESS)
275
- row.column 'city_mpg', 3, :type => :integer # ESTIMATED (CITY) MILES PER GALLON - 90% OF UNADJUSTED VALUE
276
- row.spacer 2
277
- row.column 'highway_mpg', 3, :type => :integer # ESTIMATED (HWY) MILES PER GALLON - 78% OF UNADJUSTED VALUE
278
- row.spacer 2
279
- row.column 'combined_mpg', 3, :type => :integer # COMBINED MILES PER GALLON
280
- row.spacer 2
281
- row.column 'unadj_city_mpg', 3, :type => :integer # UNADJUSTED CITY MILES PER GALLON
282
- row.spacer 2
283
- row.column 'unadj_hwy_mpg', 3, :type => :integer # UNADJUSTED HIGHWAY MILES PER GALLON
284
- row.spacer 2
285
- row.column 'unadj_comb_mpg', 3, :type => :integer # UNADJUSTED COMBINED MILES PER GALLON
286
- row.spacer 2
287
- row.column 'ave_anl_fuel', 6, :type => :integer # "$" in col 147, Annual Fuel Cost starting col 148 in I5
288
- row.column 'opt_disp', 8, :type => :string # OPTIONAL DISPLACEMENT
289
- row.column 'engine_desc1', 10, :type => :string # ENGINE DESCRIPTION 1
290
- row.column 'engine_desc2', 10, :type => :string # ENGINE DESCRIPTION 2
291
- row.column 'engine_desc3', 10, :type => :string # ENGINE DESCRIPTION 3
292
- row.column 'body_type_2d', 10, :type => :string # BODY TYPE 2 DOOR - IF THE BODY TYPE APPLIES IT WILL TAKE THE FORM '2DR-PPP/LL' WHERE PPP=PASSENGER INTERIOR VOLUME AND LL=LUGGAGE INTERIOR VOLUME.
293
- row.column 'body_type_4d', 10, :type => :string # BODY TYPE 4 DOOR - IF THE BODY TYPE APPLIES IT WILL TAKE THE FORM '4DR-PPP/LL' WHERE PPP=PASSENGER INTERIOR VOLUME AND LL=LUGGAGE INTERIOR VOLUME.
294
- row.column 'body_type_hbk', 10, :type => :string # BODY TYPE HBK - IF THE BODY TYPE APPLIES IT WILL TAKE THE FORM 'HBK-PPP/LL' WHERE PPP=PASSENGER INTERIOR VOLUME AND LL=LUGGAGE INTERIOR VOLUME.
295
- row.column 'puerto_rico', 1, :type => :string # '*' IF FOR PUERTO RICO SALES ONLY
296
- row.column 'overdrive', 4, :type => :string # OVERDRIVE: ' OD ' FOR OVERDRIVE, 'EOD ' FOR ELECTRICALLY OPERATED OVERDRIVE AND 'AEOD' FOR AUTOMATIC OVERDRIVE
297
- row.column 'drive_system', 3, :type => :string # FWD=FRONT WHEEL DRIVE, RWD=REAR, 4WD=4-WHEEL
298
- row.column 'filler', 1, :type => :string # NOT USED
299
- row.column 'fuel_type', 1, :type => :string # R=REGULAR(UNLEADED), P=PREMIUM, D=DIESEL
300
- row.column 'trans_desc', 15, :type => :string # TRANSMISSION DESCRIPTORS
301
- end
302
- end
303
- end
304
-
305
84
  data_miner do
306
85
  fuel_economy_guides = (1985..1997).inject({}) do |memo, year|
307
86
  yy = year.to_s[2..3]