Jump to content

Nutrients handling in Open Food Facts: Difference between revisions

no edit summary
No edit summary
Line 31: Line 31:
Notes about the energy fields:
Notes about the energy fields:
* Energy on labels can be written in kcal, kJ or both
* Energy on labels can be written in kcal, kJ or both
* when the energy is written in both, there is no simple conversion ratio between kcal and kJ
* When the energy is written in both, there is no universally defined conversion ratio between kcal and kJ.
** This is because labelling laws in EU, US, CA etc. specify that the energy fields can (or must) be computed by multiplying and summing values for carbohydrates, proteins, fat etc.
** This is because labelling laws in EU, US, CA etc. specify that the energy fields can (or must) be computed by multiplying and summing values for carbohydrates, proteins, fat etc.
** That's why we now store 2 energy fields, and not just one
** That's why we now store 2 energy fields, and not just one
** see https://esha.com/calorie-calculation-country/ for details
** See https://esha.com/calorie-calculation-country/ for details
* energy-kj and energy-kcal are the identifiers (nutrient-id) of the "Energy in kJ" and "Energy in kcal" fields.
* <code>energy-kj</code> and <code>energy-kcal</code> are the identifiers (<code>{nutrient-id}</code>) of the "Energy in kJ" and "Energy in kcal" fields.
* old apps used to pass energy (as we had only one energy field instead of energy-kcal + energy-kj)
* Old apps used to pass energy (as we had only one energy field instead of energy-kcal + energy-kj)
** for those apps, the energy_unit field is used to populate the corresponding energy-kj or energy-kcal field
** For those apps, the <code>energy_unit</code> field is used to populate the corresponding <code>energy-kj</code> or <code>energy-kcal</code> field


==== Fields entered and computed by the OFF backend (Product Opener) ====
==== Fields entered and computed by the OFF backend (Product Opener) ====
Line 49: Line 49:
=== Data display ===
=== Data display ===


The OFF web site, and apps, should only use these OFF processed fields to display the nutrition data:
The OFF web site, and apps, '''should only use these OFF processed fields''' to display the nutrition data:


* <code>{nutrient-id}_100g</code> or <code>{nutrient-id}_serving</code> (depending on the value of nutrition_data_per): value in g or in kJ. The values are passed as float/double???
* <code>{nutrient-id}_100g</code> or <code>{nutrient-id}_serving</code> (depending on the value of nutrition_data_per): value in g or in kJ. The values are passed as float/double???
Line 56: Line 56:
The web site and apps '''must''':
The web site and apps '''must''':
* Indicate if the nutrition facts are per 100g or per serving.
* Indicate if the nutrition facts are per 100g or per serving.
* Convert the value in g or in kJ to the desired unit.
* Convert the value from g or kJ to the desired unit.


Notes:
Notes:
* Don't use the <code>{nutrient-id}_value</code> and <code>{nutrient-id}_unit</code> fields
* Don't use the <code>{nutrient-id}_value</code> and <code>{nutrient-id}_unit</code> fields
** The nutrient-id may be empty as some apps don't pass a unit, and we use a default unit for the field
** The <code>{nutrient-id}</code> may be empty as some apps don't pass a unit, and we use a default unit for the field
** The value may be per 100g or per serving
** The value may be per 100g or per serving


Line 69: Line 69:
(What does this mean? only allow editing of the off processed field)???
(What does this mean? only allow editing of the off processed field)???


== Possible improvements to make thing (a bit) simpler ==
== Possible improvements to make things (a bit) simpler ==


* In the API, rename the "nutrient-id" fields (such as energy-kj, saturated-fat) to "nutrient-id_value", so that it matches the name of the field stored. It also makes clearer where the value is coded.
* In the API, rename the "nutrient-id" fields (such as energy-kj, saturated-fat) to "nutrient-id_value", so that it matches the name of the field stored. It also makes clearer where the value is coded.
Line 77: Line 77:
** This would be a breaking change if some apps use the energy-kcal_100g/serving or energy-kj_100g/serving fields
** This would be a breaking change if some apps use the energy-kcal_100g/serving or energy-kj_100g/serving fields


== Possible improvements to make thing (a bit) more complex ==
== Possible improvements to make things (a bit) more complex ==


The current API does not allow to store values for the prepared product, but it can be done on the OFF web site.
The current API does not allow to store values for the prepared product, but it can be done on the OFF web site.
72

edits