earth 0.6.6 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/earth.gemspec +1 -1
  2. data/lib/earth/air/flight_distance_class.rb +1 -1
  3. data/lib/earth/air/flight_distance_class/data_miner.rb +3 -2
  4. data/lib/earth/air/flight_seat_class/data_miner.rb +4 -29
  5. data/lib/earth/air/flight_segment.rb +4 -0
  6. data/lib/earth/automobile.rb +1 -0
  7. data/lib/earth/automobile/automobile_fuel/data_miner.rb +3 -3
  8. data/lib/earth/automobile/automobile_type_fuel_year/data_miner.rb +1 -1
  9. data/lib/earth/locality.rb +3 -0
  10. data/lib/earth/locality/country.rb +32 -9
  11. data/lib/earth/locality/country/data_miner.rb +38 -2
  12. data/lib/earth/locality/country_rail_class.rb +18 -0
  13. data/lib/earth/locality/country_rail_class/data_miner.rb +16 -0
  14. data/lib/earth/locality/country_rail_traction.rb +13 -0
  15. data/lib/earth/locality/country_rail_traction/data_miner.rb +34 -0
  16. data/lib/earth/locality/country_rail_traction_class.rb +14 -0
  17. data/lib/earth/locality/country_rail_traction_class/data_miner.rb +35 -0
  18. data/lib/earth/locality/data_miner.rb +3 -0
  19. data/lib/earth/locality/zip_code.rb +9 -7
  20. data/lib/earth/rail.rb +8 -0
  21. data/lib/earth/rail/data_miner.rb +9 -0
  22. data/lib/earth/rail/national_transit_database_company.rb +37 -0
  23. data/lib/earth/rail/national_transit_database_company/data_miner.rb +12 -0
  24. data/lib/earth/rail/national_transit_database_mode.rb +12 -0
  25. data/lib/earth/rail/national_transit_database_mode/data_miner.rb +10 -0
  26. data/lib/earth/rail/national_transit_database_record.rb +41 -0
  27. data/lib/earth/rail/national_transit_database_record/data_miner.rb +57 -0
  28. data/lib/earth/rail/rail_class.rb +2 -63
  29. data/lib/earth/rail/rail_class/data_miner.rb +13 -12
  30. data/lib/earth/rail/rail_company.rb +26 -0
  31. data/lib/earth/rail/rail_company/data_miner.rb +98 -0
  32. data/lib/earth/rail/rail_company_traction.rb +12 -0
  33. data/lib/earth/rail/rail_company_traction/data_miner.rb +4 -0
  34. data/lib/earth/rail/rail_company_traction_class.rb +14 -0
  35. data/lib/earth/rail/rail_company_traction_class/data_miner.rb +4 -0
  36. data/lib/earth/rail/rail_fuel.rb +18 -0
  37. data/lib/earth/rail/rail_fuel/data_miner.rb +36 -0
  38. data/lib/earth/rail/rail_traction.rb +5 -0
  39. data/lib/earth/rail/rail_traction/data_miner.rb +21 -0
  40. data/lib/earth/version.rb +1 -1
  41. data/spec/earth_spec.rb +14 -2
  42. metadata +46 -30
@@ -0,0 +1,4 @@
1
+ RailCompanyTractionClass.class_eval do
2
+ data_miner do
3
+ end
4
+ end
@@ -0,0 +1,18 @@
1
+ class RailFuel < ActiveRecord::Base
2
+ set_primary_key :name
3
+
4
+ belongs_to :fuel, :foreign_key => 'fuel_name'
5
+
6
+ [:density, :density_units, :co2_emission_factor, :co2_emission_factor_units, :co2_biogenic_emission_factor, :co2_biogenic_emission_factor_units].each do |method|
7
+ define_method method do
8
+ fuel.send(method)
9
+ end
10
+ end
11
+
12
+ col :name
13
+ col :fuel_name
14
+ col :ch4_emission_factor, :type => :float
15
+ col :ch4_emission_factor_units
16
+ col :n2o_emission_factor, :type => :float
17
+ col :n2o_emission_factor_units
18
+ end
@@ -0,0 +1,36 @@
1
+ RailFuel.class_eval do
2
+ data_miner do
3
+ import "Rail diesel CH4 and N2O emission factors from the EPA GHG Inventory",
4
+ :url => 'https://docs.google.com/spreadsheet/pub?hl=en_US&hl=en_US&key=0AoQJbWqPrREqdEppYmtaU2k2Y0k0TS1MaW9iUm16amc&output=csv' do
5
+ key 'name'
6
+ store 'fuel_name'
7
+ store 'ch4_emission_factor', :units_field_name => 'ch4_emission_factor_units'
8
+ store 'n2o_emission_factor', :units_field_name => 'n2o_emission_factor_units'
9
+ end
10
+
11
+ process "Ensure Fuel and GreenhouseGas are populated" do
12
+ Fuel.run_data_miner!
13
+ GreenhouseGas.run_data_miner!
14
+ end
15
+
16
+ process "Convert ch4 and n2o emission factor units to kg co2e / l" do
17
+ RailFuel.find_each do |fuel|
18
+ if fuel.ch4_emission_factor_units == "grams_per_kilogram" and fuel.density_units == "kilograms_per_litre"
19
+ fuel.ch4_emission_factor = GreenhouseGas["ch4"].global_warming_potential * fuel.density * fuel.ch4_emission_factor / 1000.0
20
+ fuel.ch4_emission_factor_units = "kilograms_co2e_per_litre"
21
+ fuel.save!
22
+ else
23
+ raise "We don't know how to perform this unit conversion."
24
+ end
25
+
26
+ if fuel.n2o_emission_factor_units == "grams_per_kilogram" and fuel.density_units == "kilograms_per_litre"
27
+ fuel.n2o_emission_factor = GreenhouseGas["n2o"].global_warming_potential * fuel.density * fuel.n2o_emission_factor / 1000.0
28
+ fuel.n2o_emission_factor_units = "kilograms_co2e_per_litre"
29
+ fuel.save!
30
+ else
31
+ raise "We don't know how to perform this unit conversion."
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,5 @@
1
+ class RailTraction < ActiveRecord::Base
2
+ set_primary_key :name
3
+
4
+ col :name
5
+ end
@@ -0,0 +1,21 @@
1
+ RailTraction.class_eval do
2
+ data_miner do
3
+ process "Ensure CountryRailTraction, CountryRailTractionClass, RailCompanyTraction, and RailCompanyTractionClass are populated" do
4
+ CountryRailTractionClass.run_data_miner!
5
+ CountryRailTraction.run_data_miner!
6
+ RailCompanyTractionClass.run_data_miner!
7
+ RailCompanyTraction.run_data_miner!
8
+ end
9
+
10
+ process "Derive rail traction names from CountryRailTraction, CountryRailTractionClass, RailCompanyTraction, and RailCompanyTractionClass" do
11
+ names = []
12
+ names += CountryRailTractionClass.select("DISTINCT rail_traction_name").map(&:rail_traction_name)
13
+ names += CountryRailTraction.select("DISTINCT rail_traction_name").map(&:rail_traction_name)
14
+ names += RailCompanyTractionClass.select("DISTINCT rail_traction_name").map(&:rail_traction_name)
15
+ names += RailCompanyTraction.select("DISTINCT rail_traction_name").map(&:rail_traction_name)
16
+ names.uniq.each do |name|
17
+ RailTraction.find_or_create_by_name(name)
18
+ end
19
+ end
20
+ end
21
+ end
data/lib/earth/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Earth
2
- VERSION = "0.6.6"
2
+ VERSION = "0.7.0"
3
3
  end
data/spec/earth_spec.rb CHANGED
@@ -23,7 +23,7 @@ describe Earth do
23
23
  describe '.resource_map' do
24
24
  it 'should get a list of resource_map' do
25
25
  resource_map = Earth.resource_map
26
- resource_map.keys.count.should == 78
26
+ resource_map.keys.count.should == 89
27
27
  resource_map['FuelType'].should == 'fuel'
28
28
  end
29
29
  it 'should exclude data_miner files' do
@@ -33,12 +33,24 @@ describe Earth do
33
33
 
34
34
  describe '.search' do
35
35
  it 'should get a list of all resource names' do
36
- Earth.search.length.should == 78
36
+ Earth.search.length.should == 89
37
37
  Earth.search.should include('Aircraft')
38
38
  Earth.search.should include('Industry')
39
39
  end
40
40
  it 'should filter resource_map by domain' do
41
+ Earth.search('air').length.should == 12
42
+ Earth.search('automobile').length.should == 15
43
+ Earth.search('bus').length.should == 4
44
+ Earth.search('computation').length.should == 3
45
+ Earth.search('diet').length.should == 2
41
46
  Earth.search('fuel').length.should == 5
47
+ Earth.search('hospitality').length.should == 1
48
+ Earth.search('industry').length.should == 10
49
+ Earth.search('locality').length.should == 13
50
+ Earth.search('pet').length.should == 4
51
+ Earth.search('rail').length.should == 9
52
+ Earth.search('residence').length.should == 8
53
+ Earth.search('shipping').length.should == 3
42
54
  Earth.search('fuel').should include('FuelType')
43
55
  end
44
56
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: earth
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.6.6
5
+ version: 0.7.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Seamus Abshere
@@ -17,6 +17,7 @@ default_executable:
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: data_miner
20
+ prerelease: false
20
21
  requirement: &id001 !ruby/object:Gem::Requirement
21
22
  none: false
22
23
  requirements:
@@ -24,10 +25,10 @@ dependencies:
24
25
  - !ruby/object:Gem::Version
25
26
  version: "1.3"
26
27
  type: :runtime
27
- prerelease: false
28
28
  version_requirements: *id001
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: to_regexp
31
+ prerelease: false
31
32
  requirement: &id002 !ruby/object:Gem::Requirement
32
33
  none: false
33
34
  requirements:
@@ -35,10 +36,10 @@ dependencies:
35
36
  - !ruby/object:Gem::Version
36
37
  version: "0"
37
38
  type: :runtime
38
- prerelease: false
39
39
  version_requirements: *id002
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: cohort_scope
42
+ prerelease: false
42
43
  requirement: &id003 !ruby/object:Gem::Requirement
43
44
  none: false
44
45
  requirements:
@@ -46,10 +47,10 @@ dependencies:
46
47
  - !ruby/object:Gem::Version
47
48
  version: "0"
48
49
  type: :runtime
49
- prerelease: false
50
50
  version_requirements: *id003
51
51
  - !ruby/object:Gem::Dependency
52
52
  name: table_warnings
53
+ prerelease: false
53
54
  requirement: &id004 !ruby/object:Gem::Requirement
54
55
  none: false
55
56
  requirements:
@@ -57,10 +58,10 @@ dependencies:
57
58
  - !ruby/object:Gem::Version
58
59
  version: 0.0.6
59
60
  type: :runtime
60
- prerelease: false
61
61
  version_requirements: *id004
62
62
  - !ruby/object:Gem::Dependency
63
63
  name: remote_table
64
+ prerelease: false
64
65
  requirement: &id005 !ruby/object:Gem::Requirement
65
66
  none: false
66
67
  requirements:
@@ -68,10 +69,10 @@ dependencies:
68
69
  - !ruby/object:Gem::Version
69
70
  version: 1.2.3
70
71
  type: :runtime
71
- prerelease: false
72
72
  version_requirements: *id005
73
73
  - !ruby/object:Gem::Dependency
74
74
  name: falls_back_on
75
+ prerelease: false
75
76
  requirement: &id006 !ruby/object:Gem::Requirement
76
77
  none: false
77
78
  requirements:
@@ -79,10 +80,10 @@ dependencies:
79
80
  - !ruby/object:Gem::Version
80
81
  version: "0"
81
82
  type: :runtime
82
- prerelease: false
83
83
  version_requirements: *id006
84
84
  - !ruby/object:Gem::Dependency
85
85
  name: fixed_width-multibyte
86
+ prerelease: false
86
87
  requirement: &id007 !ruby/object:Gem::Requirement
87
88
  none: false
88
89
  requirements:
@@ -90,10 +91,10 @@ dependencies:
90
91
  - !ruby/object:Gem::Version
91
92
  version: "0"
92
93
  type: :runtime
93
- prerelease: false
94
94
  version_requirements: *id007
95
95
  - !ruby/object:Gem::Dependency
96
96
  name: geokit-rails
97
+ prerelease: false
97
98
  requirement: &id008 !ruby/object:Gem::Requirement
98
99
  none: false
99
100
  requirements:
@@ -101,10 +102,10 @@ dependencies:
101
102
  - !ruby/object:Gem::Version
102
103
  version: "0"
103
104
  type: :runtime
104
- prerelease: false
105
105
  version_requirements: *id008
106
106
  - !ruby/object:Gem::Dependency
107
107
  name: loose_tight_dictionary
108
+ prerelease: false
108
109
  requirement: &id009 !ruby/object:Gem::Requirement
109
110
  none: false
110
111
  requirements:
@@ -112,21 +113,21 @@ dependencies:
112
113
  - !ruby/object:Gem::Version
113
114
  version: 0.2.3
114
115
  type: :runtime
115
- prerelease: false
116
116
  version_requirements: *id009
117
117
  - !ruby/object:Gem::Dependency
118
118
  name: weighted_average
119
+ prerelease: false
119
120
  requirement: &id010 !ruby/object:Gem::Requirement
120
121
  none: false
121
122
  requirements:
122
123
  - - ">="
123
124
  - !ruby/object:Gem::Version
124
- version: 1.0.1
125
+ version: 1.0.2
125
126
  type: :runtime
126
- prerelease: false
127
127
  version_requirements: *id010
128
128
  - !ruby/object:Gem::Dependency
129
129
  name: mini_record-compat
130
+ prerelease: false
130
131
  requirement: &id011 !ruby/object:Gem::Requirement
131
132
  none: false
132
133
  requirements:
@@ -134,10 +135,10 @@ dependencies:
134
135
  - !ruby/object:Gem::Version
135
136
  version: "0"
136
137
  type: :runtime
137
- prerelease: false
138
138
  version_requirements: *id011
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: activesupport
141
+ prerelease: false
141
142
  requirement: &id012 !ruby/object:Gem::Requirement
142
143
  none: false
143
144
  requirements:
@@ -145,10 +146,10 @@ dependencies:
145
146
  - !ruby/object:Gem::Version
146
147
  version: "0"
147
148
  type: :runtime
148
- prerelease: false
149
149
  version_requirements: *id012
150
150
  - !ruby/object:Gem::Dependency
151
151
  name: activerecord
152
+ prerelease: false
152
153
  requirement: &id013 !ruby/object:Gem::Requirement
153
154
  none: false
154
155
  requirements:
@@ -156,10 +157,10 @@ dependencies:
156
157
  - !ruby/object:Gem::Version
157
158
  version: "0"
158
159
  type: :runtime
159
- prerelease: false
160
160
  version_requirements: *id013
161
161
  - !ruby/object:Gem::Dependency
162
162
  name: bundler
163
+ prerelease: false
163
164
  requirement: &id014 !ruby/object:Gem::Requirement
164
165
  none: false
165
166
  requirements:
@@ -167,10 +168,10 @@ dependencies:
167
168
  - !ruby/object:Gem::Version
168
169
  version: "0"
169
170
  type: :development
170
- prerelease: false
171
171
  version_requirements: *id014
172
172
  - !ruby/object:Gem::Dependency
173
173
  name: bueller
174
+ prerelease: false
174
175
  requirement: &id015 !ruby/object:Gem::Requirement
175
176
  none: false
176
177
  requirements:
@@ -178,10 +179,10 @@ dependencies:
178
179
  - !ruby/object:Gem::Version
179
180
  version: "0"
180
181
  type: :development
181
- prerelease: false
182
182
  version_requirements: *id015
183
183
  - !ruby/object:Gem::Dependency
184
184
  name: cucumber
185
+ prerelease: false
185
186
  requirement: &id016 !ruby/object:Gem::Requirement
186
187
  none: false
187
188
  requirements:
@@ -189,10 +190,10 @@ dependencies:
189
190
  - !ruby/object:Gem::Version
190
191
  version: "0"
191
192
  type: :development
192
- prerelease: false
193
193
  version_requirements: *id016
194
194
  - !ruby/object:Gem::Dependency
195
195
  name: rake
196
+ prerelease: false
196
197
  requirement: &id017 !ruby/object:Gem::Requirement
197
198
  none: false
198
199
  requirements:
@@ -200,10 +201,10 @@ dependencies:
200
201
  - !ruby/object:Gem::Version
201
202
  version: "0"
202
203
  type: :development
203
- prerelease: false
204
204
  version_requirements: *id017
205
205
  - !ruby/object:Gem::Dependency
206
206
  name: rdoc
207
+ prerelease: false
207
208
  requirement: &id018 !ruby/object:Gem::Requirement
208
209
  none: false
209
210
  requirements:
@@ -211,10 +212,10 @@ dependencies:
211
212
  - !ruby/object:Gem::Version
212
213
  version: "0"
213
214
  type: :development
214
- prerelease: false
215
215
  version_requirements: *id018
216
216
  - !ruby/object:Gem::Dependency
217
217
  name: rspec
218
+ prerelease: false
218
219
  requirement: &id019 !ruby/object:Gem::Requirement
219
220
  none: false
220
221
  requirements:
@@ -222,10 +223,10 @@ dependencies:
222
223
  - !ruby/object:Gem::Version
223
224
  version: "0"
224
225
  type: :development
225
- prerelease: false
226
226
  version_requirements: *id019
227
227
  - !ruby/object:Gem::Dependency
228
228
  name: sqlite3-ruby
229
+ prerelease: false
229
230
  requirement: &id020 !ruby/object:Gem::Requirement
230
231
  none: false
231
232
  requirements:
@@ -233,10 +234,10 @@ dependencies:
233
234
  - !ruby/object:Gem::Version
234
235
  version: "0"
235
236
  type: :development
236
- prerelease: false
237
237
  version_requirements: *id020
238
238
  - !ruby/object:Gem::Dependency
239
239
  name: mysql
240
+ prerelease: false
240
241
  requirement: &id021 !ruby/object:Gem::Requirement
241
242
  none: false
242
243
  requirements:
@@ -244,10 +245,10 @@ dependencies:
244
245
  - !ruby/object:Gem::Version
245
246
  version: "0"
246
247
  type: :development
247
- prerelease: false
248
248
  version_requirements: *id021
249
249
  - !ruby/object:Gem::Dependency
250
250
  name: pg
251
+ prerelease: false
251
252
  requirement: &id022 !ruby/object:Gem::Requirement
252
253
  none: false
253
254
  requirements:
@@ -255,7 +256,6 @@ dependencies:
255
256
  - !ruby/object:Gem::Version
256
257
  version: "0"
257
258
  type: :development
258
- prerelease: false
259
259
  version_requirements: *id022
260
260
  description: An earth-simulation environment with ActiveRecord models and data
261
261
  email: andy@rossmeissl.net
@@ -483,6 +483,12 @@ files:
483
483
  - lib/earth/locality/climate_division/data_miner.rb
484
484
  - lib/earth/locality/country.rb
485
485
  - lib/earth/locality/country/data_miner.rb
486
+ - lib/earth/locality/country_rail_class.rb
487
+ - lib/earth/locality/country_rail_class/data_miner.rb
488
+ - lib/earth/locality/country_rail_traction.rb
489
+ - lib/earth/locality/country_rail_traction/data_miner.rb
490
+ - lib/earth/locality/country_rail_traction_class.rb
491
+ - lib/earth/locality/country_rail_traction_class/data_miner.rb
486
492
  - lib/earth/locality/data_miner.rb
487
493
  - lib/earth/locality/egrid_region.rb
488
494
  - lib/earth/locality/egrid_region/data_miner.rb
@@ -508,8 +514,24 @@ files:
508
514
  - lib/earth/pet/species/data_miner.rb
509
515
  - lib/earth/rail.rb
510
516
  - lib/earth/rail/data_miner.rb
517
+ - lib/earth/rail/national_transit_database_company.rb
518
+ - lib/earth/rail/national_transit_database_company/data_miner.rb
519
+ - lib/earth/rail/national_transit_database_mode.rb
520
+ - lib/earth/rail/national_transit_database_mode/data_miner.rb
521
+ - lib/earth/rail/national_transit_database_record.rb
522
+ - lib/earth/rail/national_transit_database_record/data_miner.rb
511
523
  - lib/earth/rail/rail_class.rb
512
524
  - lib/earth/rail/rail_class/data_miner.rb
525
+ - lib/earth/rail/rail_company.rb
526
+ - lib/earth/rail/rail_company/data_miner.rb
527
+ - lib/earth/rail/rail_company_traction.rb
528
+ - lib/earth/rail/rail_company_traction/data_miner.rb
529
+ - lib/earth/rail/rail_company_traction_class.rb
530
+ - lib/earth/rail/rail_company_traction_class/data_miner.rb
531
+ - lib/earth/rail/rail_fuel.rb
532
+ - lib/earth/rail/rail_fuel/data_miner.rb
533
+ - lib/earth/rail/rail_traction.rb
534
+ - lib/earth/rail/rail_traction/data_miner.rb
513
535
  - lib/earth/residence.rb
514
536
  - lib/earth/residence/air_conditioner_use.rb
515
537
  - lib/earth/residence/air_conditioner_use/data_miner.rb
@@ -605,18 +627,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
605
627
  requirements:
606
628
  - - ">="
607
629
  - !ruby/object:Gem::Version
608
- hash: 1109178617057141377
609
- segments:
610
- - 0
611
630
  version: "0"
612
631
  required_rubygems_version: !ruby/object:Gem::Requirement
613
632
  none: false
614
633
  requirements:
615
634
  - - ">="
616
635
  - !ruby/object:Gem::Version
617
- hash: 1109178617057141377
618
- segments:
619
- - 0
620
636
  version: "0"
621
637
  requirements: []
622
638