Skip to content

Commit

Permalink
apply suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
benbenben2 committed May 26, 2024
1 parent 952ec15 commit 5069573
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 42 deletions.
4 changes: 2 additions & 2 deletions lib/ProductOpener/Display.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9043,8 +9043,8 @@ sub data_to_display_nutrient_levels ($product_ref) {
if ((defined $product_ref->{nutrient_levels}) and (defined $product_ref->{nutrient_levels}{$nid})) {

my $nutriment_value = $product_ref->{nutriments}{$nid . $prepared . "_100g"};
my $formatted_value = defined $nutriment_value
&& $nutriment_value =~ /^-?\d+(\.\d+)?$/ ? sprintf("%.2e", $nutriment_value + 0.0) : '';
my $formatted_value = $nutriment_value
// '' =~ /^-?\d+(\.\d+)?$/ ? sprintf("%.2e", $nutriment_value + 0.0) : '';

push @{$result_data_ref->{nutrient_levels}}, {
nid => $nid,
Expand Down
8 changes: 3 additions & 5 deletions lib/ProductOpener/Products.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2340,14 +2340,12 @@ sub compute_product_history_and_completeness ($product_data_root, $current_produ
my $number_of_units = $packagings_ref->{number_of_units};
my $weight_measured = $packagings_ref->{weight_measured};

$packagings_data_signature
.= "number_of_units:" . ($number_of_units // '') . ',';
$packagings_data_signature .= "number_of_units:" . ($number_of_units // '') . ',';
foreach my $property (qw(shape material recycling quantity_per_unit)) {
$packagings_data_signature .= $property . ":"
. (defined $packagings_ref->{$property} ? $packagings_ref->{$property} : '') . ',';
$packagings_data_signature .= $property . ":" . ($packagings_ref->{$property} // '') . ',';
}
$packagings_data_signature .= "\n";
$packagings_weights_signature .= (defined $weight_measured ? $weight_measured : '') . "\n";
$packagings_weights_signature .= ($weight_measured // '') . "\n";
}
# If the signature is empty or contains only line feeds, we don't have data
if ($packagings_data_signature !~ /^\s*$/) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
}
},
[% ELSE %]
[% IF defined product.ecoscore_data.adjustments.origins_of_ingredients.value && product.ecoscore_data.adjustments.origins_of_ingredients.value <= 0 %]
[% IF product.ecoscore_data.adjustments.origins_of_ingredients.value.defined && product.ecoscore_data.adjustments.origins_of_ingredients.value <= 0 %]
"evaluation": "bad",
"title_element": {
"title": "[% edq(lang('ecoscore_origins_of_ingredients_impact_high')) %]",
[% ELSIF defined product.ecoscore_data.adjustments.origins_of_ingredients.value && product.ecoscore_data.adjustments.origins_of_ingredients.value <= 15 %]
[% ELSIF product.ecoscore_data.adjustments.origins_of_ingredients.value.defined && product.ecoscore_data.adjustments.origins_of_ingredients.value <= 15 %]
"evaluation": "average",
"title_element": {
"title": "[% edq(lang('ecoscore_origins_of_ingredients_impact_medium')) %]",
Expand All @@ -38,7 +38,7 @@
"title_element": {
"title": "[% edq(lang('ecoscore_origins_of_ingredients_impact_low')) %]",
[% END %]
[% IF defined product.ecoscore_data.adjustments.origins_of_ingredients.value && product.ecoscore_data.adjustments.origins_of_ingredients.value > 0 %]
[% IF product.ecoscore_data.adjustments.origins_of_ingredients.value.defined && product.ecoscore_data.adjustments.origins_of_ingredients.value > 0 %]
"subtitle": "[% edq(lang('bonus')) %][% sep %]: +[% product.ecoscore_data.adjustments.origins_of_ingredients.value %]",
[% ELSE %]
"subtitle": "[% edq(lang('malus')) %][% sep %]: [% product.ecoscore_data.adjustments.origins_of_ingredients.value %]",
Expand All @@ -53,8 +53,8 @@
"text_element": {
"type": "default",
"html": `
<strong>[% lang('ecoscore_environmental_policy') %][% sep %]: [% IF defined product.ecoscore_data.adjustments.origins_of_ingredients.epi_value && product.ecoscore_data.adjustments.origins_of_ingredients.epi_value > 0 %]+[% END %][% round(product.ecoscore_data.adjustments.origins_of_ingredients.epi_value) %]</strong><br>
<strong>[% lang('ecoscore_transportation') %][% sep %]: [% IF defined product.ecoscore_data.adjustments.origins_of_ingredients.transportation_value && product.ecoscore_data.adjustments.origins_of_ingredients.transportation_value > 0 %]+[% END %][% round(product.ecoscore_data.adjustments.origins_of_ingredients.transportation_value) %]</strong><br>
<strong>[% lang('ecoscore_environmental_policy') %][% sep %]: [% IF product.ecoscore_data.adjustments.origins_of_ingredients.epi_value.defined && product.ecoscore_data.adjustments.origins_of_ingredients.epi_value > 0 %]+[% END %][% round(product.ecoscore_data.adjustments.origins_of_ingredients.epi_value) %]</strong><br>
<strong>[% lang('ecoscore_transportation') %][% sep %]: [% IF product.ecoscore_data.adjustments.origins_of_ingredients.transportation_value.defined && product.ecoscore_data.adjustments.origins_of_ingredients.transportation_value > 0 %]+[% END %][% round(product.ecoscore_data.adjustments.origins_of_ingredients.transportation_value) %]</strong><br>
`
}
},
Expand Down Expand Up @@ -89,8 +89,8 @@
"percent": [% round(origin.percent) %],
// EPI bonus goes from -5 to 5 with the formula bonus = epi_score / 10 - 5
// Transportation bonus goes from 0 to 15 with the formula bonus = transportation_score * 0.15
[% SET epi_score = defined origin.epi_score ? origin.epi_score : 0 %]
[% SET transportation_score = defined origin.transportation_score ? origin.transportation_score : 0 %]
[% SET epi_score = origin.epi_score.defined ? origin.epi_score : 0 %]
[% SET transportation_score = origin.transportation_score.defined ? origin.transportation_score : 0 %]
[% SET score = epi_score / 10 - 5 + transportation_score * 0.15 %]
[% IF score >= 15 %]
"evaluation": "good",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
}
},
]
[% ELSIF defined product.ecoscore_data.adjustments.threatened_species.value && product.ecoscore_data.adjustments.threatened_species.value < 0 %]
[% ELSIF product.ecoscore_data.adjustments.threatened_species.value.defined && product.ecoscore_data.adjustments.threatened_species.value < 0 %]
"evaluation": "bad",
"title_element": {
"title": "[% edq(lang('ecoscore_ingredients_whose_cultivation_threatens_species')) %]",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,4 @@
[% USE sum_of_bonuses_and_maluses = 0;
USE value;
IF (defined product.ecoscore_data.adjustments.production_system.value && product.ecoscore_data.adjustments.production_system.value =~ /^-?\d+(\.\d+)?$/) {
value = product.ecoscore_data.adjustments.production_system.value;
}
sum_of_bonuses_and_maluses += value;

IF (defined product.ecoscore_data.adjustments.packaging.value && product.ecoscore_data.adjustments.packaging.value =~ /^-?\d+(\.\d+)?$/) {
value = product.ecoscore_data.adjustments.packaging.value;
}
sum_of_bonuses_and_maluses += value;

IF (defined product.ecoscore_data.adjustments.threatened_species.value && product.ecoscore_data.adjustments.threatened_species.value =~ /^-?\d+(\.\d+)?$/) {
value = product.ecoscore_data.adjustments.threatened_species.value;
}
sum_of_bonuses_and_maluses += value;

IF (defined product.ecoscore_data.adjustments.origins_of_ingredients.value && product.ecoscore_data.adjustments.origins_of_ingredients.value =~ /^-?\d+(\.\d+)?$/) {
value = product.ecoscore_data.adjustments.origins_of_ingredients.value;
}
sum_of_bonuses_and_maluses += value;
%]

[% SET sum_of_bonuses_and_maluses = (product.ecoscore_data.adjustments.production_system.value || 0) + (product.ecoscore_data.adjustments.packaging.value || 0) + (product.ecoscore_data.adjustments.threatened_species.value || 0) + (product.ecoscore_data.adjustments.origins_of_ingredients.value || 0) %]

{
"level": "info",
Expand Down
8 changes: 4 additions & 4 deletions templates/web/pages/product/includes/ecoscore_details.tt.html
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ <h3>[% lang('ecoscore_additional_bonuses_and_maluses') %]</h3>
<div class="panel ecoscore_panel" id="ecoscore_panel_production_system" data-equalizer-watch="ecoscore1">
<h4>[% display_icon('agriculture') %] [% lang('ecoscore_production_system') %]</h4>

[% IF defined adjustments.production_system.value && adjustments.production_system.value > 0 %]
[% IF adjustments.production_system.value.defined && adjustments.production_system.value > 0 %]

<ul>
[% FOREACH label IN adjustments.production_system.labels %]
Expand Down Expand Up @@ -164,8 +164,8 @@ <h4>[% display_icon('public') %] [% lang('ecoscore_origins_of_ingredients') %]</
[% END %]

<p>
<strong>[% lang('ecoscore_environmental_policy') %][% sep %]: [% IF defined adjustments.origins_of_ingredients.epi_value && adjustments.origins_of_ingredients.epi_value > 0 %]+[% END %][% round(adjustments.origins_of_ingredients.epi_value) %]</strong><br>
<strong>[% lang('ecoscore_transportation') %][% sep %]: [% IF defined adjustments.origins_of_ingredients.epi_value && adjustments.origins_of_ingredients.transportation_value > 0 %]+[% END %][% round(adjustments.origins_of_ingredients.transportation_value) %]</strong><br>
<strong>[% lang('ecoscore_environmental_policy') %][% sep %]: [% IF adjustments.origins_of_ingredients.epi_value.defined && adjustments.origins_of_ingredients.epi_value > 0 %]+[% END %][% round(adjustments.origins_of_ingredients.epi_value) %]</strong><br>
<strong>[% lang('ecoscore_transportation') %][% sep %]: [% IF adjustments.origins_of_ingredients.epi_value.defined && adjustments.origins_of_ingredients.transportation_value > 0 %]+[% END %][% round(adjustments.origins_of_ingredients.transportation_value) %]</strong><br>
</p>
</div>
</div>
Expand Down Expand Up @@ -233,7 +233,7 @@ <h4>[% display_icon('packaging') %] [% lang('ecoscore_packaging') %]</h4>
<p>[% lang('ecoscore_score_of_all_components') %][% sep %]: [% adjustments.packaging.score %]</p>
[% END %]

<p><strong>[% lang('ecoscore_packaging') %][% sep %]: [% IF defined adjustments.packaging.value && adjustments.packaging.value > 0 %]+[% END %][% adjustments.packaging.value %]</strong></p>
<p><strong>[% lang('ecoscore_packaging') %][% sep %]: [% IF adjustments.packaging.value.defined && adjustments.packaging.value > 0 %]+[% END %][% adjustments.packaging.value %]</strong></p>

</div>
</div>
Expand Down

0 comments on commit 5069573

Please sign in to comment.