earth 0.1.1 → 0.1.2

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/Gemfile.lock CHANGED
@@ -14,6 +14,7 @@ GEM
14
14
  arel (~> 1.0.0)
15
15
  tzinfo (~> 0.3.23)
16
16
  activesupport (3.0.0)
17
+ amatch (0.2.5)
17
18
  andand (1.3.1)
18
19
  arel (1.0.1)
19
20
  activesupport (~> 3.0.0)
@@ -24,7 +25,7 @@ GEM
24
25
  activesupport (>= 3.0.0.beta4)
25
26
  conversions (1.4.5)
26
27
  activesupport (>= 2.3.4)
27
- data_miner (0.5.3)
28
+ data_miner (0.5.4)
28
29
  activerecord (>= 2.3.4)
29
30
  activesupport (>= 2.3.4)
30
31
  andand (>= 1.3.1)
@@ -33,8 +34,8 @@ GEM
33
34
  errata (>= 0.2.1)
34
35
  escape (>= 0.0.4)
35
36
  log4r (>= 1.1.7)
36
- remote_table (>= 0.2.27)
37
- taps (= 0.3.11)
37
+ remote_table (>= 0.2.30)
38
+ taps (>= 0.3.11)
38
39
  diff-lcs (1.1.2)
39
40
  errata (0.2.3)
40
41
  activesupport (>= 2.3.4)
@@ -58,13 +59,18 @@ GEM
58
59
  json_pure (1.4.6)
59
60
  libxml-ruby (1.1.4)
60
61
  log4r (1.1.8)
62
+ loose_tight_dictionary (0.0.8)
63
+ activesupport (>= 2.3.4)
64
+ amatch (>= 0.2.5)
65
+ andand (>= 1.3.1)
66
+ fastercsv (>= 1.5.3)
61
67
  mime-types (1.16)
62
68
  nokogiri (1.4.3.1)
63
69
  rack (1.2.1)
64
70
  rake (0.8.7)
65
- rcov (0.9.8)
71
+ rcov (0.9.9)
66
72
  rdoc (2.5.11)
67
- remote_table (0.2.27)
73
+ remote_table (0.2.30)
68
74
  activesupport (>= 2.3.4)
69
75
  escape (>= 0.0.4)
70
76
  fastercsv (>= 1.5.0)
@@ -79,47 +85,54 @@ GEM
79
85
  libxml-ruby (>= 1.1.3)
80
86
  rubyzip (>= 0.9.1)
81
87
  spreadsheet (>= 0.6.4)
82
- rspec (2.0.0.beta.20)
83
- rspec-core (= 2.0.0.beta.20)
84
- rspec-expectations (= 2.0.0.beta.20)
85
- rspec-mocks (= 2.0.0.beta.20)
86
- rspec-core (2.0.0.beta.20)
87
- rspec-expectations (2.0.0.beta.20)
88
+ rspec (2.0.0.beta.22)
89
+ rspec-core (= 2.0.0.beta.22)
90
+ rspec-expectations (= 2.0.0.beta.22)
91
+ rspec-mocks (= 2.0.0.beta.22)
92
+ rspec-core (2.0.0.beta.22)
93
+ rspec-expectations (2.0.0.beta.22)
88
94
  diff-lcs (>= 1.1.2)
89
- rspec-mocks (2.0.0.beta.20)
95
+ rspec-mocks (2.0.0.beta.22)
96
+ rspec-core (= 2.0.0.beta.22)
97
+ rspec-expectations (= 2.0.0.beta.22)
90
98
  ruby-ole (1.2.10.1)
91
99
  rubyforge (2.0.4)
92
100
  json_pure (>= 1.1.7)
93
101
  rubyzip (0.9.4)
94
- sequel (3.13.0)
102
+ sequel (3.15.0)
95
103
  sinatra (1.0)
96
104
  rack (>= 1.0)
97
105
  slither (0.99.3)
98
106
  spreadsheet (0.6.4.1)
99
107
  ruby-ole
100
108
  sqlite3-ruby (1.3.1)
101
- taps (0.3.11)
109
+ taps (0.3.12)
102
110
  json_pure (>= 1.2.0, < 1.5.0)
103
111
  rack (>= 1.0.1)
104
112
  rest-client (~> 1.4.0)
105
- sequel (~> 3.13.0)
113
+ sequel (~> 3.15.0)
106
114
  sinatra (~> 1.0.0)
107
115
  sqlite3-ruby (~> 1.2)
108
116
  tzinfo (0.3.23)
117
+ weighted_average (0.0.5)
118
+ activerecord (>= 3.0.0.beta2)
119
+ arel (>= 0.3.3)
109
120
 
110
121
  PLATFORMS
111
122
  ruby
112
123
 
113
124
  DEPENDENCIES
114
125
  activerecord (>= 3.0.0.beta4)
115
- cohort_scope (>= 0.0.6)
126
+ cohort_scope (>= 0.0.7)
116
127
  conversions (>= 1.4.5)
117
- data_miner (>= 0.5.2)
118
- falls_back_on (>= 0.0.2)
128
+ data_miner (>= 0.5.3)
129
+ falls_back_on (>= 0.0.3)
119
130
  geokit (>= 1.5.0)
120
131
  jeweler
132
+ loose_tight_dictionary (>= 0.0.8)
121
133
  rake
122
134
  rcov
123
135
  rdoc
124
136
  rspec (>= 2.0.0.beta.17)
125
137
  sqlite3-ruby (>= 1.3.0)
138
+ weighted_average (>= 0.0.4)
data/lib/earth.rb CHANGED
@@ -85,7 +85,12 @@ private
85
85
  elsif !domains.include?(:none)
86
86
  domains.each do |domain|
87
87
  require "earth/#{domain}"
88
- require "earth/#{domain}/data_miner" if options[:apply_schemas] or options[:load_data_miner]
88
+ if options[:apply_schemas] or options[:load_data_miner]
89
+ begin
90
+ require "earth/#{domain}/data_miner"
91
+ rescue LoadError
92
+ end
93
+ end
89
94
  end
90
95
  end
91
96
  end
@@ -20,7 +20,7 @@ FlightDomesticity.class_eval do
20
20
  FlightSegment.run_data_miner!
21
21
  connection.execute %{
22
22
  INSERT IGNORE INTO flight_domesticities(name, bts_data_source_code)
23
- SELECT flight_segments.domesticity, flight_segments.bts_data_source_code FROM flight_segments WHERE LENGTH(flight_segments.domesticity) > 0
23
+ SELECT flight_segments.domesticity_id, flight_segments.bts_data_source_code FROM flight_segments WHERE LENGTH(flight_segments.domesticity_id) > 0
24
24
  }
25
25
  end
26
26
 
@@ -29,7 +29,7 @@ FlightDomesticity.class_eval do
29
29
  segments = FlightSegment.arel_table
30
30
  flight_domesticities = FlightDomesticity.arel_table
31
31
  ## slow, all-in-one method
32
- # conditional_relation = flight_domesticities[:name].eq(segments[:domesticity])
32
+ # conditional_relation = flight_domesticities[:name].eq(segments[:domesticity_id])
33
33
  # update_all "seats = (#{FlightSegment.weighted_average_relation(:seats, :weighted_by => :passengers ).where(conditional_relation).to_sql})"
34
34
  # update_all "distance = (#{FlightSegment.weighted_average_relation(:distance, :weighted_by => :passengers ).where(conditional_relation).to_sql})"
35
35
  # update_all "load_factor = (#{FlightSegment.weighted_average_relation(:load_factor, :weighted_by => :passengers ).where(conditional_relation).to_sql})"
@@ -39,7 +39,7 @@ FlightDomesticity.class_eval do
39
39
  find_in_batches do |batch|
40
40
  batch.each do |flight_domesticity|
41
41
  targeting_relation = flight_domesticities[:name].eq flight_domesticity.name
42
- conditional_relation = segments[:domesticity].eq flight_domesticity.name
42
+ conditional_relation = segments[:domesticity_id].eq flight_domesticity.name
43
43
  connection.execute "CREATE TEMPORARY TABLE tmp1 #{FlightSegment.where(conditional_relation).to_sql}"
44
44
  update_all "seats = (#{FlightSegment.weighted_average_relation(:seats, :weighted_by => :passengers ).to_sql.gsub('flight_segments', 'tmp1')})", targeting_relation.to_sql
45
45
  update_all "distance = (#{FlightSegment.weighted_average_relation(:distance, :weighted_by => :passengers ).to_sql.gsub('flight_segments', 'tmp1')})", targeting_relation.to_sql
data/lib/earth/all.rb CHANGED
@@ -4,6 +4,7 @@ require 'earth/bus'
4
4
  require 'earth/diet'
5
5
  require 'earth/fuel'
6
6
  require 'earth/hospitality'
7
+ require 'earth/industry'
7
8
  require 'earth/locality'
8
9
  require 'earth/pet'
9
10
  require 'earth/rail'
@@ -0,0 +1,10 @@
1
+ require 'earth/industry/industries_product_lines'
2
+ require 'earth/industry/industries_sectors'
3
+ require 'earth/industry/industry'
4
+ require 'earth/industry/merchant'
5
+ require 'earth/industry/merchant_categories_industries'
6
+ require 'earth/industry/merchant_category'
7
+ require 'earth/industry/product_line'
8
+ require 'earth/industry/product_lines_sectors'
9
+ require 'earth/industry/sector'
10
+
@@ -0,0 +1,21 @@
1
+ class IndustriesProductLines < ActiveRecord::Base
2
+ extend Earth::Base
3
+ set_primary_key :row_hash
4
+
5
+ belongs_to :industry, :foreign_key => 'naics_code'
6
+ belongs_to :product_line, :foreign_key => 'ps_code'
7
+
8
+ def self.schema_definition
9
+ lambda do
10
+ string 'row_hash'
11
+ string 'naics_code'
12
+ float 'ratio'
13
+ string 'ps_code'
14
+ float 'revenue_allocated'
15
+ end
16
+ end
17
+
18
+ data_miner do
19
+ IndustriesProductLines.define_schema(self)
20
+ end
21
+ end
@@ -0,0 +1,17 @@
1
+ class IndustriesSectors < ActiveRecord::Base
2
+ extend Earth::Base
3
+ belongs_to :industry, :foreign_key => 'naics_code'
4
+ belongs_to :sector, :foreign_key => 'io_code'
5
+
6
+ def self.schema_definition
7
+ lambda do
8
+ string 'naics_code'
9
+ float 'ratio'
10
+ string 'io_code'
11
+ end
12
+ end
13
+
14
+ data_miner do
15
+ IndustriesSectors.define_schema(self)
16
+ end
17
+ end
@@ -0,0 +1,22 @@
1
+ class Industry < ActiveRecord::Base
2
+ extend Earth::Base
3
+ set_primary_key :naics_code
4
+
5
+ has_many :industries_product_lines, :foreign_key => 'naics_code'
6
+ has_many :product_lines, :through => :industries_product_lines
7
+ has_many :industries_sectors, :foreign_key => 'naics_code'
8
+ has_many :sectors, :through => :industries_sectors
9
+ has_many :merchant_categories_industries, :foreign_key => 'naics_code',
10
+ :class_name => 'MerchantCategoriesIndustries'
11
+
12
+ def self.schema_definition
13
+ lambda do
14
+ string 'naics_code'
15
+ string 'description'
16
+ end
17
+ end
18
+
19
+ data_miner do
20
+ Industry.define_schema(self)
21
+ end
22
+ end
@@ -0,0 +1,18 @@
1
+ class Merchant < ActiveRecord::Base
2
+ extend Earth::Base
3
+ set_primary_key :id
4
+
5
+ belongs_to :merchant_category, :foreign_key => 'mcc'
6
+
7
+ def self.schema_definition
8
+ lambda do
9
+ string 'id'
10
+ string 'name'
11
+ string 'mcc'
12
+ end
13
+ end
14
+
15
+ data_miner do
16
+ Merchant.define_schema(self)
17
+ end
18
+ end
@@ -0,0 +1,20 @@
1
+ class MerchantCategoriesIndustries < ActiveRecord::Base
2
+ extend Earth::Base
3
+
4
+ belongs_to :merchant_category, :foreign_key => 'mcc'
5
+ belongs_to :industry, :foreign_key => 'naics_code'
6
+ has_many :industries_product_lines, :through => :industry, :class_name => 'IndustriesProductLines'
7
+ has_many :industries_sectors, :through => :industry, :class_name => 'IndustriesSectors'
8
+
9
+ def self.schema_definition
10
+ lambda do
11
+ string 'mcc'
12
+ float 'ratio'
13
+ string 'naics_code'
14
+ end
15
+ end
16
+
17
+ data_miner do
18
+ MerchantCategoriesIndustries.define_schema(self)
19
+ end
20
+ end
@@ -0,0 +1,18 @@
1
+ class MerchantCategory < ActiveRecord::Base
2
+ extend Earth::Base
3
+ set_primary_key :mcc
4
+
5
+ has_many :merchant_categories_industries, :foreign_key => 'mcc', :class_name => 'MerchantCategoriesIndustries'
6
+ has_many :industries, :through => :merchant_categories_industries
7
+
8
+ def name
9
+ description
10
+ end
11
+
12
+ data_miner do
13
+ schema Earth.database_options do
14
+ string 'mcc'
15
+ string 'description'
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,20 @@
1
+ class ProductLine < ActiveRecord::Base
2
+ extend Earth::Base
3
+ set_primary_key :ps_code
4
+
5
+ has_many :product_lines_sectors, :foreign_key => 'ps_code'
6
+ has_many :sectors, :through => :product_lines_sectors
7
+
8
+ def self.schema_definition
9
+ lambda do
10
+ string 'ps_code'
11
+ string 'description'
12
+ string 'broadline' # FIXME TODO do we need this?
13
+ string 'parent' # FIXME TODO do we need this?
14
+ end
15
+ end
16
+
17
+ data_miner do
18
+ ProductLine.define_schema(self)
19
+ end
20
+ end
@@ -0,0 +1,18 @@
1
+ class ProductLinesSectors < ActiveRecord::Base
2
+ extend Earth::Base
3
+ belongs_to :product_line, :foreign_key => 'ps_code'
4
+ belongs_to :sector, :foreign_key => 'io_code'
5
+
6
+ def self.schema_definition
7
+ lambda do
8
+ string 'row_hash'
9
+ string 'ps_code'
10
+ float 'ratio'
11
+ string 'io_code'
12
+ end
13
+ end
14
+
15
+ data_miner do
16
+ ProductLinesSectors.define_schema(self)
17
+ end
18
+ end
@@ -0,0 +1,19 @@
1
+ class Sector < ActiveRecord::Base
2
+ extend Earth::Base
3
+ set_primary_key :io_code
4
+
5
+ has_many :product_lines_sectors, :class_name => 'ProductLinesSectors', :foreign_key => 'io_code'
6
+
7
+ def self.schema_definition
8
+ lambda do
9
+ string 'io_code'
10
+ string 'description'
11
+ float 'emission_factor'
12
+ string 'emission_factor_units'
13
+ end
14
+ end
15
+
16
+ data_miner do
17
+ Sector.define_schema(self)
18
+ end
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: 25
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
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-20 00:00:00 -05:00
20
+ date: 2010-09-20 00:00:00 -04: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: 299253624
31
+ hash: -1848230024
32
32
  segments:
33
33
  - 3
34
34
  - 0
@@ -323,6 +323,16 @@ files:
323
323
  - lib/earth/hospitality/data_miner.rb
324
324
  - lib/earth/hospitality/lodging_class.rb
325
325
  - lib/earth/hospitality/lodging_class/data_miner.rb
326
+ - lib/earth/industry.rb
327
+ - lib/earth/industry/industries_product_lines.rb
328
+ - lib/earth/industry/industries_sectors.rb
329
+ - lib/earth/industry/industry.rb
330
+ - lib/earth/industry/merchant.rb
331
+ - lib/earth/industry/merchant_categories_industries.rb
332
+ - lib/earth/industry/merchant_category.rb
333
+ - lib/earth/industry/product_line.rb
334
+ - lib/earth/industry/product_lines_sectors.rb
335
+ - lib/earth/industry/sector.rb
326
336
  - lib/earth/inflectors.rb
327
337
  - lib/earth/locality.rb
328
338
  - lib/earth/locality/census_division.rb