<<

NAME

ProductOpener::Ecoscore - compute the Ecoscore environmental grade of a food product

SYNOPSIS

ProductOpener::Ecoscore is used to compute the Ecoscore environmental grade of a food product.

DESCRIPTION

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.

VARIABLES

%ecoscore_countries_enabled

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.

FUNCTIONS

load_agribalyse_data()

Loads the AgriBalyse database.

load_ecoscore_data_origins_of_ingredients_distances ( $product_ref )

Loads origins of ingredients distances data needed to compute the Eco-Score.

load_ecoscore_data_origins_of_ingredients( $product_ref )

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)

load_ecoscore_data_packaging( $product_ref )

Loads packaging data needed to compute the Eco-Score.

load_ecoscore_data( $product_ref )

Loads data needed to compute the Eco-Score.

compute_ecoscore( $product_ref )

compute_ecoscore() computes the Eco-Score of a food product, and stores the details of the computation.

Arguments

Product reference $product_ref

Return values

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_agribalyse ( $product_ref )

compute_ecoscore() computes the Life Cycle Analysis (LCA) part of the Eco-Score, based on the French AgriBalyse database.

Arguments

Product reference $product_ref

Return values

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.

compute_ecoscore_production_system_adjustment ( $product_ref )

Computes an adjustment (bonus or malus) based on production system of the product (e.g. organic).

Arguments

Product reference $product_ref

Return values

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:

Notes

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

compute_ecoscore_threatened_species_adjustment ( $product_ref )

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.

Arguments

Product reference $product_ref

Return values

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

aggregate_origins_of_ingredients ( $default_origins_ref, $aggregated_origins_ref, $ingredient_ref )

Computes adjustments(bonus or malus for transportation + EPI / Environmental Performance Index) according to the countries of origin of the ingredients.

Arguments

Default origins reference: $default_origins_ref

Array of origins specified in the origins field, that we will use for ingredients that do not have a specific origin.

Aggregated origins reference $aggregated_origins_ref

Data structure to which we will add the percentages for the ingredient specified in $ingredient_ref

Ingredient reference $ingredient_ref

Ingredient reference that may contains an ingredients structure for sub-ingredients.

Return values

The percentages are stored in $aggregated_origins_ref

get_country_origin_from_origins ( $origins_ref )

Given a list of origins, return the country for the first origin that is a country or a child of a country.

compute_ecoscore_origins_of_ingredients_adjustment ( $product_ref )

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.

Arguments

Product reference $product_ref

Return values

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

compute_ecoscore_packaging_adjustment ( $product_ref )

Computes adjustments (malus) based on the packaging of the product.

Arguments

Product reference $product_ref

Return values

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

localize_ecoscore ( $cc, $product_ref)

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.

Arguments

Country code of the request $cc

Product reference $product_ref

Return values

The adjustment value and computations details are stored in the product reference passed as input parameter.

ecoscore_extended_data_expected_error ( $product_ref)

Expected error of the Eco-Score extended data from the impact estimator, based on % of uncharacterized ingredients and standard deviation.

Arguments

Product reference $product_ref

Return values

The expected error as float.

<<