openfoodfacts / openfoodfacts-dart

Open Food Facts API Wrapper
https://pub.dev/packages/openfoodfacts
Apache License 2.0
167 stars 67 forks source link

Nutrient: support xx_modifier #584

Open g123k opened 2 years ago

g123k commented 2 years ago

Hi everyone,

On the website, we can input a modifier (eg: > or <) and it's available through a field called modifier. Here is an example with the salt: "nutriments":{"fat":1,"fat_100g":1,"fat_modifier":">","fat_unit":"g","fat_value":1}

We should support that value on the Dart SDK. And will also fix https://github.com/openfoodfacts/smooth-app/issues/3135

monsieurtanuki commented 2 years ago

@g123k I used to see those modifiers, but they are not in the website, are they? Capture d’écran 2022-10-13 à 15 15 40

g123k commented 2 years ago

On the website, just change the value to ">892" and it will appear. By default, it's just like if it's an =892

monsieurtanuki commented 2 years ago

Thank you @g123k! So you mean that the full list of modifiers is as following, right?

g123k commented 2 years ago

@stephanegigandet or @alexgarel Could you confirm this, please?

stephanegigandet commented 2 years ago

There's no "=" value, it's the implicit meaning when there is no "xyz_modifier"field, but you should not send "=812", that won't work.

There is an additional "-" modifier: it means that the field is not specified on the packaging. (useful for fibers in particular).

stephanegigandet commented 2 years ago

e.g. if you input:

"-" for fibers "~0" for proteins "<10" for sugars

you will get this:

"nutriments": {
  "fiber_modifier": "-",
  "fruits-vegetables-nuts-estimate-from-ingredients_100g": 0,
  "fruits-vegetables-nuts-estimate-from-ingredients_serving": 0,
  "nova-group": 1,
  "nova-group_100g: 1,
  "nova-group_serving": 1,
  "proteins": 0,
  "proteins_100g": 0,
  "proteins_modifier": "~",
  "proteins_unit": "g",
  "proteins_value": 0,
  "sugars": 10,
  "sugars_100g": 10,
  "sugars_modifier": "<",
  "sugars_unit": "g",
  "sugars_value": 10
}