Skip to content

Commit

Permalink
feat: add dq error for product quantity above 30kg (#9316)
Browse files Browse the repository at this point in the history
* add dq error for product quantity above 30kg

* make lint

* fix missing parent error
  • Loading branch information
benbenben2 committed Nov 15, 2023
1 parent 1aacb01 commit b7fe2b2
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/ProductOpener/DataQualityFood.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1298,6 +1298,10 @@ sub check_quantity ($product_ref) {
if ((defined $product_ref->{product_quantity}) and ($product_ref->{product_quantity} ne "")) {
if ($product_ref->{product_quantity} > 10 * 1000) {
push @{$product_ref->{data_quality_warnings_tags}}, "en:product-quantity-over-10kg";

if ($product_ref->{product_quantity} > 30 * 1000) {
push @{$product_ref->{data_quality_errors_tags}}, "en:product-quantity-over-30kg";
}
}
if ($product_ref->{product_quantity} < 1) {
push @{$product_ref->{data_quality_warnings_tags}}, "en:product-quantity-under-1g";
Expand Down
10 changes: 9 additions & 1 deletion taxonomies/data_quality.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2794,6 +2794,14 @@ description:en:Compared to the category average, the Sugars value is abnormally

### Quantity and serving

<en:Data quality errors
en:Quantity and serving errors
description:en: Potential issues on quantities or serving size

<en:Quantity and serving errors
en:Product quantity over 30kg
description:en:Product quantity is above 30kg, which is very unlikely.

<en:Data quality warnings
en:Quantity and serving warnings
description:en: Potential issues on quantities or serving size
Expand All @@ -2804,7 +2812,7 @@ en:Product quantity in mg

<en:Quantity and serving warnings
en:Product quantity over 10kg
#description:en:
description:en:Product quantity is above 10kg, which is unlikely for most of the products

<en:Quantity and serving warnings
en:Product quantity under 1g
Expand Down
36 changes: 36 additions & 0 deletions tests/unit/dataqualityfood.t
Original file line number Diff line number Diff line change
Expand Up @@ -1220,4 +1220,40 @@ check_quality_and_test_product_has_quality_tag(
'en:vegetarian-label-but-could-not-confirm-for-all-ingredients',
'raise warning because vegetarian or non-vegetarian is unknown for an ingredient', 0
);
# product quantity warnings and errors
$product_ref = {product_quantity => "123456789",};
check_quality_and_test_product_has_quality_tag(
$product_ref,
'en:product-quantity-over-10kg',
'raise warning because the product quantity is above 10000g', 1
);
check_quality_and_test_product_has_quality_tag(
$product_ref,
'en:product-quantity-over-30kg',
'raise error because the product quantity is above 30000g', 1
);
# product quantity warnings and errors
$product_ref = {product_quantity => "20000",};
check_quality_and_test_product_has_quality_tag(
$product_ref,
'en:product-quantity-over-10kg',
'raise warning because the product quantity is above 10000g', 1
);
check_quality_and_test_product_has_quality_tag(
$product_ref,
'en:product-quantity-over-30kg',
'raise error because the product quantity is above 30000g', 0
);
$product_ref = {
product_quantity => "0.001",
quantity => "1 mg",
};
check_quality_and_test_product_has_quality_tag(
$product_ref,
'en:product-quantity-under-1g',
'raise warning because the product quantity is under 1g', 1
);
check_quality_and_test_product_has_quality_tag($product_ref, 'en:product-quantity-in-mg',
'raise warning because the product quantity is in mg', 1);

done_testing();

0 comments on commit b7fe2b2

Please sign in to comment.