Skip to content

Commit

Permalink
Merge branch 'main' into aleene-25-1
Browse files Browse the repository at this point in the history
  • Loading branch information
aleene committed Jan 7, 2025
2 parents 95e0f35 + 176fe9e commit 7f4945f
Show file tree
Hide file tree
Showing 48 changed files with 71 additions and 54 deletions.
31 changes: 24 additions & 7 deletions lib/ProductOpener/Display.pm
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,15 @@ sub process_template ($template_filename, $template_data_ref, $result_content_re
};

$template_data_ref->{round} = sub ($var) {
return sprintf("%.0f", $var);
# Check if $var is defined and is numeric
if (defined $var && $var =~ /^-?\d+(\.\d+)?$/) {
return sprintf("%.0f", $var);
}
else {
return;
}
};

$template_data_ref->{sprintf} = sub ($var1, $var2) {
return sprintf($var1, $var2);
};
Expand Down Expand Up @@ -5455,7 +5462,11 @@ sub search_and_display_products ($request_ref, $query_ref, $sort_by, $limit, $pa
$cursor = execute_query(
sub {
return get_products_collection(get_products_collection_request_parameters($request_ref))
->query($query_ref)->fields($fields_ref)->sort($sort_ref)->limit($limit)->skip($skip);
->query($query_ref)
->fields($fields_ref)
->sort($sort_ref)
->limit($limit)
->skip($skip);
}
);
$log->debug("MongoDB query ok", {error => $@}) if $log->is_debug();
Expand Down Expand Up @@ -6920,7 +6931,8 @@ sub search_and_graph_products ($request_ref, $query_ref, $graph_ref) {
$cursor = execute_query(
sub {
return get_products_collection(get_products_collection_request_parameters($request_ref))
->query($query_ref)->fields($fields_ref);
->query($query_ref)
->fields($fields_ref);
}
);
};
Expand Down Expand Up @@ -7230,7 +7242,8 @@ sub search_products_for_map ($request_ref, $query_ref) {
$cursor = execute_query(
sub {
return get_products_collection(get_products_collection_request_parameters($request_ref))
->query($query_ref)->fields(
->query($query_ref)
->fields(
{
code => 1,
lc => 1,
Expand Down Expand Up @@ -7953,8 +7966,11 @@ JS

localize_environmental_score($request_ref->{cc}, $product_ref);

$template_data_ref->{environmental_score_grade} = uc($product_ref->{environmental_score_data}{"grade"});
$template_data_ref->{environmental_score_grade_lc} = $product_ref->{environmental_score_data}{"grade"};
if (defined $product_ref->{environmental_score_data}{"grade"}) {
$template_data_ref->{environmental_score_grade} = uc($product_ref->{environmental_score_data}{"grade"});
$template_data_ref->{environmental_score_lc} = $product_ref->{environmental_score_data}{"grade"};
}

$template_data_ref->{environmental_score_score} = $product_ref->{environmental_score_data}{"score"};
$template_data_ref->{environmental_score_data} = $product_ref->{environmental_score_data};
$template_data_ref->{environmental_score_calculation_details}
Expand Down Expand Up @@ -11586,7 +11602,8 @@ sub search_and_analyze_recipes ($request_ref, $query_ref) {
$cursor = execute_query(
sub {
return get_products_collection(get_products_collection_request_parameters($request_ref))
->query($query_ref)->fields($fields_ref);
->query($query_ref)
->fields($fields_ref);
}
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
"salt" : 0,
"salt_100g" : "0",
"salt_unit" : "g",
"salt_value" : 0,
"salt_value" : "0",
"saturated-fat_100g" : "5",
"sodium_100g" : 0,
"sodium_value" : "0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"salt" : 0.5525,
"salt_100g" : 0.5525,
"salt_unit" : "g",
"salt_value" : 0.5525,
"salt_value" : "0.5525",
"saturated-fat_100g" : 1.03,
"sodium_100g" : 0.221,
"sodium_value" : 0.221,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"salt_prepared" : 0.1125,
"salt_prepared_100g" : 0.1125,
"salt_prepared_unit" : "g",
"salt_prepared_value" : 0.1125,
"salt_prepared_value" : "0.1125",
"saturated-fat_prepared_100g" : 1.1,
"sodium_prepared_100g" : 0.045,
"sodium_prepared_value" : 0.045,
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/expected_test_results/nutriscore/colza-oil.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"salt" : 0,
"salt_100g" : "0",
"salt_unit" : "g",
"salt_value" : 0,
"salt_value" : "0",
"saturated-fat_100g" : "7",
"sodium_100g" : 0,
"sodium_value" : "0",
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/expected_test_results/nutriscore/cookies.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"salt" : 0,
"salt_100g" : "0",
"salt_unit" : "g",
"salt_value" : 0,
"salt_value" : "0",
"saturated-fat_100g" : "15",
"sodium_100g" : 0,
"sodium_value" : "0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
"salt" : 0,
"salt_100g" : "0",
"salt_unit" : "g",
"salt_value" : 0,
"salt_value" : "0",
"saturated-fat_100g" : "5",
"sodium_100g" : 0,
"sodium_value" : "0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
"salt" : 0,
"salt_100g" : "0",
"salt_unit" : "g",
"salt_value" : 0,
"salt_value" : "0",
"saturated-fat_100g" : "5",
"sodium_100g" : 0,
"sodium_value" : "0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
"salt" : 0,
"salt_100g" : "0",
"salt_unit" : "g",
"salt_value" : 0,
"salt_value" : "0",
"saturated-fat_100g" : "5",
"sodium_100g" : 0,
"sodium_value" : "0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
"sodium" : 0,
"sodium_100g" : 0,
"sodium_unit" : "g",
"sodium_value" : 0,
"sodium_value" : "0",
"sugars_100g" : "0"
},
"nutriments_estimated" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"salt" : 0.5,
"salt_100g" : 0.5,
"salt_unit" : "g",
"salt_value" : 0.5,
"salt_value" : "0.5",
"saturated-fat_100g" : 0,
"sodium_100g" : 0.2,
"sodium_value" : 0.2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@
"salt_prepared" : 0.025,
"salt_prepared_100g" : 0.025,
"salt_prepared_unit" : "g",
"salt_prepared_value" : 0.025,
"salt_prepared_value" : "0.025",
"saturated-fat_prepared_100g" : 0,
"sodium_prepared_100g" : 0.01,
"sodium_prepared_value" : 0.01,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
"sodium" : 0,
"sodium_100g" : 0,
"sodium_unit" : "g",
"sodium_value" : 0,
"sodium_value" : "0",
"sugars_100g" : 2.48
},
"nutriments_estimated" : {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/expected_test_results/nutriscore/en-milk.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"sodium" : 0.04,
"sodium_100g" : 0.04,
"sodium_unit" : "g",
"sodium_value" : 0.04,
"sodium_value" : "0.04",
"sugars_100g" : 4.8
},
"nutriscore" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"sodium" : 0,
"sodium_100g" : 0,
"sodium_unit" : "g",
"sodium_value" : 0,
"sodium_value" : "0",
"sugars_100g" : "0"
},
"nutriscore" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
"sodium" : 0,
"sodium_100g" : 0,
"sodium_unit" : "g",
"sodium_value" : 0,
"sodium_value" : "0",
"sugars_100g" : "0"
},
"nutriscore" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
"sodium" : 0,
"sodium_100g" : 0,
"sodium_unit" : "g",
"sodium_value" : 0,
"sodium_value" : "0",
"sugars_100g" : "0"
},
"nutriments_estimated" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
"salt" : 0.5,
"salt_100g" : 0.5,
"salt_unit" : "g",
"salt_value" : 0.5,
"salt_value" : "0.5",
"saturated-fat_100g" : "0",
"sodium_100g" : 0.2,
"sodium_value" : 0.2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"salt" : 0.5,
"salt_100g" : 0.5,
"salt_unit" : "g",
"salt_value" : 0.5,
"salt_value" : "0.5",
"saturated-fat_100g" : "0",
"sodium_100g" : 0.2,
"sodium_value" : 0.2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"salt" : 0.5,
"salt_100g" : 0.5,
"salt_unit" : "g",
"salt_value" : 0.5,
"salt_value" : "0.5",
"saturated-fat_100g" : "0",
"sodium_100g" : 0.2,
"sodium_value" : 0.2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@
"salt" : 0,
"salt_100g" : "0",
"salt_unit" : "g",
"salt_value" : 0,
"salt_value" : "0",
"saturated-fat_100g" : "10",
"sodium_100g" : 0,
"sodium_value" : "0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@
"salt" : 0,
"salt_100g" : "0",
"salt_unit" : "g",
"salt_value" : 0,
"salt_value" : "0",
"saturated-fat_100g" : "10",
"sodium_100g" : 0,
"sodium_value" : "0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@
"salt" : 0,
"salt_100g" : "0",
"salt_unit" : "g",
"salt_value" : 0,
"salt_value" : "0",
"saturated-fat_100g" : "10",
"sodium_100g" : 0,
"sodium_value" : "0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"salt" : 0,
"salt_100g" : "0",
"salt_unit" : "g",
"salt_value" : 0,
"salt_value" : "0",
"saturated-fat_100g" : "10",
"sodium_100g" : 0,
"sodium_value" : "0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"salt" : 0,
"salt_100g" : "0",
"salt_unit" : "g",
"salt_value" : 0,
"salt_value" : "0",
"saturated-fat_100g" : "10",
"sodium_100g" : 0,
"sodium_value" : "0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@
"salt" : 0.025,
"salt_100g" : 0.025,
"salt_unit" : "g",
"salt_value" : 0.025,
"salt_value" : "0.025",
"saturated-fat_100g" : "0",
"sodium_100g" : 0.01,
"sodium_value" : 0.01,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@
"salt" : 0.025,
"salt_100g" : 0.025,
"salt_unit" : "g",
"salt_value" : 0.025,
"salt_value" : "0.025",
"saturated-fat_100g" : "0",
"sodium_100g" : 0.01,
"sodium_value" : 0.01,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@
"salt" : 0.025,
"salt_100g" : 0.025,
"salt_unit" : "g",
"salt_value" : 0.025,
"salt_value" : "0.025",
"saturated-fat_100g" : "0",
"sodium_100g" : 0.01,
"sodium_value" : 0.01,
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/expected_test_results/nutriscore/en-tofu.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@
"salt" : 0.025,
"salt_100g" : 0.025,
"salt_unit" : "g",
"salt_value" : 0.025,
"salt_value" : "0.025",
"saturated-fat_100g" : "0",
"sodium_100g" : 0.01,
"sodium_value" : 0.01,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
"salt" : 0.025,
"salt_100g" : 0.025,
"salt_unit" : "g",
"salt_value" : 0.025,
"salt_value" : "0.025",
"saturated-fat_100g" : "0",
"sodium_100g" : 0.01,
"sodium_value" : 0.01,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"salt" : 0,
"salt_100g" : "0",
"salt_unit" : "g",
"salt_value" : 0,
"salt_value" : "0",
"saturated-fat_100g" : "0",
"sodium_100g" : 0,
"sodium_value" : "0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@
"sodium" : 0.48,
"sodium_100g" : 0.48,
"sodium_unit" : "g",
"sodium_value" : 0.48,
"sodium_value" : "0.48",
"sugars_100g" : 3.6
},
"nutriments_estimated" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@
"sodium" : 0.48,
"sodium_100g" : 0.48,
"sodium_unit" : "g",
"sodium_value" : 0.48,
"sodium_value" : "0.48",
"sugars_100g" : 3.6
},
"nutriscore" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
"sodium" : 0.012,
"sodium_100g" : 0.012,
"sodium_unit" : "g",
"sodium_value" : 0.012,
"sodium_value" : "0.012",
"sugars_100g" : 0.5
},
"nutriments_estimated" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@
"salt" : 0.5,
"salt_100g" : 0.5,
"salt_unit" : "g",
"salt_value" : 0.5,
"salt_value" : "0.5",
"saturated-fat_100g" : 0.2,
"sodium_100g" : 0.2,
"sodium_value" : 0.2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
"sodium" : 0.32,
"sodium_100g" : 0.32,
"sodium_unit" : "g",
"sodium_value" : 0.32,
"sodium_value" : "0.32",
"sugars_100g" : 3.6
},
"nutriments_estimated" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@
"salt" : 0.025,
"salt_100g" : 0.025,
"salt_unit" : "g",
"salt_value" : 0.025,
"salt_value" : "0.025",
"saturated-fat_100g" : "0",
"sodium_100g" : 0.01,
"sodium_value" : 0.01,
Expand Down
Loading

0 comments on commit 7f4945f

Please sign in to comment.