Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix carbs value when importing from USDA #622

Merged
merged 2 commits into from
Sep 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions metadata/en-US/changelogs/30405.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
- added ability to export diary as CSV file
- improved Open Food Facts search integration
- carbs values of items imported from USDA no longer include fiber
- added support for Serbian language (Cyrillic and Latin)
- various bugfixes

Expand Down
16 changes: 13 additions & 3 deletions www/activities/foodlist/js/usda.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,25 @@ app.USDA = {
let value = app.Utils.convertUnit(n.value, n.unitName, units[x]);
result.nutrition[x] = Math.round(value * multiplier * 100) / 100;

if (x == "sodium")
result.nutrition.salt = result.nutrition.sodium * 0.0025;

break;
}
}
}
});

// The USDA db only contains values for sodium, but not for salt
if (result.nutrition.sodium !== undefined) {
result.nutrition.salt = result.nutrition.sodium * 0.0025;
}

// The carbs values in the USDA db include fiber, but we don't want that
if (result.nutrition.carbohydrates && result.nutrition.fiber) {
let correctedCarbs = result.nutrition.carbohydrates - result.nutrition.fiber;
if (correctedCarbs < result.nutrition.sugars || 0)
correctedCarbs = result.nutrition.sugars || 0;
result.nutrition.carbohydrates = correctedCarbs;
}

return result;
},

Expand Down