openfoodfacts / openfoodfacts-androidapp

(Legacy) Native version of Open Food Facts on Android - Coders & Decoders welcome 🤳🥫
https://android.openfoodfacts.org
Apache License 2.0
768 stars 447 forks source link

Prepared nutrition facts are not displayed #2177

Open teolemon opened 5 years ago

teolemon commented 5 years ago

image https://world.openfoodfacts.org/product/3033710065967/nesquik-nestle

image https://world.openfoodfacts.org/api/v0/product/3033710065967.json

You need to concatenate _prepared to the regular values

Example: https://world.openfoodfacts.org/product/3036812020704/gratinee-oignons-et-croutons-royco https://world.openfoodfacts.org/api/v0/product/3036812020704.json

{"salt_prepared_100g":0.850000000000001,"carbohydrates_unit":"","sodium_prepared":0.334645669291339,"fiber_prepared_value":"0.2","nutrition-score-fr":"3","proteins_prepared":0.6,"salt_prepared":0.850000000000001,"energy_prepared_serving":"292","fiber_prepared_serving":0.4,"sugars_prepared_value":"0.6","carbohydrates_prepared":"5","saturated-fat_prepared_value":"0.7","energy_prepared":"146","proteins_unit":"","fat_prepared_value":"1.4","sugars_prepared_100g":0.6,"sodium_prepared_serving":0.669,"nutrition-score-uk":"3","energy_prepared_value":"35","salt_unit":"","sodium_prepared_value":"0.334645669291339","nutrition-score-uk_100g":"3","salt_prepared_value":"0.85","saturated-fat_prepared_100g":0.7,"fat_unit":"","saturated-fat_prepared_serving":1.4,"carbohydrates_prepared_serving":"10","fat_prepared_serving":2.8,"sodium_prepared_100g":0.334645669291339,"proteins_prepared_100g":0.6,"sugars_prepared":0.6,"fat_prepared":1.4,"proteins_prepared_serving":1.2,"fiber_unit":"","salt_prepared_serving":1.7,"fiber_prepared_100g":0.2,"proteins_prepared_value":"0.6","fat_prepared_100g":1.4,"sugars_unit":"","sugars_prepared_serving":1.2,"energy_unit":"kcal","nutrition-score-fr_100g":"3","saturated-fat_prepared":0.7,"carbohydrates_prepared_100g":"5","carbohydrates_prepared_value":"5","saturated-fat_unit":"","energy_prepared_100g":"146","fiber_prepared":0.2}

It should probably be additional columns, but raises UX questions, since it can create up to 2 additional columns

yasnogor commented 5 years ago

I'd like to take this one.

teolemon commented 5 years ago

You can go ahead 👍

yasnogor commented 5 years ago

Actually, it looks like this is working fine now. Might have been fixed by PR #2027.

teolemon commented 5 years ago

No, someone added more info. Try with this one: https://barcode.tec-it.com/en/EAN13?data=7613034178527

teolemon commented 5 years ago

https://world.openfoodfacts.org/product/7613034178527/mon-1er-nesquik-nestle

yasnogor commented 5 years ago

It seems that the response from the server and the attributes that come back differs between these products.

Compare: Has the data - https://world.openfoodfacts.org/api/v0/product/3033710065967.json carbohydrates_100g proteins_100g Does not have this data - https://world.openfoodfacts.org/api/v0/product/7613034178527.json However, this server response does contain proteins_prepared_100g carbohydrates_prepared_100g

Should the app be looking for these later attributes?

yasnogor commented 5 years ago

It seems that the app code is looking for carbohydrates_100g and such data to be returned. If I change the attributes to carbohydrates_prepared_100g the data shows up fine in app. Should the app code be modified to look for X_prepared_100g if X_100g is not available in json? I'm not sure if this is an appropriate solution though.

yasnogor commented 5 years ago

I added some code to check if nutrient X_prepared is available in json when X isn't available. However, I'm not sure if this is an appropriate solution from business logic point of view. Does the server side need to be changed instead to include the missing attributes? I can create a PR if you'd like to take a look.

teolemon commented 5 years ago

Depending on what's available (non prepared, prepared, or both), I guess there might be a dropdown at the top of the table enabling to switch Or we could have a table that scrolls horizontally. @yasnogor