Skip to content

Commit

Permalink
only-known-nutriments
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfauquette committed Dec 11, 2024
1 parent f6e0fae commit 6a2bace
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 21 deletions.
18 changes: 5 additions & 13 deletions src/pages/nutrition/config.ts
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -104,10 +96,10 @@ export const NUTRIMENTS_ORDER = [
"pantothenic-acid",
"silica",
"bicarbonate",
"Sulphate",
"Nitrate",
"Hydrogencarbonate",
"Nitrite",
"sulphate",
"nitrate",
"nydrogencarbonate",
"nitrite",
"potassium",
"chloride",
"calcium",
Expand Down
10 changes: 5 additions & 5 deletions src/pages/nutrition/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 (
<React.Suspense>
Expand Down Expand Up @@ -157,7 +157,7 @@ export default function Nutrition() {
</tr>
</thead>
<tbody>
{nutrimentsDetected.map((nutrimentId) => {
{nutrimentsDisplayed.map((nutrimentId) => {
const key100g = `${nutrimentId}_100g`;
const { value: value100g, unit: unit100g } =
values[key100g] ?? {};
Expand Down
6 changes: 3 additions & 3 deletions src/pages/nutrition/utils.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -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)) {
Expand All @@ -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)) {
Expand Down

0 comments on commit 6a2bace

Please sign in to comment.