ProductOpener::Ecoscore - compute the Ecoscore environmental grade of a food product
ProductOpener::Ecoscore
is used to compute the Ecoscore environmental grade of a food product.
The modules implements the Eco-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 Eco-Score.
The list is different from %ecoscore_countries that can contain more countries for which we have some data to compute the Eco-Score (e.g. distances).
2021-10-28: we will now enable Eco-Score for all available countries, so this list will be overrode when we load the Eco-Score data.
Loads the AgriBalyse database.
Loads origins of ingredients distances data needed to compute the Eco-Score.
Loads origins of ingredients data needed to compute the Eco-Score.
Data contains: - EPI score for each origin - Original transportation score for France, as defined in Eco-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 Eco-Score.
Loads data needed to compute the Eco-Score.
compute_ecoscore()
computes the Eco-Score of a food product,
and stores the details of the computation.
The Eco-Score score and computations details are stored in the product reference passed as input parameter.
Returned values:
- ecoscore_score : numeric Eco-Score value - ecoscore_grade : corresponding A to E grade - ecoscore_data : Eco-Score computation details
compute_ecoscore()
computes the Life Cycle Analysis (LCA) part of the Eco-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->{ecoscore_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->{ecoscore_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/ecoscore.t test file so that the test fail if they are renamed.
The labels are listed in the Eco-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 Eco-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 Eco-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 Eco-Score for all countries, and this function copies the values for a specific country to the main Eco-Score fields.
Note: even if we could not compute the Eco-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 Eco-Score extended data from the impact estimator, based on % of uncharacterized ingredients and standard deviation.
The expected error as float.