This repository has been archived by the owner on Jul 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 64046e7
Showing
23 changed files
with
988,503 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.history |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.history | ||
converter | ||
.gitignore | ||
db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Food Web | ||
|
||
Food Web is an open source project that makes it simple to access the USDA's [Nutrient Standard Reference Database](https://www.ars.usda.gov/northeast-area/beltsville-md/beltsville-human-nutrition-research-center/nutrient-data-laboratory/docs/sr28-download-files/). | ||
|
||
## Install | ||
|
||
```shell | ||
$ npm i -S foodweb | ||
``` | ||
|
||
## Methods | ||
|
||
TBA |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
var asciiHelper = function () { | ||
|
||
this.convert = function (raw,allowBoolean) { | ||
var newline = (/\r/g.test(raw)?"\r":"")+(/\n/g.test(raw)?"\n":""); | ||
raw = raw.split(newline); | ||
var addition = {}; | ||
for (var i in raw) { | ||
raw[i] = raw[i].split('^'); | ||
for (var o in raw[i]) { | ||
if (/^(-?[1-9]+\d*([.]\d+)?)$|^(-?0[.]\d*[1-9]+)$|^0$|^0.0$/.test(raw[i][o])) raw[i][o] = Number(raw[i][o]); | ||
if (typeof raw[i][o] === 'string') raw[i][o] = raw[i][o].replace(/^~(.*?)~$/,'$1'); | ||
if (raw[i][o] === 'Y'&&allowBoolean) raw[i][o] = true; | ||
if (raw[i][o] === 'N'&&allowBoolean) raw[i][o] = false; | ||
} | ||
} | ||
return raw; | ||
}; | ||
|
||
}; | ||
|
||
module.exports = new asciiHelper(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
var fs = require('fs'); | ||
var ascii = require('./component/ascii'); | ||
|
||
var foodDes = ascii.convert(fs.readFileSync('./../db/FOOD_DES.txt','ascii'), true); | ||
|
||
var searchDb = []; | ||
|
||
for (var i in foodDes) { | ||
var a = foodDes[i]; | ||
foodDes[i] = {}; | ||
foodDes[i].id = a[0]; //NDB_NO | ||
foodDes[i].group = a[1]; //FOOD GROUP | ||
if (a[5]) foodDes[i].maker = a[5]; | ||
if (a[6]) foodDes[i].hasExtra = a[6]; | ||
if (a[8]) foodDes[i].refuse = a[8]; | ||
foodDes[i].about = {}; | ||
foodDes[i].about.long = a[2]; | ||
foodDes[i].about.short = a[3]; | ||
if (a[2]) foodDes[i].keywords = a[2].replace(/[^ \w]+/g,'').replace(/[\s]+/g,' ').toLowerCase().split(' '); | ||
if (a[7]) foodDes[i].about.refuse = a[7]; | ||
foodDes[i].name = {}; | ||
if (a[9]) foodDes[i].name.sci = a[9]; | ||
if (a[4]) foodDes[i].name.alias = a[4]; | ||
foodDes[i].factor = {}; | ||
if (a[10]) foodDes[i].factor.n = a[10]; | ||
if (a[11]) foodDes[i].factor.pro = a[11]; | ||
if (a[12]) foodDes[i].factor.fat = a[12]; | ||
if (a[13]) foodDes[i].factor.cho = a[13]; | ||
searchDb.push({id: a[0], key: foodDes[i].keywords}); | ||
} | ||
|
||
fs.writeFileSync('./../json/src/searchDb.json', JSON.stringify(searchDb)); | ||
|
||
var footNote = ascii.convert(fs.readFileSync('./../db/FOOTNOTE.txt','ascii')); | ||
|
||
for (var i in foodDes) { | ||
for (var o in footNote) { | ||
foodDes[i].footnote = {}; | ||
if (foodDes[i].id === footNote[o][0]) { | ||
if (footNote[o][1]) foodDes[i].footnote.number = footNote[o][1]; | ||
if (footNote[o][2]) foodDes[i].footnote.type = footNote[o][2]; | ||
if (footNote[o][3]) foodDes[i].footnote.nutrient = footNote[o][3]; | ||
if (footNote[o][4]) foodDes[i].footnote.text = footNote[o][4]; | ||
} | ||
} | ||
} | ||
|
||
var foodGroup = ascii.convert(fs.readFileSync('./../db/FD_GROUP.txt','ascii')); | ||
fs.writeFileSync('./../json/src/foodGroup.json', JSON.stringify(foodGroup)); | ||
|
||
fs.writeFileSync('./../json/src/foodDb.json', JSON.stringify(foodDes)); |
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.