Skip to content

Commit

Permalink
fix: remove old carbon footprint fields (#7541)
Browse files Browse the repository at this point in the history
This is to remove old carbon footprint fields (and associated computations) we implemented before the Eco-Score.

Co-authored-by: Alex Garel <alex@garel.org>
  • Loading branch information
stephanegigandet and alexgarel committed Oct 19, 2022
1 parent 7ae35ea commit d5e459d
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 323 deletions.
2 changes: 0 additions & 2 deletions cgi/product_jqm_multilingual.pl
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,6 @@
extract_ingredients_from_text($product_ref);
extract_ingredients_classes_from_text($product_ref);
detect_allergens_from_text($product_ref);
compute_carbon_footprint_from_ingredients($product_ref);
compute_carbon_footprint_from_meat_or_fish($product_ref);

# Food category rules for sweeetened/sugared beverages
# French PNNS groups from categories
Expand Down
4 changes: 0 additions & 4 deletions cgi/product_multilingual.pl
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,11 @@ ()
my @fields = @ProductOpener::Config::product_fields;

if ($admin) {
push @fields, "environment_impact_level";

# Let admins edit any other fields
if (defined single_param("fields")) {
push @fields, split(/,/, single_param("fields"));
}

}

if (($action eq 'process') and (($type eq 'add') or ($type eq 'edit'))) {
Expand Down Expand Up @@ -585,8 +583,6 @@ ()
extract_ingredients_classes_from_text($product_ref);
$log->debug("detect_allergens_from_text") if $log->is_debug();
detect_allergens_from_text($product_ref);
compute_carbon_footprint_from_ingredients($product_ref);
compute_carbon_footprint_from_meat_or_fish($product_ref);

# Food category rules for sweetened/sugared beverages
# French PNNS groups from categories
Expand Down
21 changes: 2 additions & 19 deletions lib/ProductOpener/Display.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5165,15 +5165,6 @@ sub customize_response_for_product ($request_ref, $product_ref) {
localize_ecoscore($cc, $product_ref);

foreach my $field (split(/,/, $fields)) {

# On demand carbon footprint tags -- deactivated: the environmental footprint infocard is now replaced by the Eco-Score details
if (0 and (not $carbon_footprint_computed) and ($field =~ /^environment_infocard/)
or ($field =~ /^environment_impact_level/))
{
compute_carbon_footprint_infocard($product_ref);
$carbon_footprint_computed = 1;
}

if ($field eq "product_display_name") {
$customized_product_ref->{$field} = remove_tags_and_quote(product_name_brand_quantity($product_ref));
}
Expand All @@ -5183,8 +5174,8 @@ sub customize_response_for_product ($request_ref, $product_ref) {
$customized_product_ref->{$field} = display_nutrition_table($product_ref, undef);
}

# The environment infocard now displays the Eco-Score details
elsif (($field =~ /^environment_infocard/) or ($field eq "ecoscore_details_simple_html")) {
# Eco-Score details in simple HTML
elsif ($field eq "ecoscore_details_simple_html") {
if ((1 or $show_ecoscore) and (defined $product_ref->{ecoscore_data})) {
$customized_product_ref->{$field}
= display_ecoscore_calculation_details_simple_html($cc, $product_ref->{ecoscore_data});
Expand Down Expand Up @@ -8648,14 +8639,6 @@ HTML

$template_data_ref->{admin} = $admin;

# the carbon footprint infocard has been replaced by the Eco-Score details
if (0 and $admin) {
compute_carbon_footprint_infocard($product_ref);
$template_data_ref->{display_field_environment_infocard} = display_field($product_ref, 'environment_infocard');
$template_data_ref->{carbon_footprint_from_meat_or_fish_debug}
= $product_ref->{"carbon_footprint_from_meat_or_fish_debug"};
}

# Platform for producers: data quality issues and improvements opportunities

if ($server_options{producers_platform}) {
Expand Down
133 changes: 0 additions & 133 deletions lib/ProductOpener/Food.pm
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ BEGIN {
&compute_unknown_nutrients
&compute_nutrient_levels
&compute_units_of_alcohol
&compute_carbon_footprint_infocard
&compare_nutriments
Expand Down Expand Up @@ -1727,138 +1726,6 @@ sub compute_serving_size_data ($product_ref) {
return;
}

sub compute_carbon_footprint_infocard ($product_ref) {

# compute the environment impact level
# -> currently only for prepared meals

# Limit to France, as the carbon values from ADEME are intended for France

if (
not( (has_tag($product_ref, "countries", "en:france"))
and (defined $product_ref->{ingredients_text})
and (length($product_ref->{ingredients_text}) > 5))
)
{

my @product_fields_to_delete = (
"environment_impact_level", "environment_impact_level_tags",
"environment_infocard", "environment_infocard_en",
"environment_infocard_fr"
);

remove_fields($product_ref, \@product_fields_to_delete);

return;
}

if (has_tag($product_ref, "categories", "en:meals")) {

$product_ref->{environment_impact_level} = "en:low";

if ( (defined $product_ref->{nutriments})
and (defined $product_ref->{nutriments}{"carbon-footprint-from-meat-or-fish_product"}))
{

if ($product_ref->{nutriments}{"carbon-footprint-from-meat-or-fish_product"} < 250) {
$product_ref->{environment_impact_level} = "en:medium";
}
else {
$product_ref->{environment_impact_level} = "en:high";
}
}

$product_ref->{environment_impact_level_tags} = [$product_ref->{environment_impact_level}];
}

# compute the carbon footprint infocard when we have a carbon footprint from meat or fish

if ( (defined $product_ref->{nutriments})
and (defined $product_ref->{nutriments}{"carbon-footprint-from-meat-or-fish_product"}))
{

foreach my $lang ("en", "fr") {
my $html = "<h2>" . $Lang{carbon_impact_from_meat_or_fish}{$lang} . "</h2>";

$html .= "<ul>\n";

$html
.= "<li><b>"
. (
sprintf("%.2e", $product_ref->{nutriments}{"carbon-footprint-from-meat-or-fish_product"} / 1000) + 0.0)
. " kg</b> "
. $Lang{of_carbon_impact_from_meat_or_fish_for_whole_product}{$lang};

if (defined $product_ref->{nutriments}{"carbon-footprint-from-meat-or-fish_serving"}) {
$html
.= " (<b>"
. (
sprintf("%.2e", $product_ref->{nutriments}{"carbon-footprint-from-meat-or-fish_serving"} / 1000)
+ 0.0)
. " kg</b> "
. $Lang{for_one_serving}{$lang} . ")";
}

$html .= "</li>\n";

# COP 21 sustainable amount of CO2 per person per year: 2 tons
my %sustainable = (annual => 2000 * 1000);
$sustainable{daily} = $sustainable{annual} / 365;
$sustainable{weekly} = $sustainable{daily} * 7;

foreach my $period ("daily", "weekly") {

$html .= "<li><b>"
. (
sprintf("%.2e",
$product_ref->{nutriments}{"carbon-footprint-from-meat-or-fish_product"}
/ $sustainable{$period}
* 100) + 0.0
)
. "%</b> "
. $Lang{"of_sustainable_" . $period . "_emissions_of_1_person"}{$lang};
if (defined $product_ref->{nutriments}{"carbon-footprint-from-meat-or-fish_serving"}) {
$html .= " (<b>"
. (
sprintf("%.2e",
$product_ref->{nutriments}{"carbon-footprint-from-meat-or-fish_serving"}
/ $sustainable{$period}
* 100) + 0.0
)
. "%</b> "
. $Lang{for_one_serving}{$lang} . ")";
}

$html .= "</li>\n";
}

$html .= "</ul>";

$html .= "<br><br>";

$html
.= "<h3>"
. $Lang{methodology}{$lang} . "</h3>" . "<p>"
. $Lang{carbon_footprint_note_foodges_ademe}{$lang} . "</p>" . "<p>"
. $Lang{carbon_footprint_note_sustainable_annual_emissions}{$lang} . "</p>" . "<p>"
. $Lang{carbon_footprint_note_uncertainty}{$lang} . "</p>";

$product_ref->{"environment_infocard_" . $lang} = $html;
}

# copy the main language
if (defined $product_ref->{"environment_infocard_" . $product_ref->{lc}}) {
$product_ref->{environment_infocard} = $product_ref->{"environment_infocard_" . $product_ref->{lc}};
}
else {
$product_ref->{environment_infocard} = $product_ref->{environment_infocard_en};
}
}

return;
}

sub compute_unknown_nutrients ($product_ref) {

$product_ref->{unknown_nutrients_tags} = [];
Expand Down

0 comments on commit d5e459d

Please sign in to comment.