Skip to content

Commit

Permalink
feat: added error facet for sum of -ose nutriments greater than sugars (
Browse files Browse the repository at this point in the history
#8120)

* added error facet for sum of -ose nutriments greater than sugars

* Update lib/ProductOpener/DataQualityFood.pm

typo

Co-authored-by: Stéphane Gigandet <[email protected]>

---------

Co-authored-by: Stéphane Gigandet <[email protected]>
  • Loading branch information
benbenben2 and stephanegigandet authored Feb 24, 2023
1 parent 94faf7c commit 6fabb9d
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lib/ProductOpener/DataQualityFood.pm
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,36 @@ sub check_nutrition_data ($product_ref) {
"en:nutrition-sugars-plus-starch-greater-than-carbohydrates";
}

# sum of nutriments that compose sugar can not be greater than sugar value
if (
(defined $product_ref->{nutriments}{sugars_100g})
and (
(
(
(defined $product_ref->{nutriments}{fructose_100g}) ? $product_ref->{nutriments}{fructose_100g}
: 0
) + (
(defined $product_ref->{nutriments}{glucose_100g}) ? $product_ref->{nutriments}{glucose_100g}
: 0
) + (
(defined $product_ref->{nutriments}{maltose_100g}) ? $product_ref->{nutriments}{maltose_100g}
: 0
) + (
(defined $product_ref->{nutriments}{lactose_100g}) ? $product_ref->{nutriments}{lactose_100g}
: 0
) + (
(defined $product_ref->{nutriments}{sucrose_100g}) ? $product_ref->{nutriments}{sucrose_100g}
: 0
)
) > ($product_ref->{nutriments}{sugars_100g}) + 0.001
)
)
{

push @{$product_ref->{data_quality_errors_tags}},
"en:nutrition-fructose-plus-glucose-plus-maltose-plus-lactose-plus-sucrose-greater-than-sugars";
}

if (
(
(defined $product_ref->{nutriments}{"saturated-fat_100g"})
Expand Down
3 changes: 3 additions & 0 deletions taxonomies/data_quality.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ en:Nutrition - Sugars plus starch greater than carbohydrates
es:Nutrición: azúcares más almidón más que los carbohidratos
fr:Nutrition - Sucres plus amidon supérieurs aux glucides

<en:Nutrition errors
en:Nutrition - Fructose plus glucose plus maltose plus lactose plus sucrose greater than sugars

<en:Nutrition errors
en:Nutrition Saturated Fat greater than Fat
fr:Acides gras saturés supérieurs aux matières grasses
Expand Down
120 changes: 120 additions & 0 deletions tests/unit/dataqualityfood.t
Original file line number Diff line number Diff line change
Expand Up @@ -547,4 +547,124 @@ check_quality_and_test_product_has_quality_tag(
'en:ingredients-extracted-ingredient-from-picture-with-more-than-100-percent',
'percentage should not be above 100, error when extracting the ingredients from the picture', 0
);
# sum of fructose plus glucose plus maltose plus lactose plus sucrose cannot be greater than sugars
$product_ref = {nutriments => {}};
ProductOpener::DataQuality::check_quality($product_ref);
check_quality_and_test_product_has_quality_tag(
$product_ref,
'en:nutrition-fructose-plus-glucose-plus-maltose-plus-lactose-plus-sucrose-greater-than-sugars',
'sum of fructose plus glucose plus maltose plus lactose plus sucrose cannot be greater than sugars', 0
);
$product_ref = {
nutriments => {
"sugars_100g" => 1,
}
};
ProductOpener::DataQuality::check_quality($product_ref);
check_quality_and_test_product_has_quality_tag(
$product_ref,
'en:nutrition-fructose-plus-glucose-plus-maltose-plus-lactose-plus-sucrose-greater-than-sugars',
'sum of fructose plus glucose plus maltose plus lactose plus sucrose cannot be greater than sugars', 0
);
$product_ref = {
nutriments => {
"fructose_100g" => 1,
}
};
ProductOpener::DataQuality::check_quality($product_ref);
check_quality_and_test_product_has_quality_tag(
$product_ref,
'en:nutrition-fructose-plus-glucose-plus-maltose-plus-lactose-plus-sucrose-greater-than-sugars',
'sum of fructose plus glucose plus maltose plus lactose plus sucrose cannot be greater than sugars', 0
);
$product_ref = {
nutriments => {
"sugars_100g" => 2,
"fructose_100g" => 1,
}
};
ProductOpener::DataQuality::check_quality($product_ref);
check_quality_and_test_product_has_quality_tag(
$product_ref,
'en:nutrition-fructose-plus-glucose-plus-maltose-plus-lactose-plus-sucrose-greater-than-sugars',
'sum of fructose plus glucose plus maltose plus lactose plus sucrose cannot be greater than sugars', 0
);
$product_ref = {
nutriments => {
"sugars_100g" => 0,
"fructose_100g" => 2,
}
};
ProductOpener::DataQuality::check_quality($product_ref);
check_quality_and_test_product_has_quality_tag(
$product_ref,
'en:nutrition-fructose-plus-glucose-plus-maltose-plus-lactose-plus-sucrose-greater-than-sugars',
'sum of fructose plus glucose plus maltose plus lactose plus sucrose cannot be greater than sugars', 1
);
$product_ref = {
nutriments => {
"sugars_100g" => 1,
"fructose_100g" => 1,
}
};
ProductOpener::DataQuality::check_quality($product_ref);
check_quality_and_test_product_has_quality_tag(
$product_ref,
'en:nutrition-fructose-plus-glucose-plus-maltose-plus-lactose-plus-sucrose-greater-than-sugars',
'sum of fructose plus glucose plus maltose plus lactose plus sucrose cannot be greater than sugars', 0
);
ProductOpener::DataQuality::check_quality($product_ref);
check_quality_and_test_product_has_quality_tag(
$product_ref,
'en:nutrition-fructose-plus-glucose-plus-maltose-plus-lactose-plus-sucrose-greater-than-sugars',
'sum of fructose plus glucose plus maltose plus lactose plus sucrose cannot be greater than sugars', 0
);
$product_ref = {
nutriments => {
"sugars_100g" => 20,
"fructose_100g" => 1,
"glucose_100g" => 1,
"maltose_100g" => 1,
"lactose_100g" => 1,
"sucrose_100g" => 1,
}
};
ProductOpener::DataQuality::check_quality($product_ref);
check_quality_and_test_product_has_quality_tag(
$product_ref,
'en:nutrition-fructose-plus-glucose-plus-maltose-plus-lactose-plus-sucrose-greater-than-sugars',
'sum of fructose plus glucose plus maltose plus lactose plus sucrose cannot be greater than sugars', 0
);
$product_ref = {
nutriments => {
"sugars_100g" => 1,
"fructose_100g" => 1,
"glucose_100g" => 1,
"maltose_100g" => 1,
"lactose_100g" => 1,
"sucrose_100g" => 1,
}
};
ProductOpener::DataQuality::check_quality($product_ref);
check_quality_and_test_product_has_quality_tag(
$product_ref,
'en:nutrition-fructose-plus-glucose-plus-maltose-plus-lactose-plus-sucrose-greater-than-sugars',
'sum of fructose plus glucose plus maltose plus lactose plus sucrose cannot be greater than sugars', 1
);
$product_ref = {
nutriments => {
"sugars_100g" => 20,
"fructose_100g" => 4,
"glucose_100g" => 4,
"maltose_100g" => 4,
"lactose_100g" => 4,
"sucrose_100g" => 4,
}
};
ProductOpener::DataQuality::check_quality($product_ref);
check_quality_and_test_product_has_quality_tag(
$product_ref,
'en:nutrition-fructose-plus-glucose-plus-maltose-plus-lactose-plus-sucrose-greater-than-sugars',
'sum of fructose plus glucose plus maltose plus lactose plus sucrose cannot be greater than sugars', 0
);
done_testing();

0 comments on commit 6fabb9d

Please sign in to comment.