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

feat: Finalize Eco-Score knowledge panels #6017

Merged
merged 9 commits into from
Oct 26, 2021
Merged
Show file tree
Hide file tree
Changes from 7 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
8 changes: 4 additions & 4 deletions html/js/product-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,16 +264,16 @@ function display_product_summary(target, product) {
var color = "#eee";

if (attribute.status == "known") {
if (attribute.match <= 20) {
if (attribute.grade == "e") {
color = "hsl(0, 100%, 90%)";
}
else if (attribute.match <= 40) {
else if (attribute.grade == "d") {
color = "hsl(30, 100%, 90%)";
}
else if (attribute.match <= 60) {
else if (attribute.grade == "c") {
color = "hsl(60, 100%, 90%)";
}
else if (attribute.match <= 80) {
else if (attribute.grade == "b") {
color = "hsl(90, 100%, 90%)";
}
else {
Expand Down
36 changes: 31 additions & 5 deletions lib/ProductOpener/Attributes.pm
Original file line number Diff line number Diff line change
Expand Up @@ -615,16 +615,16 @@ sub compute_attribute_ecoscore($$$) {
my $match = 0;

# Score ranges from 0 to 100 with some maluses and bonuses that can be added

# Warning: a score of 20 means D grade for the Eco-Score, but a match of 20 is E grade for the attributes
# So we substract 1 to the Eco-Score score to compute the match.
$match = $score - 1;

if ($score < 0) {
$match = 0;
}
elsif ($score > 100) {
$match = 100;
}
else {
$match = $score;
}

$attribute_ref->{match} = $match;

Expand Down Expand Up @@ -1375,10 +1375,11 @@ sub compute_attribute_ingredients_analysis($$$) {
$analysis_tag = "$analysis-status-unknown";
}
}

if (defined $match) {
$attribute_ref->{match} = $match;
}

$attribute_ref->{status} = $status;
$attribute_ref->{icon_url} = "$static_subdomain/images/attributes/$analysis_tag.svg";
# the ingredients_analysis taxonomy contains en:palm-oil and not en:contains-palm-oil
Expand Down Expand Up @@ -1429,6 +1430,31 @@ sub add_attribute_to_group($$$$) {
# Delete fields that are returned only by /api/v2/attribute_groups to list all the available attributes
delete $attribute_ref->{setting_name};
delete $attribute_ref->{setting_note};

# Compute a 5 level grade from the match score
# We do it server side to be sure that clients do it the same way
# and that a Nutri-Score E match of 20 has a grade "e".
if ($attribute_ref->{status} eq "known") {

if ($attribute_ref->{match} <= 20) {
$attribute_ref->{grade} = 'e';
}
elsif ($attribute_ref->{match} <= 40) {
$attribute_ref->{grade} = 'd';
}
elsif ($attribute_ref->{match} <= 60) {
$attribute_ref->{grade} = 'c';
}
elsif ($attribute_ref->{match} <= 80) {
$attribute_ref->{grade} = 'b';
}
else {
$attribute_ref->{grade} = 'a';
}
}
else {
$attribute_ref->{grade} = 'unknown';
}

my $group_ref;
# Select the requested group
Expand Down
4 changes: 4 additions & 0 deletions lib/ProductOpener/KnowledgePanels.pm
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,10 @@ sub create_ecoscore_panel($$$) {
$label_panel_data_ref, $product_ref, $target_lc, $target_cc);
}
}

# Add panel for the final Eco-Score of the product
create_panel_from_json_template("ecoscore_total", "api/knowledge-panels/environment/ecoscore/total.tt.json",
$panel_data_ref, $product_ref, $target_lc, $target_cc);
}
else {
my $panel_data_ref = {};
Expand Down
60 changes: 42 additions & 18 deletions po/common/common.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5584,8 +5584,8 @@ msgid "Ingredients whose cultivation threatens species"
msgstr "Ingredients whose cultivation threatens species"

msgctxt "ecoscore_no_species_threatening_ingredients"
msgid "No ingredient which cultivation threatens species has been detected."
msgstr "No ingredient which cultivation threatens species has been detected."
msgid "No ingredient threatening species"
msgstr "No ingredient threatening species"

msgctxt "ecoscore_ingredients_unknown"
msgid "The information on the ingredients of this product has not been given."
Expand Down Expand Up @@ -5689,36 +5689,36 @@ msgid "Removing or changing the provided data will be possible only by experimen
msgstr "Removing or changing the provided data will be possible only by experimented contributors on the web site."

msgctxt "ecoscore_packaging_impact_high"
msgid "This product's packaging has an high impact on the environment."
msgstr "This product's packaging has an high impact on the environment."
msgid "Packaging with a high impact"
msgstr "Packaging with a high impact"

msgctxt "ecoscore_packaging_impact_medium"
msgid "This product's packaging has an average impact on the environment."
msgstr "This product's packaging has an average impact on the environment."
msgid "Packaging with a medium impact"
msgstr "Packaging with a medium impact"

msgctxt "ecoscore_packaging_impact_low"
msgid "This product's packaging has a low impact on the environment."
msgstr "This product's packaging has a low impact on the environment."
msgid "Packaging with a low impact"
msgstr "Packaging with a low impact"

msgctxt "ecoscore_packaging_missing_information"
msgid "The information about this product's packaging is missing."
msgstr "The information about this product's packaging is missing."
msgid "Missing packaging information for this product"
msgstr "Missing packaging information for this product"

msgctxt "ecoscore_origins_of_ingredients_impact_high"
msgid "Transportation and origins of ingredients have a high impact."
msgstr "Transportation and origins of ingredients have a high impact."
msgid "Origins of ingredients with a high impact"
msgstr "Origins of ingredients with a high impact"

msgctxt "ecoscore_origins_of_ingredients_impact_medium"
msgid "Transportation and origins of ingredients have a medium impact."
msgstr "Transportation and origins of ingredients have a medium impact."
msgid "Origins of ingredients with a medium impact"
msgstr "Origins of ingredients with a medium impact"

msgctxt "ecoscore_origins_of_ingredients_impact_low"
msgid "Transportation and origins of ingredients have a low impact."
msgstr "Transportation and origins of ingredients have a low impact."
msgid "Origins of ingredients with a low impact"
msgstr "Origins of ingredients with a low impact"

msgctxt "ecoscore_origins_of_ingredients_missing_information"
msgid "Missing information about the origins of ingredients"
msgstr "Missing information about the origins of ingredients"
msgid "Missing origins of ingredients information"
msgstr "Missing origins of ingredients information"

msgctxt "percent_of_ingredients"
msgid "% of ingredients"
Expand Down Expand Up @@ -5827,3 +5827,27 @@ msgstr "Drives deforestation and threatens species such as the orangutan"
msgctxt "contains_palm_oil_description"
msgid "Tropical forests in Asia, Africa and Latin America are destroyed to create and expand oil palm tree plantations. The deforestation contributes to climate change, and it endangers species such as the orangutan, the pigmy elephant and the Sumatran rhino."
msgstr "Tropical forests in Asia, Africa and Latin America are destroyed to create and expand oil palm tree plantations. The deforestation contributes to climate change, and it endangers species such as the orangutan, the pigmy elephant and the Sumatran rhino."

msgctxt "bonus"
msgid "Bonus"
msgstr "Bonus"

msgctxt "malus"
msgid "Malus"
msgstr "Malus"

msgctxt "life_cycle_analysis"
msgid "Life cycle analysis"
msgstr "Life cycle analysis"

msgctxt "ecoscore_bonuses_and_maluses"
msgid "Bonuses and maluses"
msgstr "Bonuses and maluses"

msgctxt "ecoscore_for_this_product"
msgid "Eco-Score for this product"
msgstr "Eco-Score for this product"

msgctxt "average_impact_of_the_category"
msgid "Average impact of products of the same category"
msgstr "Average impact of products of the same category"
60 changes: 42 additions & 18 deletions po/common/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -5601,8 +5601,8 @@ msgid "Ingredients whose cultivation threatens species"
msgstr "Ingredients whose cultivation threatens species"

msgctxt "ecoscore_no_species_threatening_ingredients"
msgid "No ingredient which cultivation threatens species has been detected."
msgstr "No ingredient which cultivation threatens species has been detected."
msgid "No ingredient threatening species"
msgstr "No ingredient threatening species"

msgctxt "ecoscore_ingredients_unknown"
msgid "The information on the ingredients of this product has not been given."
Expand Down Expand Up @@ -5706,36 +5706,36 @@ msgid "Removing or changing the provided data will be possible only by experimen
msgstr "Removing or changing the provided data will be possible only by experimented contributors on the web site."

msgctxt "ecoscore_packaging_impact_high"
msgid "This product's packaging has an high impact on the environment."
msgstr "This product's packaging has an high impact on the environment."
msgid "Packaging with a high impact"
msgstr "Packaging with a high impact"

msgctxt "ecoscore_packaging_impact_medium"
msgid "This product's packaging has an average impact on the environment."
msgstr "This product's packaging has an average impact on the environment."
msgid "Packaging with a medium impact"
msgstr "Packaging with a medium impact"

msgctxt "ecoscore_packaging_impact_low"
msgid "This product's packaging has a low impact on the environment."
msgstr "This product's packaging has a low impact on the environment."
msgid "Packaging with a low impact"
msgstr "Packaging with a low impact"

msgctxt "ecoscore_packaging_missing_information"
msgid "The information about this product's packaging is missing."
msgstr "The information about this product's packaging is missing."
msgid "Missing packaging information for this product"
msgstr "Missing packaging information for this product"

msgctxt "ecoscore_origins_of_ingredients_impact_high"
msgid "Transportation and origins of ingredients have a high impact."
msgstr "Transportation and origins of ingredients have a high impact."
msgid "Origins of ingredients with a high impact"
msgstr "Origins of ingredients with a high impact"

msgctxt "ecoscore_origins_of_ingredients_impact_medium"
msgid "Transportation and origins of ingredients have a medium impact."
msgstr "Transportation and origins of ingredients have a medium impact."
msgid "Origins of ingredients with a medium impact"
msgstr "Origins of ingredients with a medium impact"

msgctxt "ecoscore_origins_of_ingredients_impact_low"
msgid "Transportation and origins of ingredients have a low impact."
msgstr "Transportation and origins of ingredients have a low impact."
msgid "Origins of ingredients with a low impact"
msgstr "Origins of ingredients with a low impact"

msgctxt "ecoscore_origins_of_ingredients_missing_information"
msgid "Missing information about the origins of ingredients"
msgstr "Missing information about the origins of ingredients"
msgid "Missing origins of ingredients information"
msgstr "Missing origins of ingredients information"

msgctxt "percent_of_ingredients"
msgid "% of ingredients"
Expand Down Expand Up @@ -5844,3 +5844,27 @@ msgstr "Drives deforestation and threatens species such as the orangutan"
msgctxt "contains_palm_oil_description"
msgid "Tropical forests in Asia, Africa and Latin America are destroyed to create and expand oil palm tree plantations. The deforestation contributes to climate change, and it endangers species such as the orangutan, the pigmy elephant and the Sumatran rhino."
msgstr "Tropical forests in Asia, Africa and Latin America are destroyed to create and expand oil palm tree plantations. The deforestation contributes to climate change, and it endangers species such as the orangutan, the pigmy elephant and the Sumatran rhino."

msgctxt "bonus"
msgid "Bonus"
msgstr "Bonus"

msgctxt "malus"
msgid "Malus"
msgstr "Malus"

msgctxt "life_cycle_analysis"
msgid "Life cycle analysis"
msgstr "Life cycle analysis"

msgctxt "ecoscore_bonuses_and_maluses"
msgid "Bonuses and maluses"
msgstr "Bonuses and maluses"

msgctxt "ecoscore_for_this_product"
msgid "Eco-Score for this product"
msgstr "Eco-Score for this product"

msgctxt "average_impact_of_the_category"
msgid "Average impact of products of the same category"
msgstr "Average impact of products of the same category"
67 changes: 67 additions & 0 deletions scss/_off.scss
Original file line number Diff line number Diff line change
Expand Up @@ -699,3 +699,70 @@ html[dir="rtl"] {
.switch input[type="checkbox"]:focus + label::after {
outline: rgb(59, 153, 252) auto 5px;
}

// We need a large padding inside panel content so that we can see
// the hierarchy of panels that contain other panels
.panel_content {
clear:left;
margin-top:1rem;
padding-left:2rem !important;
padding-right:2rem !important;
}

.panel_content_card {
margin-top:1rem;
}

// Make active (opened) accordion look like inactive accordion
// as we use them only for knowledge panel, with only 1 openable element
// per accordion
.accordion .accordion-navigation>a, .accordion dd>a {
background:#fafafa;
}
.accordion .accordion-navigation.active>a, .accordion dd.active>a {
background:#fafafa;
}
.accordion .accordion-navigation>a:hover, .accordion dd>a:hover {
background:#f0f0f0;
}

// background colors for attributes and panels
.grade_unknown {
background-color:#efefef !important;
}
.grade_a {
background-color:hsl(120, 100%, 90%) !important;
}
a.grade_a:hover {
background-color:hsl(120, 100%, 80%) !important;
}

.grade_b {
background-color:hsl(90, 100%, 90%) !important;
}
a.grade_b:hover {
background-color:hsl(90, 100%, 80%) !important;
}

.grade_c {
background-color:hsl(60, 100%, 90%) !important;
}
a.grade_c:hover {
background-color:hsl(60, 100%, 80%) !important;
}

.grade_d {
background-color:hsl(30, 100%, 90%) !important;
}
a.grade_d:hover {
background-color:hsl(30, 100%, 80%) !important;
}

.grade_e {
background-color:hsl(0, 100%, 90%) !important;
}
a.grade_e:hover {
background-color:hsl(0, 100%, 80%) !important;
}


Loading