From 6a2bace7300bd0caf7ef0c604dd0c22a48994e8f Mon Sep 17 00:00:00 2001 From: alex Date: Wed, 11 Dec 2024 23:25:06 +0100 Subject: [PATCH] only-known-nutriments --- src/pages/nutrition/config.ts | 18 +++++------------- src/pages/nutrition/index.tsx | 10 +++++----- src/pages/nutrition/utils.ts | 6 +++--- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/src/pages/nutrition/config.ts b/src/pages/nutrition/config.ts index c998769a5..eff1c0075 100644 --- a/src/pages/nutrition/config.ts +++ b/src/pages/nutrition/config.ts @@ -1,14 +1,6 @@ export const UNITS = ["", "g", "mg", "µg"]; -export const OFF_NUTRIMENTS_TO_IGNORE = [ - "serving", - "energy", // Already available with energy kj and kcal. - "fruits-vegetables-legumes-estimate-from-ingredients", - "fruits-vegetables-nuts-estimate-from-ingredients", - "nova-group", - "nutrition-score-fr", -]; -export const NUTRIMENTS_ORDER = [ +export const KNOWN_NUTRIMENTS = [ // Energy "energy-kj", "energy-kcal", @@ -104,10 +96,10 @@ export const NUTRIMENTS_ORDER = [ "pantothenic-acid", "silica", "bicarbonate", - "Sulphate", - "Nitrate", - "Hydrogencarbonate", - "Nitrite", + "sulphate", + "nitrate", + "nydrogencarbonate", + "nitrite", "potassium", "chloride", "calcium", diff --git a/src/pages/nutrition/index.tsx b/src/pages/nutrition/index.tsx index 19a5228d1..0cc529dc7 100644 --- a/src/pages/nutrition/index.tsx +++ b/src/pages/nutrition/index.tsx @@ -15,7 +15,7 @@ import { ErrorBoundary } from "../taxonomyWalk/Error"; import LinksToProduct from "./LinksToProduct"; import { NutrimentCell } from "./NutrimentCell"; import PictureSection from "./PictureSection"; -import { NUTRIMENTS_ORDER } from "./config"; +import { KNOWN_NUTRIMENTS } from "./config"; export default function Nutrition() { const [partiallyFilled, setPartiallyFilled] = React.useState(false); @@ -65,14 +65,14 @@ export default function Nutrition() { })); }, [insight]); - const nutrimentsDetected = React.useMemo( + const nutrimentsDisplayed = React.useMemo( () => structurePredictions(values, product, additionalIds), [values, product, additionalIds], ); const notUsedNutriments = React.useMemo( - () => NUTRIMENTS_ORDER.filter((id) => !nutrimentsDetected.includes(id)), - [nutrimentsDetected], + () => KNOWN_NUTRIMENTS.filter((id) => !nutrimentsDisplayed.includes(id)), + [nutrimentsDisplayed], ); return ( @@ -157,7 +157,7 @@ export default function Nutrition() { - {nutrimentsDetected.map((nutrimentId) => { + {nutrimentsDisplayed.map((nutrimentId) => { const key100g = `${nutrimentId}_100g`; const { value: value100g, unit: unit100g } = values[key100g] ?? {}; diff --git a/src/pages/nutrition/utils.ts b/src/pages/nutrition/utils.ts index e4f919e78..98a6288ed 100644 --- a/src/pages/nutrition/utils.ts +++ b/src/pages/nutrition/utils.ts @@ -1,5 +1,5 @@ import axios from "axios"; -import { OFF_NUTRIMENTS_TO_IGNORE, UNITS } from "./config"; +import { KNOWN_NUTRIMENTS, UNITS } from "./config"; import { NutrimentPrediction } from "./insight.types"; import { ROBOTOFF_API_URL } from "../../const"; @@ -32,7 +32,7 @@ export function structurePredictions( Object.keys(predictions).forEach((key) => { const id = key.split("_")[0]; // split 'energy-kj_100g' to only get 'energy-kj' - if (OFF_NUTRIMENTS_TO_IGNORE.includes(id)) { + if (!KNOWN_NUTRIMENTS.includes(id)) { return; } if (!nurimentsIds.includes(id)) { @@ -43,7 +43,7 @@ export function structurePredictions( Object.keys(productValue?.nutriments ?? {}).forEach((key) => { const id = key.split("_")[0]; // split 'energy-kj_100g' to only get 'energy-kj' - if (OFF_NUTRIMENTS_TO_IGNORE.includes(id)) { + if (!KNOWN_NUTRIMENTS.includes(id)) { return; } if (!nurimentsIds.includes(id)) {