Skip to content

Commit

Permalink
fix: Clean nutriments generation (#1112)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfauquette authored Dec 27, 2024
1 parent db3b743 commit 9fa6f01
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 173 deletions.
28 changes: 0 additions & 28 deletions src/assets/nutriments.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"unit": "kcal",
"display": true
},
{ "id": "energy", "name": "Energy", "unit": "kj" },
{
"id": "energy-from-fat",
"name": "Energy from fat",
Expand Down Expand Up @@ -188,40 +187,13 @@
{ "id": "caffeine", "name": "Caffeine", "unit": "mg" },
{ "id": "taurine", "name": "Taurine", "unit": "g" },
{ "id": "ph", "name": "PH", "unit": "" },
{
"id": "fruits-vegetables-nuts",
"name": "Fruits‚ vegetables‚ nuts and rapeseed‚ walnut and olive oils",
"unit": "%"
},
{
"id": "fruits-vegetables-nuts-dried",
"name": "Fruits‚ vegetables and nuts - dried",
"unit": "%"
},
{
"id": "fruits-vegetables-nuts-estimate",
"name": "Fruits‚ vegetables‚ nuts and rapeseed‚ walnut and olive oils (manual estimate from ingredients list)",
"unit": "%"
},
{
"id": "collagen-meat-protein-ratio",
"name": "Collagen/Meat protein ratio (maximum)",
"unit": "%"
},
{ "id": "cocoa", "name": "Cocoa (minimum)", "unit": "%" },
{ "id": "chlorophyl", "name": "Chlorophyl", "unit": "g" },
{ "id": "carbon-footprint", "name": "Carbon footprint", "unit": "g" },
{
"id": "carbon-footprint-from-meat-or-fish",
"name": "Carbon footprint from meat or fish",
"unit": "g"
},
{
"id": "nutrition-score-fr",
"name": "Nutrition score - France",
"unit": ""
},
{ "id": "nutrition-score-uk", "name": "Nutrition score - UK", "unit": "" },
{ "id": "glycemic-index", "name": "Glycemic Index", "unit": "" },
{ "id": "water-hardness", "name": "Water hardness", "unit": "mmol/l" },
{ "id": "choline", "name": "Choline", "unit": "g" },
Expand Down
144 changes: 0 additions & 144 deletions src/pages/nutrition/config.ts
Original file line number Diff line number Diff line change
@@ -1,145 +1 @@
export const UNITS = ["", "g", "mg", "µg"];

export const KNOWN_NUTRIMENTS = [
// Energy
"energy-kj",
"energy-kcal",

// Fat
"fat",
"saturated-fat",
"unsaturated-fat",
"monounsaturated-fat",
"polyunsaturated-fat",
"trans-fat",
"butyric-acid",
"caproic-acid",
"caprylic-acid",
"capric-acid",
"lauric-acid",
"myristic-acid",
"palmitic-acid",
"stearic-acid",
"arachidic-acid",
"behenic-acid",
"lignoceric-acid",
"cerotic-acid",
"montanic-acid",
"melissic-acid",

// Sucres
"carbohydrates",
"sugars",
"added-sugars",
"sucrose",
"glucose",
"fructose",
"lactose",
"maltose",
"maltodextrins",

"fiber",
"soluble-fiber",
"insoluble-fiber",

"proteins",
"casein",
"serum-proteins",

"salt",
"added-salt",
"sodium",

"cholesterol",

"alpha-linolenic-acid",
"eicosapentaenoic-acid",
"docosahexaenoic-acid",
"omega-3-fat",
"omega-6-fat",
"linoleic-acid",
"arachidonic-acid",
"gamma-linolenic-acid",
"dihomo-gamma-linolenic-acid",
"omega-9-fat",
"oleic-acid",
"elaidic-acid",
"gondoic-acid",
"mead-acid",
"erucic-acid",
"nervonic-acid",

"oligosaccharide",

"galactose",
"starch",
"Polydextrose",
"polyols",
"erythritol",

"nucleotides",
"alcohol",
"vitamin-a",
"beta-carotene",
"vitamin-d",
"vitamin-e",
"vitamin-k",
"vitamin-c",
"vitamin-b1",
"vitamin-b2",
"vitamin-pp",
"vitamin-b6",
"vitamin-b9",
"folates",
"vitamin-b12",
"biotin",
"pantothenic-acid",
"silica",
"bicarbonate",
"sulphate",
"nitrate",
"nydrogencarbonate",
"nitrite",
"potassium",
"chloride",
"calcium",
"phosphorus",
"iron",
"magnesium",
"zinc",
"copper",
"manganese",
"fluoride",
"selenium",
"chromium",
"molybdenum",
"iodine",
"caffeine",
"taurine",
"ph",
"collagen-meat-protein-ratio",
"cocoa",
"chlorophyl",
"glycemic-index",
"water-hardness",
"choline",
"phylloquinone",
"beta-glucan",
"inositol",
"carnitine",
"spermidine",
"water",
"acidity",
"dry-residue",
"beta-alanine",
"creatine",
"l-citrulline",
"l-glutamine",
"bcaa",
"l-valine",
"l-leucine",
"l-isoleucine",
"l-arginine",
"l-cysteine",
"l-Glutathione",
];
16 changes: 15 additions & 1 deletion update-nutriments.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
const fs = require("fs");
const axios = require("axios");

const idsToIgnore = [
"energy",
"fruits-vegetables-nuts",
"fruits-vegetables-nuts-dried",
"fruits-vegetables-nuts-estimate",
"carbon-footprint",
"carbon-footprint-from-meat-or-fish",
"nutrition-score-fr",
"nutrition-score-uk",
];
function parseNutrients(data, depth = 0) {
return data.flatMap((item) => {
const { display_in_edit_form, unit, id, name, nutrients } = item;
Expand Down Expand Up @@ -31,7 +41,11 @@ axios("https://world.openfoodfacts.org/cgi/nutrients.pl")
.then(({ data }) => {
fs.writeFile(
"./src/assets/nutriments.json",
JSON.stringify(parseNutrients(data.nutrients)),
JSON.stringify(
parseNutrients(data.nutrients).filter(
({ id }) => !idsToIgnore.includes(id),
),
),
() => console.log("nutriments updated"),
);
})
Expand Down

0 comments on commit 9fa6f01

Please sign in to comment.