ProductOpener::EnvironmentalScore - compute the EnvironmentalScore environmental grade of a food product
ProductOpener::EnvironmentalScore
is used to compute the EnvironmentalScore environmental grade of a food product.
The modules implements the Environmental-Score computation as defined by a collective that Open Food Facts is part of.
It is based on the French AgriBalyse V3 database that contains environmental impact values for 2500 food product categories.
AgriBalyse provides Life Cycle Analysis (LCA) values for food products categories, and some adjustments to the score are made for actual specific products using data about labels, origins of ingredients, packagings etc.
List of countries for which we are going to compute and display the Environmental-Score.
The list is different from %environmental_score_countries that can contain more countries for which we have some data to compute the Environmental-Score (e.g. distances).
2021-10-28: we will now enable Environmental-Score for all available countries, so this list will be overrode when we load the Environmental-Score data.
Loads the AgriBalyse database.
Loads origins of ingredients distances data needed to compute the Environmental-Score.
Loads origins of ingredients data needed to compute the Environmental-Score.
Data contains: - EPI score for each origin - Original transportation score for France, as defined in Environmental-Score original specification (distances in distances.csv have been recomputed in a slightly different way, and the scores for France slightly differ from the original ones)
Loads packaging data needed to compute the Environmental-Score.
Loads data needed to compute the Environmental-Score.
compute_environmental_score()
computes the Environmental-Score of a food product,
and stores the details of the computation.
The Environmental-Score score and computations details are stored in the product reference passed as input parameter.
Returned values:
- environmental_score_score : numeric Environmental-Score value - environmental_score_grade : corresponding A to E grade - environmental_score_data : Environmental-Score computation details
compute_environmental_score()
computes the Life Cycle Analysis (LCA) part of the Environmental-Score,
based on the French AgriBalyse database.
The LCA score and computations details are stored in the product reference passed as input parameter.
Returned values:
$product_ref->{agribalyse} hash with: -
$product_ref->{environmental_score_data}{missing} hash with: - categories if the product does not have a category - agb_category if the product does not have an Agribalyse match or proxy match for at least one of its categories.
Computes an adjustment (bonus or malus) based on production system of the product (e.g. organic).
The adjustment value and computations details are stored in the product reference passed as input parameter.
Returned values:
$product_ref->{adjustments}{production_system} hash with: -
$product_ref->{environmental_score_data}{missing} hash with:
This function tests the presence of specific labels and categories that should not be renamed. They are listed in the t/environmental_score.t test file so that the test fail if they are renamed.
The labels are listed in the Environmental-Score documentation: https://docs.score-environnemental.com/methodologie/produit/label
Computes an adjustment (malus) if the ingredients are harmful to threatened species. e.g. threatened fishes, or ingredients like palm oil that threaten the habitat of threatened species.
The adjustment value and computations details are stored in the product reference passed as input parameter.
Returned values:
$product_ref->{adjustments}{threatened_species} hash with: - value: malus (-10 for palm oil) - ingredient: the id of the ingredient responsible for the malus
Computes adjustments(bonus or malus for transportation + EPI / Environmental Performance Index) according to the countries of origin of the ingredients.
Array of origins specified in the origins field, that we will use for ingredients that do not have a specific origin.
Data structure to which we will add the percentages for the ingredient specified in $ingredient_ref
Ingredient reference that may contains an ingredients structure for sub-ingredients.
The percentages are stored in $aggregated_origins_ref
Given a list of origins, return the country for the first origin that is a country or a child of a country.
Computes adjustments(bonus or malus for transportation + EPI / Environmental Performance Index) according to the countries of origin of the ingredients.
The transportation bonus or malus is computed for all the countries where the Environmental-Score is enabled.
The adjustment value and computations details are stored in the product reference passed as input parameter.
Returned values:
$product_ref->{adjustments}{origins_of_ingredients} hash with: - value_[country code]: combined bonus or malus for transportation + EPI - epi_value - transportation_value_[country code] - aggregated origins: sorted array of origin + percent to show the % of ingredients by country used in the computation
Note: the country EPI is not taken into account if the product already has a bonus for the production system.
Computes adjustments (malus) based on the packaging of the product.
The adjustment value and computations details are stored in the product reference passed as input parameter.
Returned values:
$product_ref->{adjustments}{packaging} hash with: - value: malus for packaging - packagings: details of the computation
The Environmental-Score and some of its components depend on the country of the consumer, as we take transportation to the consumer into account.
We compute the Environmental-Score for all countries, and this function copies the values for a specific country to the main Environmental-Score fields.
Note: even if we could not compute the Environmental-Score (because of a missing category), we still localize the origins of ingredients, so that it can be displayed in separate knowledge panels.
The adjustment value and computations details are stored in the product reference passed as input parameter.
Expected error of the Environmental-Score extended data from the impact estimator, based on % of uncharacterized ingredients and standard deviation.
The expected error as float.