usda-nutrient-database 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/db/migrate/5_create_usda_weights.rb +13 -0
- data/lib/usda-nutrient-database.rb +2 -0
- data/lib/usda_nutrient_database/import/weights.rb +20 -0
- data/lib/usda_nutrient_database/importer.rb +5 -0
- data/lib/usda_nutrient_database/version.rb +1 -1
- data/lib/usda_nutrient_database/weight.rb +11 -0
- data/spec/lib/usda_nutrient_database/import/weights_spec.rb +11 -0
- data/spec/lib/usda_nutrient_database/importer_spec.rb +1 -0
- data/spec/lib/usda_nutrient_database/weight_spec.rb +9 -0
- data/spec/schema.rb +10 -0
- data/spec/support/sr25/WEIGHT.txt +3 -0
- metadata +10 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b8b9d0a98a2fda3048ddebf81c84ae5ed539f2f5
|
4
|
+
data.tar.gz: a1af06b2493267b44614bdcf29e1270e6c6626ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: efec3b2602fe153081ef36d5051f36a044d5a0a156686ce4598b7d7d3e0264ac6ea74c875abe6b95ece7c484a70d8a6155b975bfe08957d48245bc4383e5525e
|
7
|
+
data.tar.gz: 7e2c0a946e79f215a6c2bab31724bc7333bf549dc36a850d4f60bf4305f14dd1d34a11c590a3f908bbc4d287e647e2ee442394e7a1eb019d344368f95b95945f
|
data/README.md
CHANGED
@@ -31,7 +31,7 @@ Import the latest data with the import task:
|
|
31
31
|
```
|
32
32
|
rake usda:import
|
33
33
|
```
|
34
|
-
This is going to take a while.
|
34
|
+
This is going to take a while. 60+ minutes on my 2.66 GHz i7 macbook pro
|
35
35
|
|
36
36
|
Use the models to query and profit:
|
37
37
|
```
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class CreateUsdaWeights < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :usda_weights do |t|
|
4
|
+
t.string :nutrient_databank_number, null: false, index: true
|
5
|
+
t.string :sequence_number, null: false
|
6
|
+
t.float :amount, null: false
|
7
|
+
t.string :measurement_description, null: false
|
8
|
+
t.float :gram_weight, null: false
|
9
|
+
t.integer :num_data_points
|
10
|
+
t.float :standard_deviation
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -12,8 +12,10 @@ require 'usda_nutrient_database/import/food_groups'
|
|
12
12
|
require 'usda_nutrient_database/import/foods'
|
13
13
|
require 'usda_nutrient_database/import/foods_nutrients'
|
14
14
|
require 'usda_nutrient_database/import/nutrients'
|
15
|
+
require 'usda_nutrient_database/import/weights'
|
15
16
|
require 'usda_nutrient_database/railtie' if defined?(Rails)
|
16
17
|
require 'usda_nutrient_database/version'
|
18
|
+
require 'usda_nutrient_database/weight'
|
17
19
|
|
18
20
|
module UsdaNutrientDatabase
|
19
21
|
class << self
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module UsdaNutrientDatabase
|
2
|
+
module Import
|
3
|
+
class Weights < Base
|
4
|
+
def import
|
5
|
+
CSV.open(
|
6
|
+
"#{directory}/WEIGHT.txt", 'r:iso-8859-1:utf-8', csv_options
|
7
|
+
) do |csv|
|
8
|
+
csv.each do |row|
|
9
|
+
UsdaNutrientDatabase::Weight.create!(
|
10
|
+
nutrient_databank_number: row[0],
|
11
|
+
sequence_number: row[1], amount: row[2],
|
12
|
+
measurement_description: row[3], gram_weight: row[4],
|
13
|
+
num_data_points: row[5], standard_deviation: row[6]
|
14
|
+
)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -13,6 +13,7 @@ module UsdaNutrientDatabase
|
|
13
13
|
food_importer.import
|
14
14
|
nutrient_importer.import
|
15
15
|
foods_nutrient_importer.import
|
16
|
+
weights_importer.import
|
16
17
|
ensure
|
17
18
|
downloader.cleanup
|
18
19
|
end
|
@@ -36,6 +37,10 @@ module UsdaNutrientDatabase
|
|
36
37
|
UsdaNutrientDatabase::Import::FoodGroups.new("#{directory}/#{version}")
|
37
38
|
end
|
38
39
|
|
40
|
+
def weights_importer
|
41
|
+
UsdaNutrientDatabase::Import::Weights.new("#{directory}/#{version}")
|
42
|
+
end
|
43
|
+
|
39
44
|
def downloader
|
40
45
|
UsdaNutrientDatabase::Import::Downloader.new(directory, version)
|
41
46
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module UsdaNutrientDatabase
|
2
|
+
class Weight < ActiveRecord::Base
|
3
|
+
self.table_name = 'usda_weights'
|
4
|
+
|
5
|
+
validates :nutrient_databank_number, presence: true
|
6
|
+
validates :sequence_number, presence: true
|
7
|
+
validates :amount, presence: true
|
8
|
+
validates :measurement_description, presence: true
|
9
|
+
validates :gram_weight, presence: true
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe UsdaNutrientDatabase::Import::Weights do
|
4
|
+
let(:importer) { described_class.new('spec/support/sr25') }
|
5
|
+
|
6
|
+
describe '#import' do
|
7
|
+
before { importer.import }
|
8
|
+
|
9
|
+
it { expect(UsdaNutrientDatabase::Weight.count).to eql(3) }
|
10
|
+
end
|
11
|
+
end
|
@@ -14,5 +14,6 @@ describe UsdaNutrientDatabase::Importer do
|
|
14
14
|
it { expect(UsdaNutrientDatabase::Food.count).to eql(16) }
|
15
15
|
it { expect(UsdaNutrientDatabase::Nutrient.count).to eql(15) }
|
16
16
|
it { expect(UsdaNutrientDatabase::FoodsNutrient.count).to eql(12) }
|
17
|
+
it { expect(UsdaNutrientDatabase::Weight.count).to eql(11) }
|
17
18
|
end
|
18
19
|
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe UsdaNutrientDatabase::Weight do
|
4
|
+
it { should validate_presence_of(:nutrient_databank_number) }
|
5
|
+
it { should validate_presence_of(:sequence_number) }
|
6
|
+
it { should validate_presence_of(:amount) }
|
7
|
+
it { should validate_presence_of(:measurement_description) }
|
8
|
+
it { should validate_presence_of(:gram_weight) }
|
9
|
+
end
|
data/spec/schema.rb
CHANGED
@@ -49,4 +49,14 @@ ActiveRecord::Schema.define version: 0 do
|
|
49
49
|
t.string :add_mod_date
|
50
50
|
t.string :confidence_code
|
51
51
|
end
|
52
|
+
|
53
|
+
create_table :usda_weights, force: true do |t|
|
54
|
+
t.string :nutrient_databank_number, null: false, index: true
|
55
|
+
t.string :sequence_number, null: false
|
56
|
+
t.float :amount, null: false
|
57
|
+
t.string :measurement_description, null: false
|
58
|
+
t.float :gram_weight, null: false
|
59
|
+
t.integer :num_data_points
|
60
|
+
t.float :standard_deviation
|
61
|
+
end
|
52
62
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: usda-nutrient-database
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Beedle
|
@@ -196,6 +196,7 @@ files:
|
|
196
196
|
- db/migrate/2_create_usda_foods.rb
|
197
197
|
- db/migrate/3_create_usda_foods_nutrients.rb
|
198
198
|
- db/migrate/4_create_usda_nutrients.rb
|
199
|
+
- db/migrate/5_create_usda_weights.rb
|
199
200
|
- lib/tasks/usda_nutrient_database.rake
|
200
201
|
- lib/usda-nutrient-database.rb
|
201
202
|
- lib/usda_nutrient_database/configuration.rb
|
@@ -209,10 +210,12 @@ files:
|
|
209
210
|
- lib/usda_nutrient_database/import/foods.rb
|
210
211
|
- lib/usda_nutrient_database/import/foods_nutrients.rb
|
211
212
|
- lib/usda_nutrient_database/import/nutrients.rb
|
213
|
+
- lib/usda_nutrient_database/import/weights.rb
|
212
214
|
- lib/usda_nutrient_database/importer.rb
|
213
215
|
- lib/usda_nutrient_database/nutrient.rb
|
214
216
|
- lib/usda_nutrient_database/railtie.rb
|
215
217
|
- lib/usda_nutrient_database/version.rb
|
218
|
+
- lib/usda_nutrient_database/weight.rb
|
216
219
|
- spec/database.yml
|
217
220
|
- spec/lib/usda_nutrient_database/food_group_spec.rb
|
218
221
|
- spec/lib/usda_nutrient_database/food_spec.rb
|
@@ -222,8 +225,10 @@ files:
|
|
222
225
|
- spec/lib/usda_nutrient_database/import/foods_nutrients_spec.rb
|
223
226
|
- spec/lib/usda_nutrient_database/import/foods_spec.rb
|
224
227
|
- spec/lib/usda_nutrient_database/import/nutrients_spec.rb
|
228
|
+
- spec/lib/usda_nutrient_database/import/weights_spec.rb
|
225
229
|
- spec/lib/usda_nutrient_database/importer_spec.rb
|
226
230
|
- spec/lib/usda_nutrient_database/nutrient_spec.rb
|
231
|
+
- spec/lib/usda_nutrient_database/weight_spec.rb
|
227
232
|
- spec/schema.rb
|
228
233
|
- spec/spec_helper.rb
|
229
234
|
- spec/support/sr25.zip
|
@@ -231,6 +236,7 @@ files:
|
|
231
236
|
- spec/support/sr25/FOOD_DES.txt
|
232
237
|
- spec/support/sr25/NUTR_DEF.txt
|
233
238
|
- spec/support/sr25/NUT_DATA.txt
|
239
|
+
- spec/support/sr25/WEIGHT.txt
|
234
240
|
- usda-nutrient-database.gemspec
|
235
241
|
homepage: https://github.com/mattbeedle/usda-nutrient-database
|
236
242
|
licenses:
|
@@ -266,8 +272,10 @@ test_files:
|
|
266
272
|
- spec/lib/usda_nutrient_database/import/foods_nutrients_spec.rb
|
267
273
|
- spec/lib/usda_nutrient_database/import/foods_spec.rb
|
268
274
|
- spec/lib/usda_nutrient_database/import/nutrients_spec.rb
|
275
|
+
- spec/lib/usda_nutrient_database/import/weights_spec.rb
|
269
276
|
- spec/lib/usda_nutrient_database/importer_spec.rb
|
270
277
|
- spec/lib/usda_nutrient_database/nutrient_spec.rb
|
278
|
+
- spec/lib/usda_nutrient_database/weight_spec.rb
|
271
279
|
- spec/schema.rb
|
272
280
|
- spec/spec_helper.rb
|
273
281
|
- spec/support/sr25.zip
|
@@ -275,3 +283,4 @@ test_files:
|
|
275
283
|
- spec/support/sr25/FOOD_DES.txt
|
276
284
|
- spec/support/sr25/NUTR_DEF.txt
|
277
285
|
- spec/support/sr25/NUT_DATA.txt
|
286
|
+
- spec/support/sr25/WEIGHT.txt
|