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
@@ -1,18 +1,81 @@
1
1
  require 'spec_helper'
2
- require 'earth/industry/cbecs_energy_intensity'
3
-
4
- def create_cbecs(name, args)
5
- c = CbecsEnergyIntensity.new args
6
- c.name = name
7
- c.save!
8
- end
2
+ require "#{Earth::FACTORY_DIR}/cbecs_energy_intensity"
9
3
 
10
4
  describe CbecsEnergyIntensity do
11
- describe 'verify imported data', :sanity => true do
5
+ describe '.find_by_naics_code_and_census_division_number' do
6
+ it 'finds an exact match' do
7
+ intensity = FactoryGirl.create :cbecs_energy_intensity, :i1111d1
8
+ CbecsEnergyIntensity.find_by_naics_code_and_census_division_number('1111', 1).should == intensity
9
+ end
10
+ it 'finds a parent category when exact code is not present' do
11
+ intensity = FactoryGirl.create :cbecs_energy_intensity, :i1111d1
12
+ CbecsEnergyIntensity.find_by_naics_code_and_census_division_number('11111', 1).should == intensity
13
+ end
14
+ it 'does not find a sibling category' do
15
+ FactoryGirl.create :cbecs_energy_intensity, :i1112d1
16
+ intensity = FactoryGirl.create :cbecs_energy_intensity, :i11d1
17
+ CbecsEnergyIntensity.find_by_naics_code_and_census_division_number('1111', 1).should == intensity
18
+ end
19
+ it 'returns nil if no match found' do
20
+ CbecsEnergyIntensity.find_by_naics_code_and_census_division_number('1111', 1).should be_nil
21
+ end
22
+ end
23
+
24
+ describe '.find_by_naics_code_and_census_region_number' do
25
+ it 'finds an exact match' do
26
+ intensity = FactoryGirl.create :cbecs_energy_intensity, :i1111r1
27
+ CbecsEnergyIntensity.find_by_naics_code_and_census_region_number('1111', 1).should == intensity
28
+ end
29
+ it 'finds a parent category when exact code is not present' do
30
+ intensity = FactoryGirl.create :cbecs_energy_intensity, :i1111r1
31
+ CbecsEnergyIntensity.find_by_naics_code_and_census_region_number('11111', 1).should == intensity
32
+ end
33
+ it 'does not find a sibling category' do
34
+ FactoryGirl.create :cbecs_energy_intensity, :i1112r1
35
+ intensity = FactoryGirl.create :cbecs_energy_intensity, :i11r1
36
+ CbecsEnergyIntensity.find_by_naics_code_and_census_region_number('1111', 1).should == intensity
37
+ end
38
+ it 'returns nil if no match found' do
39
+ CbecsEnergyIntensity.find_by_naics_code_and_census_region_number('1111', 1).should be_nil
40
+ end
41
+ end
42
+
43
+ describe '.find_by_naics_code' do
44
+ it 'finds an exact match' do
45
+ intensity = FactoryGirl.create :cbecs_energy_intensity, :i1111
46
+ CbecsEnergyIntensity.find_by_naics_code('1111').should == intensity
47
+ end
48
+ it 'finds a parent category when exact code is not present' do
49
+ intensity = FactoryGirl.create :cbecs_energy_intensity, :i1111
50
+ CbecsEnergyIntensity.find_by_naics_code('11111').should == intensity
51
+ end
52
+ it 'does not find a sibling category' do
53
+ FactoryGirl.create :cbecs_energy_intensity, :i1112
54
+ intensity = FactoryGirl.create :cbecs_energy_intensity, :i11
55
+ CbecsEnergyIntensity.find_by_naics_code('1111').should == intensity
56
+ end
57
+ it 'returns nil if no match found' do
58
+ CbecsEnergyIntensity.find_by_naics_code('1111').should be_nil
59
+ end
60
+ end
61
+
62
+ describe '#fuel_ratios' do
63
+ it 'makes ratios from fuel energies' do
64
+ cbecs = CbecsEnergyIntensity.new :name => '1', :electricity => 1000, :natural_gas => 2000, :fuel_oil => 500, :district_heat => 0
65
+ cbecs.fuel_ratios.should == {
66
+ :electricity => 0.2857142857142857,
67
+ :natural_gas => 0.5714285714285714,
68
+ :fuel_oil => 0.14285714285714285,
69
+ :district_heat => 0.0
70
+ }
71
+ end
72
+ end
73
+
74
+ describe 'Sanity check', :sanity => true do
12
75
  it 'imports the right number of records' do
13
76
  CbecsEnergyIntensity.count.should == 182
14
77
  end
15
-
78
+
16
79
  #TODO check values
17
80
  it 'checks census divisions' do
18
81
  divisionals = CbecsEnergyIntensity.divisional
@@ -63,67 +126,4 @@ describe CbecsEnergyIntensity do
63
126
  ])
64
127
  end
65
128
  end
66
-
67
- describe '.find_by_naics_code_and_census_division_number' do
68
- it 'finds an exact match' do
69
- CbecsEnergyIntensity.find_by_naics_code_and_census_division_number('445', 2).name.should == '445-1-2'
70
- end
71
- it 'finds a parent category when exact code is not present' do
72
- CbecsEnergyIntensity.find_by_naics_code_and_census_division_number('4451', 2).name.should == '445-1-2'
73
- end
74
- it 'does not find a sibling category' do
75
- create_cbecs '72221-1-2', :naics_code => '72221', :census_division_number => 2, :census_region_number => 1
76
- CbecsEnergyIntensity.find_by_naics_code_and_census_division_number('72229', 2).name.should == '722-1-2'
77
- CbecsEnergyIntensity.delete '72221-1-2'
78
- end
79
- it 'returns nil if no match found' do
80
- CbecsEnergyIntensity.find_by_naics_code_and_census_division_number('48', 2).should be_nil
81
- end
82
- end
83
-
84
- describe '.find_by_naics_code_and_census_region_number' do
85
- it 'finds an exact match' do
86
- CbecsEnergyIntensity.find_by_naics_code_and_census_region_number('445', 2).name.should == '445-2'
87
- end
88
- it 'finds a parent category when exact code is not present' do
89
- CbecsEnergyIntensity.find_by_naics_code_and_census_region_number('4451', 2).name.should == '445-2'
90
- end
91
- it 'does not find a sibling category' do
92
- create_cbecs '72221-2', :naics_code => '72221', :census_region_number => 2
93
- CbecsEnergyIntensity.find_by_naics_code_and_census_region_number('72229', 2).name.should == '722-2'
94
- CbecsEnergyIntensity.delete '72221-2'
95
- end
96
- it 'returns nil if no match found' do
97
- CbecsEnergyIntensity.find_by_naics_code_and_census_region_number('48', 2).should be_nil
98
- end
99
- end
100
-
101
- describe '.find_by_naics_code' do
102
- it 'finds an exact match' do
103
- CbecsEnergyIntensity.find_by_naics_code('445').name.should == '445'
104
- end
105
- it 'finds a parent category when exact code is not present' do
106
- CbecsEnergyIntensity.find_by_naics_code('4451').name.should == '445'
107
- end
108
- it 'does not find a sibling category' do
109
- create_cbecs '72221', :naics_code => '72221'
110
- CbecsEnergyIntensity.find_by_naics_code('72229').name.should == '722'
111
- CbecsEnergyIntensity.delete '72221'
112
- end
113
- it 'returns nil if no match found' do
114
- CbecsEnergyIntensity.find_by_naics_code('48').should be_nil
115
- end
116
- end
117
-
118
- describe '#fuel_ratios' do
119
- it 'makes ratios from fuel energies' do
120
- cbecs = CbecsEnergyIntensity.new :name => '1', :electricity => 1000, :natural_gas => 2000, :fuel_oil => 500, :district_heat => 0
121
- cbecs.fuel_ratios.should == {
122
- :electricity => 0.2857142857142857,
123
- :natural_gas => 0.5714285714285714,
124
- :fuel_oil => 0.14285714285714285,
125
- :district_heat => 0.0
126
- }
127
- end
128
- end
129
129
  end
@@ -1,17 +1,24 @@
1
1
  require 'spec_helper'
2
- require 'earth/industry/industry'
2
+ require "#{Earth::FACTORY_DIR}/industry"
3
3
 
4
4
  describe Industry do
5
- describe "verify imported data", :sanity => true do
6
- it { Industry.count.should == 2341 }
5
+ describe '.format_naics_code(input)' do
6
+ it 'converts input to an integer and then a string' do
7
+ Industry.format_naics_code(42110).should == '42110'
8
+ Industry.format_naics_code('42110a').should == '42110'
9
+ end
7
10
  end
8
11
 
9
- describe "methods" do
10
- it "knows whether it's a trade industry (wholesale or retail trade)" do
11
- Industry.find('42331').trade_industry?.should == true
12
- Industry.find('445110').trade_industry?.should == true
13
- Industry.find('4539').trade_industry?.should == true
14
- Industry.find('33291').trade_industry?.should == false
12
+ describe '#trade_industry?' do
13
+ it "returns true if the industry is wholesale or retail trade" do
14
+ Industry.delete_all
15
+ FactoryGirl.create(:industry, :corn_farming).trade_industry?.should == false
16
+ FactoryGirl.create(:industry, :retail_trade).trade_industry?.should == true
17
+ FactoryGirl.create(:industry, :wholesale_trade).trade_industry?.should == true
15
18
  end
16
19
  end
20
+
21
+ describe "Sanity check", :sanity => true do
22
+ it { Industry.count.should == 2341 }
23
+ end
17
24
  end
@@ -1,78 +1,7 @@
1
1
  require 'spec_helper'
2
- require 'earth/industry/mecs_energy'
3
- require 'earth/industry/industry' # MecsEnergy's custom find by method calls an Industry method
2
+ require "#{Earth::FACTORY_DIR}/mecs_energy"
4
3
 
5
4
  describe MecsEnergy do
6
- describe 'verify imported data', :sanity => true do
7
- it 'should have all the data' do
8
- MecsEnergy.count.should == 395
9
- end
10
- it 'spot checks the data' do
11
- apparel = MecsEnergy.find_by_naics_code '315'
12
- apparel.census_region_number.should be_nil
13
- apparel.energy.should be_within(20_000).of(14770781900)
14
- apparel.energy_units.should == 'megajoules'
15
- apparel.electricity.should be_within(1_000).of(7.trillion_btus.to(:megajoules))
16
- apparel.electricity_units.should == 'megajoules'
17
- apparel.residual_fuel_oil.should == 0
18
- apparel.residual_fuel_oil_units.should == 'megajoules'
19
- apparel.distillate_fuel_oil.should == 0
20
- apparel.distillate_fuel_oil_units.should == 'megajoules'
21
- apparel.natural_gas.should be_within(1_000).of(7.trillion_btus.to(:megajoules))
22
- apparel.natural_gas_units.should == 'megajoules'
23
- apparel.lpg_and_ngl.should == 0
24
- apparel.lpg_and_ngl_units.should == 'megajoules'
25
- apparel.coal.should == 0
26
- apparel.coal_units.should == 'megajoules'
27
- apparel.coke_and_breeze.should == 0
28
- apparel.coke_and_breeze_units.should == 'megajoules'
29
- apparel.other_fuel.should == 0
30
- apparel.other_fuel_units.should == 'megajoules'
31
- end
32
- end
33
-
34
- describe '.find_by_naics_code_and_census_region_number' do
35
- it 'finds an exact match' do
36
- MecsEnergy.find_by_naics_code_and_census_region_number('311221', 2).
37
- name.should == '311221-2'
38
- end
39
- it 'finds a parent category when exact code is not present' do
40
- MecsEnergy.find_by_naics_code_and_census_region_number('3117', 2).
41
- name.should == '311-2'
42
- end
43
- it 'finds same category nationwide when census region is not present' do
44
- MecsEnergy.find_by_naics_code_and_census_region_number('311221', 5).
45
- name.should == '311221-'
46
- end
47
- it 'looks nationwide and at parent codes if fuel ratios is invalid' do
48
- MecsEnergy.find_by_naics_code_and_census_region_number('311221', 1).
49
- name.should == '311221-'
50
- end
51
- it 'finds a parent category rather than a sibling category' do
52
- MecsEnergy.find_by_naics_code_and_census_region_number('311225', 2).
53
- name.should == '3112-2'
54
- end
55
- it 'returns nil if no match found' do
56
- MecsEnergy.find_by_naics_code_and_census_region_number('543211', 2).
57
- should be_nil
58
- end
59
- end
60
-
61
- describe '.find_by_naics_code' do
62
- it 'finds an exact match' do
63
- MecsEnergy.find_by_naics_code('311221').name.should == '311221-'
64
- end
65
- it 'finds a parent category when exact code is not present' do
66
- MecsEnergy.find_by_naics_code('3117').name.should == '311-'
67
- end
68
- it 'finds a parent category rather than a sibling category' do
69
- MecsEnergy.find_by_naics_code('311225').name.should == '3112-'
70
- end
71
- it 'returns nil if no match found' do
72
- MecsEnergy.find_by_naics_code('543211').should be_nil
73
- end
74
- end
75
-
76
5
  describe '#fuel_ratios' do
77
6
  it 'calculates based on sum of all fuels when no fuels are missing' do
78
7
  # Energy < sum all fuels
@@ -207,4 +136,79 @@ describe MecsEnergy do
207
136
  energy.fuel_ratios.should be_nil
208
137
  end
209
138
  end
139
+
140
+ describe '.find_by_naics_code_and_census_region_number' do
141
+ it 'finds an exact match' do
142
+ energy = FactoryGirl.create :mecs_energy, :r1111c1
143
+ MecsEnergy.find_by_naics_code_and_census_region_number('1111', 1).should == energy
144
+ end
145
+ it 'finds a parent category when exact code is not present' do
146
+ energy = FactoryGirl.create :mecs_energy, :r111c1
147
+ MecsEnergy.find_by_naics_code_and_census_region_number('111', 1).should == energy
148
+ end
149
+ it 'finds same category nationwide when census region is not present' do
150
+ energy = FactoryGirl.create :mecs_energy, :r1111
151
+ MecsEnergy.find_by_naics_code_and_census_region_number('1111', 1).should == energy
152
+ end
153
+ it 'keeps looking if fuel ratios is invalid' do
154
+ FactoryGirl.create :mecs_energy, :r1111c2
155
+ energy = FactoryGirl.create :mecs_energy, :r1111
156
+ MecsEnergy.find_by_naics_code_and_census_region_number('1111', 2).should == energy
157
+ end
158
+ it 'finds a parent category rather than a sibling category' do
159
+ FactoryGirl.create :mecs_energy, :r1112c1
160
+ energy = FactoryGirl.create :mecs_energy, :r11c1
161
+ MecsEnergy.find_by_naics_code_and_census_region_number('1111', 1).should == energy
162
+ end
163
+ it 'returns nil if no match found' do
164
+ MecsEnergy.find_by_naics_code_and_census_region_number('1111', 1).should be_nil
165
+ end
166
+ end
167
+
168
+ describe '.find_by_naics_code' do
169
+ it 'finds an exact match' do
170
+ energy = FactoryGirl.create :mecs_energy, :r1111
171
+ MecsEnergy.find_by_naics_code('1111').should == energy
172
+ end
173
+ it 'finds a parent category when exact code is not present' do
174
+ energy = FactoryGirl.create :mecs_energy, :r111
175
+ MecsEnergy.find_by_naics_code('1111').should == energy
176
+ end
177
+ it 'finds a parent category rather than a sibling category' do
178
+ FactoryGirl.create :mecs_energy, :r1112
179
+ energy = FactoryGirl.create :mecs_energy, :r11
180
+ MecsEnergy.find_by_naics_code('1111').should == energy
181
+ end
182
+ it 'returns nil if no match found' do
183
+ MecsEnergy.find_by_naics_code('1111').should be_nil
184
+ end
185
+ end
186
+
187
+ describe 'Sanity check', :sanity => true do
188
+ it 'should have all the data' do
189
+ MecsEnergy.count.should == 395
190
+ end
191
+ it 'spot checks the data' do
192
+ apparel = MecsEnergy.find_by_naics_code '315'
193
+ apparel.census_region_number.should be_nil
194
+ apparel.energy.should be_within(20_000).of(14770781900)
195
+ apparel.energy_units.should == 'megajoules'
196
+ apparel.electricity.should be_within(1_000).of(7.trillion_btus.to(:megajoules))
197
+ apparel.electricity_units.should == 'megajoules'
198
+ apparel.residual_fuel_oil.should == 0
199
+ apparel.residual_fuel_oil_units.should == 'megajoules'
200
+ apparel.distillate_fuel_oil.should == 0
201
+ apparel.distillate_fuel_oil_units.should == 'megajoules'
202
+ apparel.natural_gas.should be_within(1_000).of(7.trillion_btus.to(:megajoules))
203
+ apparel.natural_gas_units.should == 'megajoules'
204
+ apparel.lpg_and_ngl.should == 0
205
+ apparel.lpg_and_ngl_units.should == 'megajoules'
206
+ apparel.coal.should == 0
207
+ apparel.coal_units.should == 'megajoules'
208
+ apparel.coke_and_breeze.should == 0
209
+ apparel.coke_and_breeze_units.should == 'megajoules'
210
+ apparel.other_fuel.should == 0
211
+ apparel.other_fuel_units.should == 'megajoules'
212
+ end
213
+ end
210
214
  end
@@ -1,59 +1,63 @@
1
1
  require 'spec_helper'
2
- require 'earth/industry/mecs_ratio'
3
- require 'earth/industry/industry' # MecsRatio's custom find by method calls an Industry method
2
+ require "#{Earth::FACTORY_DIR}/mecs_ratio"
4
3
 
5
4
  describe MecsRatio do
6
- describe 'verify imported data', :sanity => true do
7
- it 'should have all the data' do
8
- MecsRatio.count.should == 395
9
- end
10
- it 'spot checks the data' do
11
- apparel = MecsRatio.find_by_naics_code '315'
12
- apparel.census_region_number.should be_nil
13
- apparel.energy_per_dollar_of_shipments.should be_within(5e-6).of(0.5.kbtus.to(:megajoules))
14
- apparel.energy_per_dollar_of_shipments_units.should == 'megajoules'
15
- end
16
- end
17
-
18
5
  describe '.find_by_naics_code_and_census_region_number' do
19
6
  it 'finds an exact match' do
20
- MecsRatio.find_by_naics_code_and_census_region_number('311221', 2).
21
- name.should == '311221-2'
7
+ ratio = FactoryGirl.create :mecs_ratio, :r1111c1
8
+ MecsRatio.find_by_naics_code_and_census_region_number('1111', 1).should == ratio
22
9
  end
23
10
  it 'finds a parent category when exact code is not present' do
24
- MecsRatio.find_by_naics_code_and_census_region_number('3117', 2).
25
- name.should == '311-2'
11
+ ratio = FactoryGirl.create :mecs_ratio, :r111c1
12
+ MecsRatio.find_by_naics_code_and_census_region_number('111', 1).should == ratio
26
13
  end
27
14
  it 'finds same category nationwide when census region is not present' do
28
- MecsRatio.find_by_naics_code_and_census_region_number('311221', 5).
29
- name.should == '311221-'
15
+ ratio = FactoryGirl.create :mecs_ratio, :r1111
16
+ MecsRatio.find_by_naics_code_and_census_region_number('1111', 1).should == ratio
30
17
  end
31
- it 'looks nationwide and at parent codes if energy per dollar of shipments is missing' do
32
- MecsRatio.find_by_naics_code_and_census_region_number('313', 4).
33
- name.should == '313-'
18
+ it 'keeps looking if energy per dollar of shipments is missing' do
19
+ FactoryGirl.create :mecs_ratio, :r1111c2
20
+ ratio = FactoryGirl.create :mecs_ratio, :r1111
21
+ MecsRatio.find_by_naics_code_and_census_region_number('1111', 2).should == ratio
34
22
  end
35
23
  it 'finds a parent category rather than a sibling category' do
36
- MecsRatio.find_by_naics_code_and_census_region_number('311225', 2).
37
- name.should == '3112-2'
24
+ FactoryGirl.create :mecs_ratio, :r1112c1
25
+ ratio = FactoryGirl.create :mecs_ratio, :r11c1
26
+ MecsRatio.find_by_naics_code_and_census_region_number('1111', 1).should == ratio
38
27
  end
39
28
  it 'returns nil if no match found' do
40
- MecsRatio.find_by_naics_code_and_census_region_number('543211', 2).
41
- should be_nil
29
+ MecsRatio.find_by_naics_code_and_census_region_number('1111', 1).should be_nil
42
30
  end
43
31
  end
44
32
 
45
33
  describe '.find_by_naics_code' do
46
34
  it 'finds an exact match' do
47
- MecsRatio.find_by_naics_code('311221').name.should == '311221-'
35
+ ratio = FactoryGirl.create :mecs_ratio, :r1111
36
+ MecsRatio.find_by_naics_code('1111').should == ratio
48
37
  end
49
38
  it 'finds a parent category when exact code is not present' do
50
- MecsRatio.find_by_naics_code('3117').name.should == '311-'
39
+ ratio = FactoryGirl.create :mecs_ratio, :r111
40
+ MecsRatio.find_by_naics_code('1111').should == ratio
51
41
  end
52
42
  it 'finds a parent category rather than a sibling category' do
53
- MecsRatio.find_by_naics_code('311225').name.should == '3112-'
43
+ FactoryGirl.create :mecs_ratio, :r1112
44
+ ratio = FactoryGirl.create :mecs_ratio, :r11
45
+ MecsRatio.find_by_naics_code('1111').should == ratio
54
46
  end
55
47
  it 'returns nil if no match found' do
56
- MecsRatio.find_by_naics_code('543211').should be_nil
48
+ MecsRatio.find_by_naics_code('1111').should be_nil
49
+ end
50
+ end
51
+
52
+ describe 'Sanity check', :sanity => true do
53
+ it 'should have all the data' do
54
+ MecsRatio.count.should == 395
55
+ end
56
+ it 'spot checks the data' do
57
+ apparel = MecsRatio.find_by_naics_code '315'
58
+ apparel.census_region_number.should be_nil
59
+ apparel.energy_per_dollar_of_shipments.should be_within(5e-6).of(0.5.kbtus.to(:megajoules))
60
+ apparel.energy_per_dollar_of_shipments_units.should == 'megajoules'
57
61
  end
58
62
  end
59
63
  end
@@ -2,11 +2,13 @@ require 'spec_helper'
2
2
  require 'earth/industry/merchant_category'
3
3
 
4
4
  describe MerchantCategory do
5
- describe 'verify data', :sanity => true do
6
- it 'should import valid data' do
7
- MerchantCategory.count.should > 0
8
- MerchantCategory.first.mcc.to_s.should =~ /^\d+$/
9
- MerchantCategory.first.description.to_s.should_not be_empty
5
+ describe '#name' do
6
+ it "returns the description" do
7
+ MerchantCategory.new(:description => 'Description').name.should == 'Description'
10
8
  end
11
9
  end
10
+
11
+ describe 'Sanity check', :sanity => true do
12
+ it { MerchantCategory.count.should == 285 }
13
+ end
12
14
  end