openfoodfacts / openfoodfacts-server

Open Food Facts database, API server and web interface - 🐪🦋 Perl, CSS and JS coders welcome 😊 For helping in Python, see Robotoff or taxonomy-editor
http://openfoodfacts.github.io/openfoodfacts-server/
GNU Affero General Public License v3.0
660 stars 389 forks source link

Remove non-significant digits from nutrition values passed to the API #3483

Open stephanegigandet opened 4 years ago

stephanegigandet commented 4 years ago

Yuka seems now to pass floating point values with non significant digits.

e.g. https://fr.openfoodfacts.org/api/v0/produit/2227153013512/terrine-de-campagne

carbohydrates: 2.9000000953674, sugars: 1.6000000238419,

https://fr.openfoodfacts.org/api/v0/produit/8001420001624/riso-arborio-gallo-1-kg

saturated-fat: 0.89999997615814, sodium_100g: 0.359999990463256, sugars_value: 2.5999999046326,

Those values are bogus, due to how they store numbers internally. We should remove non significant digits. (and make sure 0.359999990463256 becomes 0.36)

We also need to fix existing products with that kind of values.

hangy commented 4 years ago

Those values are bogus, due to how they store numbers internally. We should remove non significant digits. (and make sure 0.359999990463256 becomes 0.36)

But that's just one app that's sending decimals as floats with low precision (or something like that). Other apps might use slower but more precise data types for these values. Also, the website allows entering arbitrary strings, and that kind of truncation might be unexpected.

stephanegigandet commented 4 years ago

Other apps might use slower but more precise data types for these values. Also, the website allows entering arbitrary strings, and that kind of truncation might be unexpected.

Any value with 0000 or 9999 in the decimals in it is not an actual nutrient value that comes from a product label, there is never such a precision in values.

VaiTon commented 4 years ago

Has this been fixed by #3489? @stephanegigandet

stephanegigandet commented 4 years ago

@VaiTon : not yet, I made a function to remove the non-significant digits, but it has not been plugged to the API, and we have not run it against existing products.

github-actions[bot] commented 9 months ago

This issue has been open 90 days with no activity. Can you give it a little love by linking it to a parent issue, adding relevant labels and projets, creating a mockup if applicable, adding code pointers from https://github.com/openfoodfacts/openfoodfacts-server/blob/main/.github/labeler.yml, giving it a priority, editing the original issue to have a more comprehensive description… Thank you very much for your contribution to 🍊 Open Food Facts