Skip to content

Commit

Permalink
fix: dq_nutrition_rm_salt_under_01g (#9464)
Browse files Browse the repository at this point in the history
* dq_nutrition_rm_salt_under_01g

* upd tests
  • Loading branch information
benbenben2 authored Dec 5, 2023
1 parent 1d98c75 commit 5ed2c36
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 11 deletions.
4 changes: 1 addition & 3 deletions lib/ProductOpener/DataQualityFood.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1256,6 +1256,7 @@ sub check_nutrition_data ($product_ref) {
}

# Too small salt value? (e.g. g entered in mg)
# warning for salt < 0.1 was removed because it was leading to too much false positives (see #9346)
if ((defined $product_ref->{nutriments}{"salt_100g"}) and ($product_ref->{nutriments}{"salt_100g"} > 0)) {

if ($product_ref->{nutriments}{"salt_100g"} < 0.001) {
Expand All @@ -1264,9 +1265,6 @@ sub check_nutrition_data ($product_ref) {
elsif ($product_ref->{nutriments}{"salt_100g"} < 0.01) {
push @{$product_ref->{data_quality_warnings_tags}}, "en:nutrition-value-under-0-01-g-salt";
}
elsif ($product_ref->{nutriments}{"salt_100g"} < 0.1) {
push @{$product_ref->{data_quality_warnings_tags}}, "en:nutrition-value-under-0-1-g-salt";
}
}

# some categories have expected nutriscore grade - push data quality error if calculated nutriscore grade differs from expected nutriscore grade or if it is not calculated
Expand Down
4 changes: 0 additions & 4 deletions taxonomies/data_quality.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2732,10 +2732,6 @@ en:Nutrition value under 0,001 g - Salt
en:Nutrition value under 0,01 g - Salt
#description:en:

<en:Nutrition warnings
en:Nutrition value under 0,1 g salt
#description:en:

<en:Nutrition warnings
en:Nutrition value very high for category - Carbohydrates
description:en:Compared to the category average, the Carbohydrates value is abnormally high.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,10 @@
"en:food-groups-1-known",
"en:food-groups-2-known",
"en:food-groups-3-unknown",
"en:nutrition-value-under-0-1-g-salt",
"en:ecoscore-origins-of-ingredients-origins-are-100-percent-unknown",
"en:ecoscore-packaging-packaging-data-missing"
],
"data_quality_warnings_tags" : [
"en:nutrition-value-under-0-1-g-salt",
"en:ecoscore-origins-of-ingredients-origins-are-100-percent-unknown",
"en:ecoscore-packaging-packaging-data-missing"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,10 @@
"en:food-groups-1-known",
"en:food-groups-2-known",
"en:food-groups-3-unknown",
"en:nutrition-value-under-0-1-g-salt",
"en:ecoscore-origins-of-ingredients-origins-are-100-percent-unknown",
"en:ecoscore-packaging-packaging-data-missing"
],
"data_quality_warnings_tags" : [
"en:nutrition-value-under-0-1-g-salt",
"en:ecoscore-origins-of-ingredients-origins-are-100-percent-unknown",
"en:ecoscore-packaging-packaging-data-missing"
],
Expand Down
53 changes: 53 additions & 0 deletions tests/unit/dataqualityfood.t
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,59 @@ check_quality_and_test_product_has_quality_tag(
'sum of fructose plus glucose plus maltose plus lactose plus sucrose cannot be greater than sugars', 0
);

# salt_100g is very small warning (may be in mg)
## lower than 0.001
$product_ref = {
nutriments => {
salt_100g => 0.0009, # lower than 0.001
}
};
ProductOpener::DataQuality::check_quality($product_ref);
check_quality_and_test_product_has_quality_tag(
$product_ref,
'en:nutrition-value-under-0-001-g-salt',
'value for salt is lower than 0.001g', 1
);
check_quality_and_test_product_has_quality_tag(
$product_ref,
'en:nutrition-value-under-0-01-g-salt',
'value for salt is lower than 0.001g, should not trigger warning for 0.01', 0
);
## lower than 0.01
$product_ref = {
nutriments => {
salt_100g => 0.009, # lower than 0.01
}
};
ProductOpener::DataQuality::check_quality($product_ref);
check_quality_and_test_product_has_quality_tag(
$product_ref,
'en:nutrition-value-under-0-001-g-salt',
'value for salt is above 0.001g', 0
);
check_quality_and_test_product_has_quality_tag(
$product_ref,
'en:nutrition-value-under-0-01-g-salt',
'value for salt is lower than 0.001g, and above 0.01', 1
);
## above 0.01
$product_ref = {
nutriments => {
salt_100g => 0.02, # above 0.01
}
};
ProductOpener::DataQuality::check_quality($product_ref);
check_quality_and_test_product_has_quality_tag(
$product_ref,
'en:nutrition-value-under-0-001-g-salt',
'value for salt is above 0.001g', 0
);
check_quality_and_test_product_has_quality_tag(
$product_ref,
'en:nutrition-value-under-0-01-g-salt',
'value for salt is above 0.001g', 0
);

# testing of ProductOpener::DataQualityFood::check_quantity subroutine
$product_ref = {quantity => "300g"};
ProductOpener::DataQuality::check_quality($product_ref);
Expand Down

0 comments on commit 5ed2c36

Please sign in to comment.