Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: better display of Eco-Score details #10934

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/ProductOpener/Display.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2462,8 +2462,7 @@ HTML
}
}
elsif ($request_ref->{groupby_tagtype} eq 'ecoscore') {
$categories
= "'A+','A','B','C','D','E',,'F','" . lang("not_applicable") . "','" . lang("unknown") . "'";
$categories = "'A+','A','B','C','D','E','F','" . lang("not_applicable") . "','" . lang("unknown") . "'";
$colors = "'#1E8F4E','#1E8F4E','#60AC0E','#EEAE0E','#FF6F1E','#DF1F1F','#DF1F1F','#a0a0a0','#a0a0a0'";
$series_data = '';
foreach my $ecoscore_grade ('a-plus', 'a', 'b', 'c', 'd', 'e', 'f', 'not-applicable', 'unknown') {
Expand Down
14 changes: 12 additions & 2 deletions lib/ProductOpener/Ecoscore.pm
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ sub load_ecoscore_data_origins_of_ingredients_distances() {
# Score 0 for unknown origin
$ecoscore_data{origins}{"en:unknown"}{"transportation_score_" . $countries[$i]} = 0;
}
# Score 0 for unspecified request country (world)
$ecoscore_data{origins}{"en:unknown"}{"transportation_score_world"} = 0;
my @ecoscore_countries_sorted = sort keys %ecoscore_countries;

%ecoscore_countries_enabled = %ecoscore_countries;
Expand Down Expand Up @@ -257,6 +259,8 @@ sub load_ecoscore_data_origins_of_ingredients_distances() {
}
$ecoscore_data{origins}{$origin_id}{"transportation_score_" . $countries[$i]} = $value;
}
# Score 0 for unspecified request country (world)
$ecoscore_data{origins}{$origin_id}{"transportation_score_world"} = 0;

$log->debug("ecoscore origins CSV file - row",
{origin => $origin, origin_id => $origin_id, ecoscore_data => $ecoscore_data{origins}{$origin_id}})
Expand Down Expand Up @@ -1754,14 +1758,21 @@ The adjustment value and computations details are stored in the product referenc

=cut

sub localize_ecoscore ($cc, $product_ref) {
sub localize_ecoscore ($request_cc, $product_ref) {

# Localize the Eco-Score fields that depends on the country of the request

if (defined $product_ref->{ecoscore_data}) {

# Localize the final score

# If we have specific Eco-Score and origins of ingredients adjustment for the country, use it,
# otherwise use the world values
my $cc = $request_cc;
if (not defined $product_ref->{ecoscore_data}{"scores"}{$cc}) {
$cc = "world";
}

if (defined $product_ref->{ecoscore_data}{"scores"}{$cc}) {
$product_ref->{ecoscore_data}{"score"} = $product_ref->{ecoscore_data}{"scores"}{$cc};
$product_ref->{ecoscore_data}{"grade"} = $product_ref->{ecoscore_data}{"grades"}{$cc};
Expand All @@ -1770,7 +1781,6 @@ sub localize_ecoscore ($cc, $product_ref) {
$product_ref->{"ecoscore_grade"} = $product_ref->{ecoscore_data}{"grade"};
$product_ref->{"ecoscore_tags"} = [$product_ref->{ecoscore_grade}];
}

# Localize the origins of ingredients data

if (defined $product_ref->{ecoscore_data}{adjustments}{origins_of_ingredients}) {
Expand Down
3 changes: 3 additions & 0 deletions lib/ProductOpener/KnowledgePanels.pm
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,9 @@ sub create_ecoscore_panel ($product_ref, $target_lc, $target_cc, $options_ref, $
if ($score > 100) {
$score = 100;
}
if ($score < 0) {
$score = 0;
}

# We can reuse some strings from the Eco-Score attribute
my $title = sprintf(lang_in_other_lc($target_lc, "attribute_ecoscore_grade_title"), uc($grade)) . ' - '
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
[% IF sum_of_bonuses_and_maluses > 0 %]+[% END %][% sum_of_bonuses_and_maluses %]
[% END %]<br><br>
[% lang('ecoscore_final_score') %][% sep %]: [% panel.score %]/100
[% IF product.ecoscore_data.downgraded AND (panel.score == 79) %] ([% lang('ecoscore_downgraded_non_recyclable_and_non_biodegradable_materials') %])[% END %]
`
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
"epi_score" : "0",
"origin" : "en:unknown",
"percent" : 100,
"transportation_score" : null
"transportation_score" : 0
}
],
"epi_score" : 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
"epi_score" : "0",
"origin" : "en:unknown",
"percent" : 100,
"transportation_score" : null
"transportation_score" : 0
}
],
"epi_score" : 0,
Expand Down Expand Up @@ -1199,7 +1199,7 @@
{
"element_type" : "text",
"text_element" : {
"html" : "\n Life cycle analysis score: 70<br>\n Sum of bonuses and maluses:\n \n -23\n <br><br>\n Final score: 47/100\n \n ",
"html" : "\n Life cycle analysis score: 70<br>\n Sum of bonuses and maluses:\n \n -23\n <br><br>\n Final score: 47/100\n ",
"type" : "summary"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
"epi_score" : 0,
"origin" : "en:unknown",
"percent" : 100,
"transportation_score" : null
"transportation_score" : 0
}
],
"epi_score" : 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@
"epi_score" : "0",
"origin" : "en:unknown",
"percent" : 100,
"transportation_score" : null
"transportation_score" : 0
}
],
"epi_score" : 0,
Expand Down Expand Up @@ -1855,7 +1855,7 @@
{
"element_type" : "text",
"text_element" : {
"html" : "\n Life cycle analysis score: 70<br>\n Sum of bonuses and maluses:\n \n -23\n <br><br>\n Final score: 47/100\n \n ",
"html" : "\n Life cycle analysis score: 70<br>\n Sum of bonuses and maluses:\n \n -23\n <br><br>\n Final score: 47/100\n ",
"type" : "summary"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@
{
"element_type" : "text",
"text_element" : {
"html" : "\n Life cycle analysis score: 70<br>\n Sum of bonuses and maluses:\n \n -23\n <br><br>\n Final score: 47/100\n \n ",
"html" : "\n Life cycle analysis score: 70<br>\n Sum of bonuses and maluses:\n \n -23\n <br><br>\n Final score: 47/100\n ",
"type" : "summary"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@
{
"element_type" : "text",
"text_element" : {
"html" : "\n Life cycle analysis score: 70<br>\n Sum of bonuses and maluses:\n \n -23\n <br><br>\n Final score: 47/100\n \n ",
"html" : "\n Life cycle analysis score: 70<br>\n Sum of bonuses and maluses:\n \n -23\n <br><br>\n Final score: 47/100\n ",
"type" : "summary"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@
{
"element_type" : "text",
"text_element" : {
"html" : "\n Score d'analyse du cycle de vie : 70<br>\n Somme des bonus et malus :\n \n -23\n <br><br>\n Score final : 47/100\n \n ",
"html" : "\n Score d'analyse du cycle de vie : 70<br>\n Somme des bonus et malus :\n \n -23\n <br><br>\n Score final : 47/100\n ",
"type" : "summary"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@
{
"element_type" : "text",
"text_element" : {
"html" : "\n Life cycle analysis score: 70<br>\n Sum of bonuses and maluses:\n \n -23\n <br><br>\n Final score: 47/100\n \n ",
"html" : "\n Life cycle analysis score: 70<br>\n Sum of bonuses and maluses:\n \n -23\n <br><br>\n Final score: 47/100\n ",
"type" : "summary"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
"epi_score" : "0",
"origin" : "en:unknown",
"percent" : 100,
"transportation_score" : null
"transportation_score" : 0
}
],
"epi_score" : 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
"epi_score" : "0",
"origin" : "en:unknown",
"percent" : 100,
"transportation_score" : null
"transportation_score" : 0
}
],
"epi_score" : 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
"epi_score" : "0",
"origin" : "en:unknown",
"percent" : 100,
"transportation_score" : null
"transportation_score" : 0
}
],
"epi_score" : 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
"epi_score" : 0,
"origin" : "en:unknown",
"percent" : 100,
"transportation_score" : null
"transportation_score" : 0
}
],
"epi_score" : 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
"epi_score" : "0",
"origin" : "en:unknown",
"percent" : 100,
"transportation_score" : null
"transportation_score" : 0
}
],
"epi_score" : 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
"epi_score" : "0",
"origin" : "en:unknown",
"percent" : 100,
"transportation_score" : null
"transportation_score" : 0
}
],
"epi_score" : 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
"epi_score" : 0,
"origin" : "en:unknown",
"percent" : 100,
"transportation_score" : null
"transportation_score" : 0
}
],
"epi_score" : 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
"epi_score" : "0",
"origin" : "en:unknown",
"percent" : 100,
"transportation_score" : null
"transportation_score" : 0
}
],
"epi_score" : 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
"epi_score" : 0,
"origin" : "en:unknown",
"percent" : 100,
"transportation_score" : null
"transportation_score" : 0
}
],
"epi_score" : 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
"epi_score" : 0,
"origin" : "en:unknown",
"percent" : 100,
"transportation_score" : null
"transportation_score" : 0
}
],
"epi_score" : 0,
Expand Down Expand Up @@ -1193,7 +1193,7 @@
{
"element_type" : "text",
"text_element" : {
"html" : "\n Life cycle analysis score: 70<br>\n Sum of bonuses and maluses:\n \n -23\n <br><br>\n Final score: 47/100\n \n ",
"html" : "\n Life cycle analysis score: 70<br>\n Sum of bonuses and maluses:\n \n -23\n <br><br>\n Final score: 47/100\n ",
"type" : "summary"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
"epi_score" : "0",
"origin" : "en:unknown",
"percent" : 100,
"transportation_score" : null
"transportation_score" : 0
}
],
"epi_score" : 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@
"epi_score" : "0",
"origin" : "en:unknown",
"percent" : 100,
"transportation_score" : null
"transportation_score" : 0
}
],
"epi_score" : 0,
Expand Down Expand Up @@ -1841,7 +1841,7 @@
{
"element_type" : "text",
"text_element" : {
"html" : "\n Life cycle analysis score: 70<br>\n Sum of bonuses and maluses:\n \n -23\n <br><br>\n Final score: 47/100\n \n ",
"html" : "\n Life cycle analysis score: 70<br>\n Sum of bonuses and maluses:\n \n -23\n <br><br>\n Final score: 47/100\n ",
"type" : "summary"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@
{
"element_type" : "text",
"text_element" : {
"html" : "\n Life cycle analysis score: 70<br>\n Sum of bonuses and maluses:\n \n -23\n <br><br>\n Final score: 47/100\n \n ",
"html" : "\n Life cycle analysis score: 70<br>\n Sum of bonuses and maluses:\n \n -23\n <br><br>\n Final score: 47/100\n ",
"type" : "summary"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@
{
"element_type" : "text",
"text_element" : {
"html" : "\n Life cycle analysis score: 70<br>\n Sum of bonuses and maluses:\n \n -23\n <br><br>\n Final score: 47/100\n \n ",
"html" : "\n Life cycle analysis score: 70<br>\n Sum of bonuses and maluses:\n \n -23\n <br><br>\n Final score: 47/100\n ",
"type" : "summary"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@
{
"element_type" : "text",
"text_element" : {
"html" : "\n Score d'analyse du cycle de vie : 70<br>\n Somme des bonus et malus :\n \n -23\n <br><br>\n Score final : 47/100\n \n ",
"html" : "\n Score d'analyse du cycle de vie : 70<br>\n Somme des bonus et malus :\n \n -23\n <br><br>\n Score final : 47/100\n ",
"type" : "summary"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@
{
"element_type" : "text",
"text_element" : {
"html" : "\n Life cycle analysis score: 70<br>\n Sum of bonuses and maluses:\n \n -23\n <br><br>\n Final score: 47/100\n \n ",
"html" : "\n Life cycle analysis score: 70<br>\n Sum of bonuses and maluses:\n \n -23\n <br><br>\n Final score: 47/100\n ",
"type" : "summary"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"epi_score" : 0,
"origin" : "en:unknown",
"percent" : 100,
"transportation_score" : null
"transportation_score" : 0
}
],
"epi_score" : 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"epi_score" : 0,
"origin" : "en:unknown",
"percent" : 100,
"transportation_score" : null
"transportation_score" : 0
}
],
"epi_score" : 0,
Expand Down
Loading
Loading