earth 0.0.40 → 0.0.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/earth.rb CHANGED
@@ -24,62 +24,18 @@ module Earth
24
24
  def taps_server=(val)
25
25
  @taps_server = val
26
26
  end
27
-
28
- def classes
29
- [
30
- AirConditionerUse,
31
- Aircraft,
32
- AircraftClass,
33
- AircraftManufacturer,
34
- Airline,
35
- Airport,
36
- AutomobileFuelType,
37
- AutomobileMake,
38
- AutomobileMakeFleetYear,
39
- AutomobileMakeYear,
40
- AutomobileModel,
41
- AutomobileModelYear,
42
- AutomobileSizeClass,
43
- AutomobileVariant,
44
- Breed,
45
- BreedGender,
46
- BusClass,
47
- CensusDivision,
48
- CensusRegion,
49
- ClimateDivision,
50
- ClothesMachineUse,
51
- Country,
52
- DietClass,
53
- DishwasherUse,
54
- EgridRegion,
55
- EgridSubregion,
56
- FlightConfiguration,
57
- FlightDistanceClass,
58
- FlightDomesticity,
59
- FlightFuelType,
60
- FlightPropulsion,
61
- FlightSeatClass,
62
- FlightSegment,
63
- FlightService,
64
- FoodGroup,
65
- Gender,
66
- LodgingClass,
67
- PetroleumAdministrationForDefenseDistrict,
68
- RailClass,
69
- ResidenceAppliance,
70
- ResidenceClass,
71
- ResidenceFuelPrice,
72
- ResidenceFuelType,
73
- ResidentialEnergyConsumptionSurveyResponse,
74
- Species,
75
- State,
76
- Urbanity,
77
- ZipCode
78
- ]
27
+
28
+ # Takes argument like Earth.resource_names(['air'])
29
+ # Default is search all domains
30
+ # For example, <tt>[ 'Aircraft', 'Airline' ]</tt>
31
+ def resource_names(search_domains = nil)
32
+ (search_domains || domains).map do |domain|
33
+ Dir[File.join(Earth.gem_root, 'lib', 'earth', domain, '*.rb')]
34
+ end.flatten.uniq.map { |p| File.basename(p, '.rb').camelcase } - %w{ DataMiner }
79
35
  end
80
36
 
81
- def root
82
- File.join(File.dirname(__FILE__), '..')
37
+ def gem_root
38
+ File.expand_path File.join(File.dirname(__FILE__), '..')
83
39
  end
84
40
 
85
41
  def domains
@@ -121,6 +77,7 @@ module Earth
121
77
  private
122
78
  def load_domains(domains, options)
123
79
  if domains.empty? or domains.include?(:all)
80
+ # sabshere 9/16/10 why maintain this separately?
124
81
  require 'earth/all'
125
82
  require 'earth/data_miner' if options[:apply_schemas] or options[:load_data_miner]
126
83
  elsif !domains.include?(:none)
@@ -133,24 +90,33 @@ private
133
90
 
134
91
  def load_plugins
135
92
  require 'earth/active_record_ext'
136
- Dir[File.join(Earth.root, 'vendor', '**', 'init.rb')].each do |pluginit|
93
+ Dir[File.join(Earth.gem_root, 'vendor', '**', 'init.rb')].each do |pluginit|
137
94
  $:.unshift File.join(File.dirname(pluginit), 'lib')
138
95
  load pluginit
139
96
  end
140
97
  end
141
98
 
142
99
  def load_schemas
143
- load_ar_schema
100
+ force_fallback_table
144
101
  load_data_miner_schemas
145
102
  end
146
-
147
- def load_ar_schema
148
- orig_std_out = STDOUT.clone
149
- STDOUT.reopen File.open(File.join('/tmp', 'schema_output'), 'w')
150
-
151
- load File.join(File.dirname(__FILE__), 'earth', 'schema.rb')
152
- ensure
153
- STDOUT.reopen(orig_std_out)
103
+
104
+ # sabshere 9/17/10 this sucks. the falls_back_on gem sucks.
105
+ def force_fallback_table
106
+ c = ActiveRecord::Base.connection
107
+ if c.table_exists? 'fallbacks'
108
+ raise "The earth gem expects a different schema for the fallbacks table." unless c.column_exists?('fallbacks', 'name') and
109
+ c.column_exists?('fallbacks', 'values') and
110
+ c.column_exists?('fallbacks', 'created_at') and
111
+ c.column_exists?('fallbacks', 'updated_at')
112
+ else
113
+ c.create_table 'fallbacks' do |t|
114
+ t.string 'name'
115
+ t.text 'values'
116
+ t.datetime 'created_at'
117
+ t.datetime 'updated_at'
118
+ end
119
+ end
154
120
  end
155
121
 
156
122
  def load_data_miner_schemas
@@ -1,4 +1,24 @@
1
1
  Aircraft.class_eval do
2
+
3
+ # TODO use http://www.transtats.bts.gov/Download_Lookup.asp?Lookup=L_AIRCRAFT_TYPE
4
+ def self.bts_name_dictionary
5
+ @_bts_dictionary ||= LooseTightDictionary.new RemoteTable.new(:url => 'http://www.transtats.bts.gov/Download_Lookup.asp?Lookup=L_AIRCRAFT_TYPE', :select => lambda { |record| record['Code'].to_i.between?(1, 998) }),
6
+ :tightenings => RemoteTable.new(:url => 'http://spreadsheets.google.com/pub?key=tiS_6CCDDM_drNphpYwE_iw&single=true&gid=0&output=csv', :headers => false),
7
+ :identities => RemoteTable.new(:url => 'http://spreadsheets.google.com/pub?key=tiS_6CCDDM_drNphpYwE_iw&single=true&gid=3&output=csv', :headers => false),
8
+ :blockings => RemoteTable.new(:url => 'http://spreadsheets.google.com/pub?key=tiS_6CCDDM_drNphpYwE_iw&single=true&gid=4&output=csv', :headers => false),
9
+ :blocking_only => true,
10
+ :right_reader => lambda { |record| record['Description'] }
11
+ end
12
+
13
+ # warning: self-referential, assumes it will be used once first import step is done
14
+ def self.icao_name_dictionary
15
+ @_icao_dictionary ||= LooseTightDictionary.new Aircraft.all,
16
+ :tightenings => RemoteTable.new(:url => 'http://spreadsheets.google.com/pub?key=tiS_6CCDDM_drNphpYwE_iw&single=true&gid=0&output=csv', :headers => false),
17
+ :identities => RemoteTable.new(:url => 'http://spreadsheets.google.com/pub?key=tiS_6CCDDM_drNphpYwE_iw&single=true&gid=3&output=csv', :headers => false),
18
+ :blockings => RemoteTable.new(:url => 'http://spreadsheets.google.com/pub?key=tiS_6CCDDM_drNphpYwE_iw&single=true&gid=4&output=csv', :headers => false),
19
+ :right_reader => lambda { |record| record.manufacturer_name.to_s + ' ' + record.name.to_s }
20
+ end
21
+
2
22
  class Aircraft::BtsMatcher
3
23
  attr_reader :wants
4
24
  def initialize(wants)
@@ -71,10 +91,6 @@ Aircraft.class_eval do
71
91
  end
72
92
 
73
93
  data_miner do
74
- process "Don't re-import too often" do
75
- raise DataMiner::Skip unless DataMiner::Run.allowed? Aircraft
76
- end
77
-
78
94
  schema Earth.database_options do
79
95
  string 'icao_code'
80
96
  string 'manufacturer_name'
@@ -161,11 +177,8 @@ Aircraft.class_eval do
161
177
  update_all "weighting = (#{segments.project(segments[:passengers].sum).where(aircraft[:bts_aircraft_type_code].eq(segments[:bts_aircraft_type_code])).to_sql})"
162
178
  end
163
179
 
164
- [ AircraftManufacturer ].each do |synthetic_resource|
165
- process "Synthesize #{synthetic_resource}" do
166
- synthetic_resource.run_data_miner!
167
- end
180
+ process "Synthesize AircraftManufacturer" do
181
+ AircraftManufacturer.run_data_miner!
168
182
  end
169
-
170
183
  end
171
184
  end
@@ -159,10 +159,6 @@ FlightSegment.class_eval do
159
159
  }.gsub /[\s]+/,''
160
160
 
161
161
  data_miner do
162
- process "Don't re-import too often" do
163
- raise DataMiner::Skip unless DataMiner::Run.allowed? FlightSegment
164
- end
165
-
166
162
  schema Earth.database_options do
167
163
  string 'row_hash'
168
164
  string 'propulsion_id'
@@ -273,10 +273,6 @@ AutomobileVariant.class_eval do
273
273
  end
274
274
 
275
275
  data_miner do
276
- process "Don't re-import too often" do
277
- raise DataMiner::Skip unless DataMiner::Run.allowed? AutomobileVariant
278
- end
279
-
280
276
  schema Earth.database_options do
281
277
  string 'row_hash'
282
278
  string 'name' # short name!
@@ -454,9 +450,9 @@ AutomobileVariant.class_eval do
454
450
  update_all 'fuel_efficiency_highway = 1 / ((0.001376 / 0.425143707) + (1.3466 / raw_fuel_efficiency_highway))'
455
451
  end
456
452
 
457
- [ AutomobileMake, AutomobileModelYear, AutomobileModel ].each do |synthetic_resource|
453
+ %w{ AutomobileMake AutomobileModelYear AutomobileModel }.each do |synthetic_resource|
458
454
  process "Synthesize #{synthetic_resource}" do
459
- synthetic_resource.run_data_miner!
455
+ synthetic_resource.constantize.run_data_miner!
460
456
  end
461
457
  end
462
458
  end
@@ -6,8 +6,7 @@ Sector.class_eval do
6
6
  :url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdHV2dzdjdGVnLUJCdDA4TURXNThROVE&hl=en&single=true&gid=1&output=csv' do
7
7
  key 'io_code'
8
8
  store 'description'
9
- store 'emission_factor'
10
- store 'emission_factor_units'
9
+ store 'emission_factor', :units_field_name => 'emission_factor_units'
11
10
  end
12
11
  end
13
12
  end
@@ -7,6 +7,11 @@ class CensusDivision < ActiveRecord::Base
7
7
  has_many :climate_divisions, :through => :states
8
8
  has_many :residential_energy_consumption_survey_responses, :foreign_key => 'census_division_number'
9
9
 
10
+ falls_back_on :meeting_building_natural_gas_intensity => 0.011973,
11
+ :meeting_building_fuel_oil_intensity => 0.0037381,
12
+ :meeting_building_electricity_intensity => 0.072444,
13
+ :meeting_building_district_heat_intensity => 3458.7
14
+
10
15
  data_miner do
11
16
  tap "Brighter Planet's sanitized census divisions", Earth.taps_server
12
17
 
@@ -22,11 +22,16 @@ CensusDivision.class_eval do
22
22
  float 'lodging_building_district_heat_intensity'
23
23
  string 'lodging_building_district_heat_intensity_units'
24
24
  end
25
-
26
- falls_back_on :meeting_building_natural_gas_intensity => 0.011973,
27
- :meeting_building_fuel_oil_intensity => 0.0037381,
28
- :meeting_building_electricity_intensity => 0.072444,
29
- :meeting_building_district_heat_intensity => 3458.7
25
+
26
+ process 'Define some unit conversions' do
27
+ Conversions.register :hundred_cubic_feet_per_square_foot_hour, :cubic_metres_per_square_metre_hour, 30.48
28
+ Conversions.register :gallons_per_square_foot_hour, :litres_per_square_metre_hour, 40.745833
29
+ Conversions.register :kilowatt_hours_per_square_foot_hour, :kilowatt_hours_per_square_metre_hour, 10.76391
30
+ Conversions.register :thousand_btu_per_square_foot_hour, :joules_per_square_metre_hour, 11_356_527
31
+ Conversions.register :hundred_cubic_feet_per_room_night, :cubic_metres_per_room_night, 2.8317
32
+ Conversions.register :gallons_per_room_night, :litres_per_room_night, 3.7854
33
+ Conversions.register :thousand_btu_per_room_night, :joules_per_room_night, 1_055_056
34
+ end
30
35
 
31
36
  import 'the U.S. Census Geographic Terms and Definitions',
32
37
  :url => 'http://www.census.gov/popest/geographic/codes02.csv',
@@ -38,16 +43,6 @@ CensusDivision.class_eval do
38
43
  store 'census_region_name', :field_name => 'Region', :dictionary => { :input => 'number', :output => 'name', :url => 'http://data.brighterplanet.com/census_regions.csv' }
39
44
  end
40
45
 
41
- process 'Define some unit conversions' do
42
- Conversions.register :hundred_cubic_feet_per_square_foot_hour, :cubic_metres_per_square_metre_hour, 30.48
43
- Conversions.register :gallons_per_square_foot_hour, :litres_per_square_metre_hour, 40.745833
44
- Conversions.register :kilowatt_hours_per_square_foot_hour, :kilowatt_hours_per_square_metre_hour, 10.76391
45
- Conversions.register :thousand_btu_per_square_foot_hour, :joules_per_square_metre_hour, 11_356_527
46
- Conversions.register :hundred_cubic_feet_per_room_night, :cubic_metres_per_room_night, 2.8317
47
- Conversions.register :gallons_per_room_night, :litres_per_room_night, 3.7854
48
- Conversions.register :thousand_btu_per_room_night, :joules_per_room_night, 1_055_056
49
- end
50
-
51
46
  import 'meeting building fuel intensities calculated from CBECS 2003',
52
47
  :url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdGotdjgtUEk0eUU0R3lxM1hHdlF1V0E&hl=en&output=csv' do
53
48
  key 'number', :field_name => 'census_division'
@@ -1,7 +1,6 @@
1
1
  class ResidenceFuelType < ActiveRecord::Base
2
2
  set_primary_key :name
3
3
 
4
-
5
4
  has_many :prices, :class_name => 'ResidenceFuelPrice', :foreign_key => 'residence_fuel_type_name'
6
5
 
7
6
  data_miner do
@@ -1,9 +1,5 @@
1
1
  ResidentialEnergyConsumptionSurveyResponse.class_eval do
2
2
  data_miner do
3
- process "Don't re-import too often" do
4
- raise DataMiner::Skip unless DataMiner::Run.allowed? ResidentialEnergyConsumptionSurveyResponse
5
- end
6
-
7
3
  schema Earth.database_options do
8
4
  integer 'department_of_energy_identifier'
9
5
  string 'residence_class_id'
@@ -7,13 +7,13 @@ describe Earth do
7
7
 
8
8
  it 'should require all Earth models' do
9
9
  lambda do
10
- Earth.classes.each { |k| k }
10
+ Earth.resource_names.each { |k| k.constantize }
11
11
  end.should_not raise_error(NameError)
12
12
  end
13
13
 
14
14
  it 'should include data_miner definitions' do
15
15
  lambda do
16
- Earth.classes.each { |k| k.should_receive(:data_miner) }
16
+ Earth.resource_names.each { |k| k.constantize.should_receive(:data_miner) }
17
17
  end
18
18
  require 'earth/data_miner'
19
19
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: earth
3
3
  version: !ruby/object:Gem::Version
4
- hash: 79
4
+ hash: 77
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 40
10
- version: 0.0.40
9
+ - 41
10
+ version: 0.0.41
11
11
  platform: ruby
12
12
  authors:
13
13
  - Seamus Abshere
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2010-09-15 00:00:00 -07:00
20
+ date: 2010-09-17 00:00:00 -05:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
@@ -28,7 +28,7 @@ dependencies:
28
28
  requirements:
29
29
  - - ">="
30
30
  - !ruby/object:Gem::Version
31
- hash: -1848230024
31
+ hash: 299253624
32
32
  segments:
33
33
  - 3
34
34
  - 0
@@ -366,7 +366,6 @@ files:
366
366
  - lib/earth/residence/residence_fuel_type/data_miner.rb
367
367
  - lib/earth/residence/residential_energy_consumption_survey_response.rb
368
368
  - lib/earth/residence/residential_energy_consumption_survey_response/data_miner.rb
369
- - lib/earth/schema.rb
370
369
  - vendor/geokit-rails/CHANGELOG.rdoc
371
370
  - vendor/geokit-rails/MIT-LICENSE
372
371
  - vendor/geokit-rails/README.markdown
data/lib/earth/schema.rb DELETED
@@ -1,8 +0,0 @@
1
- ActiveRecord::Schema.define(:version => 1) do
2
- create_table "fallbacks", :force => true do |t|
3
- t.string "name"
4
- t.text "values"
5
- t.datetime "created_at"
6
- t.datetime "updated_at"
7
- end
8
- end