Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: data quality - increase threshold for comparison between fiber and its subnutriments #11145

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/ProductOpener/DataQualityFood.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1340,7 +1340,9 @@ sub check_nutrition_data ($product_ref) {

my $total_fiber = $soluble_fiber + $insoluble_fiber;

if ($total_fiber > $product_ref->{nutriments}{fiber_100g} + 0.001) {
# increased threshold from 0.001 to 0.01 (see issue #10491)
# make sure that floats stop after 2 decimals
if (sprintf("%.2f", $total_fiber) > sprintf("%.2f", $product_ref->{nutriments}{fiber_100g} + 0.01)) {
push @{$product_ref->{data_quality_errors_tags}},
"en:nutrition-soluble-fiber-plus-insoluble-fiber-greater-than-fiber";
}
Expand Down
34 changes: 34 additions & 0 deletions tests/unit/dataqualityfood.t
Original file line number Diff line number Diff line change
Expand Up @@ -1974,4 +1974,38 @@ ok(
'insoluble-fiber_100g larger than fiber_100g'
) or diag Dumper $product_ref;

# Test case for sum fiber subnutriment comparison with fiber (0.01 difference should be fine)
$product_ref = {
nutriments => {
fiber_100g => 3.57,
'soluble-fiber_100g' => 1.79,
'insoluble-fiber_100g' => 1.79,
},
data_quality_errors_tags => [],
};

ProductOpener::DataQuality::check_quality($product_ref);

ok(
!has_tag($product_ref, 'data_quality_errors', 'en:nutrition-soluble-fiber-plus-insoluble-fiber-greater-than-fiber'),
'insoluble-fiber_100g larger than fiber_100g'
) or diag Dumper $product_ref;

# Test case for sum fiber subnutriment comparison with fiber (0.02 difference should be raise error)
$product_ref = {
nutriments => {
fiber_100g => 3.57,
'soluble-fiber_100g' => 1.79,
'insoluble-fiber_100g' => 1.80,
},
data_quality_errors_tags => [],
};

ProductOpener::DataQuality::check_quality($product_ref);

ok(
has_tag($product_ref, 'data_quality_errors', 'en:nutrition-soluble-fiber-plus-insoluble-fiber-greater-than-fiber'),
'insoluble-fiber_100g larger than fiber_100g'
) or diag Dumper $product_ref;

done_testing();
Loading