<<

NAME

ProductOpener::Food - functions related to food products and nutrition

DESCRIPTION

ProductOpener::Food contains functions specific to food products, in particular related to nutrition facts. This module provides functions It does not contain functions related to ingredients which are in the ProductOpener::Ingredients module.

..

%nutrients_tables

An array that condition how nutrients are displayed.

It is a list of nutrients names with eventual prefixes and suffixes:

#nutrient a leading # indicates a comment and will be ignored
!nutrient a leading ! indicates an important nutrient, they should always be shown
The level of each nutrient is indicated by leading dashes before its id:
nutrient - no dash for top nutrients
-sub-nutrient - for level 2
--sub-sub-nutrient - for level 3, etc.
nutrient- a - at the end indicates that the nutrient should be hidden and only shown if explicitly added.

is_beverage_for_nutrition_score_2021 ( $product_ref )

Determines if a product should be considered as a beverage for Nutri-Score computations, based on the product categories.

2021 Nutri-Score: Dairy drinks are not considered as beverages if they have at least 80% of milk.

is_beverage_for_nutrition_score_2023 ( $product_ref )

Determines if a product should be considered as a beverage for Nutri-Score computations, based on the product categories.

2023 Nutri-Score: Milk and dairy drinks are considered beverages.

is_water_for_nutrition_score( $product_ref )

Determines if a product should be considered as water for Nutri-Score computations, based on the product categories.

is_cheese_for_nutrition_score( $product_ref )

Determines if a product should be considered as cheese for Nutri-Score computations, based on the product categories.

is_fat_for_nutrition_score( $product_ref )

Determines if a product should be considered as fat for Nutri-Score (2021 version) computations, based on the product categories.

is_fat_oil_nuts_seeds_for_nutrition_score( $product_ref )

Determines if a product should be considered as fats / oils / nuts / seeds for Nutri-Score (2023 version) computations, based on the product categories.

From the 2022 main algorithm report update FINAL:

"This category includes fats and oils from plant or animal sources, including cream, margarines, butters and oils (as the current situation).

Additionally, the following products are included in this category, using the Harmonized System Nomenclature1 codes: - Nuts: 0801 0802 - Processed nuts: 200811 200819 - Ground nuts: 1202 - Seeds: 1204 (linseed) 1206 (sunflower)1207 (other seeds)

Of note chestnuts are excluded from the category."

is_red_meat_for_nutrition_score ( $product_ref )

Determines if a product should be considered as red meat for Nutri-Score (2023 version) computations, based on the product categories and/or ingredients.

From the 2022 main algorithm report update FINAL:

"Regarding the Codex Alimentarius classifications, the entire group 08.0 (Meat and meat products, including poultry and game and all its subgroups) is concerned, though not all food items in the individual sub-groups are concerned, only those containing red meat (see above). In the Harmonized System Classification, the codes correspond to the following:

Beef: o 0201 Meat of bovine animals, fresh or chilled o 0202 Meat of bovine animals, frozen Pork o 0203 Meat of swine, fresh, chilled or frozen Lamb: o 0204 Meat of sheep or goats, fresh, chilled or frozen Horse o 0205 Horse and equine meat Game and venison o 0208903000 Of game, other than of rabbits or hares o 02089060 Fresh, chilled or frozen reindeer meat and edible offal thereof Offals and processed meat (as red meat) o 0206 Edible offal of bovine animals, swine, sheep, goats, horses, asses, mules or hinnies, fresh, chilled or frozen o 0210 Meat and edible offal, salted, in brine, dried or smoked; edible flours and meals of meat or meat offal o 1601 sausages o 1602 Prepared or preserved meat, meat offal, blood or insects (excl. sausages and similar products, and meat extracts and juices) ▪ All those from swine, lamb or beef even as mixtures"

compute_nutriscore_2021_fruits_vegetables_nuts_colza_walnut_olive_oil($product_ref)

Compute the fruit % according to the Nutri-Score rules

<b>Warning</b> Also modifies product_ref->{misc_tags}

return

The fruit ratio

compute_nutriscore_2023_fruits_vegetables_legumes($product_ref)

Compute the % of fruits, vegetables and legumes for the Nutri-Score 2023 algorithm.

Differences with the 2021 version: - we use only the estimate from the ingredients or a conservative estimate from the product category - we do not use values estimated by users from ingredients list: too difficult to know what should be included or not

Arguments

$product_ref - ref to the product

Return values

Return undef if no value could be computed or estimated.

saturated_fat_ratio( $nutrition_ref )

Compute saturated_fat_ratio as needed for nutriscore

Arguments

$nutrition_ref - ref to the nutrition of a product

saturated_fat_0_because_of_fat_0 ($nutrition_ref)

Detect if we are in the special case where we can detect saturated fat is 0 because fat is 0

Arguments

$nutrition_ref - ref to the nutrition of a product

sugar_0_because_of_carbohydrates_0 ($nutrition_ref)

Detect if we are in the special case where we can detect sugars are 0 because carbohydrates are 0

Arguments

$nutrition_ref - ref to the nutrition of a product

compute_nutriscore_data( $products_ref, $preparation, $version )

Compute data for nutriscore computation.

<b>Warning:</b> it also modifies $product_ref

Arguments

$product_ref - ref to the product

$preparation - "as_sold" or "prepared"

$version - version of nutriscore to compute data for. Either "2021" or "2023". Default is "2021"

return

Ref to a mapping suitable to call compute_nutriscore_score_and_grade

remove_nutriscore_fields ( $product_ref )

is_nutriscore_applicable_to_the_product_categories($product_ref)

Check that the product has a category, that we know if it is a beverage or not, and that it is not in a category for which the Nutri-Score should not be computed (e.g. food for babies)

Return values

$category_available - 0 or 1

$nutriscore_applicable - 0 or 1

$not_applicable_category - undef or category id

has_category_that_should_have_prepared_nutrition_data($product_ref)

Check if the product should have prepared nutrition data, based on its categories.

Arguments

$product_ref - ref to the product

Return values

$category_tag - undef or category tag

Return the product category tag that should have prepared nutrition data, or undef if none.

check_availability_of_nutrients_needed_for_nutriscore ($product_ref)

Check that we know or can estimate the nutrients needed to compute the Nutri-Score of the product.

To compute the Nutri-Score, we use the nutrition.aggregated_set

Arguments

$product_ref - ref to the product

Return values

$nutrients_available 0 or 1

$preparation: "as_sold" or "prepared"

Indicates if the Nutri-Score should be computed on as sold or prepared values

$estimated: 0 or 1

Indicates if some of the nutrients needed were estimated

set_fields_for_current_version_of_nutriscore($product_ref, $current_version, $nutriscore_score, $nutriscore_grade)

We may compute several versions of the Nutri-Score grade and score. One version is considered "current". This function sets the product fields for the current version.

set_fields_comparing_nutriscore_versions($product_ref, $version1, $version2)

When we are migrating from one version of the Nutri-Score to another (e.g. 2021 vs 2023), we may compute both version for a time. This function sets temporary fields to ease the comparison of both versions.

Once the migration is complete, those fields will no longer be computed.

compute_nutriscore( $product_ref, $current_version = "2023" )

Determines if we have enough data to compute the Nutri-Score (category + nutrition facts), and if the Nutri-Score is applicable to the product the category.

Populates the data structure needed to compute the Nutri-Score and computes it.

compute_nutrient_levels ($product_ref)

Computes nutrient levels (low, moderate, high) for fat, saturated fat, sugars, salt/sodium and alcohol. The nutrient levels are also known as nutrition traffic lights.

We use the aggregated set to compute the levels.

create_nutrients_level_taxonomy ()

create_nutrients_level_taxonomy() creates the source file for the nutrients level taxonomy: /taxonomies/nutrient_levels.txt

It creates entries such as "High in saturated fat" in all languages.

compute_units_of_alcohol ($product_ref, $serving_size_in_ml)

calculate the number of units of alcohol in one serving of an alcoholic beverage. (https://en.wikipedia.org/wiki/Unit_of_alcohol)

compare_nutrients ($a_ref, $b_ref)

For each comparable nutrient in both $a_ref and $b_ref, compute what percent the $a_ref value differs from the $b_ref value

Arguments

$a_ref - ref to a product, a category, ajr etc.

$b_ref - ref to a structure with nutrient values to compare to

Return values

$nutrients_ref - ref to a hash with the nutrient values from $b_ref and the percent difference between $a_ref and $b_ref values

assign_categories_properties_to_product ( PRODUCT_REF )

Go through the categories of a product to apply category properties at the product level. The most specific categories are checked first. If the category has a value for the property, it is assigned to the product and the processing stop.

This function was first designed to assign a CIQUAL category to products, based on the mapping of the Open Food Facts categories to the French CIQUAL categories.

It may be used for other properties in the future.

agribalyse_food_code:en:42501 agribalyse_proxy_food_code:en:43244

get_nutrient_unit ( $nid, $cc )

Returns the unit of the nutrient.

We may have a unit specific to the country (e.g. US nutrition facts table using the International Unit for this nutrient, and Europe using mg)

<<