<<

NAME

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

SYNOPSIS

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

DESCRIPTION

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.

VARIABLES

%environmental_score_countries_enabled

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.

FUNCTIONS

load_agribalyse_data()

Loads the AgriBalyse database.

load_environmental_score_data_origins_of_ingredients_distances ( $product_ref )

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

load_environmental_score_data_origins_of_ingredients( $product_ref )

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)

load_environmental_score_data_packaging( $product_ref )

Loads packaging data needed to compute the Environmental-Score.

load_environmental_score_data( $product_ref )

Loads data needed to compute the Environmental-Score.

compute_environmental_score( $product_ref )

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

Arguments

Product reference $product_ref

Return values

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

compute_environmental_score() computes the Life Cycle Analysis (LCA) part of the Environmental-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->{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.

compute_environmental_score_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->{environmental_score_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/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

compute_environmental_score_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_environmental_score_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 Environmental-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

Note: the country EPI is not taken into account if the product already has a bonus for the production system.

compute_environmental_score_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_environmental_score ( $cc, $product_ref)

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.

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.

environmental_score_extended_data_expected_error ( $product_ref)

Expected error of the Environmental-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.

<<