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

feat: dq_kcal_does_not_match_exclude_more #9339

Merged
merged 7 commits into from
Nov 28, 2023
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
14 changes: 13 additions & 1 deletion lib/ProductOpener/DataQualityFood.pm
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,19 @@ sub check_nutrition_data_energy_computation ($product_ref) {
my ($ignore_energy_calculated_error, $category_id)
= get_inherited_property_from_categories_tags($product_ref, "ignore_energy_calculated_error:en");

if (not((defined $ignore_energy_calculated_error) and ($ignore_energy_calculated_error eq 'yes'))) {
if (
(
not((defined $ignore_energy_calculated_error) and ($ignore_energy_calculated_error eq 'yes'))
# consider only when energy is high enough to minimize false positives (issue #7789)
# consider either computed_energy or energy input by contributor, to avoid when the energy is 5, but it should be 1500
and (
(($unit eq "kj") and (($specified_energy > 55) or ($computed_energy > 55)))
or ( ($unit eq "kcal")
and (($specified_energy > 13) or ($computed_energy > 13)))
)
)
)
{
# Compare to specified energy value with a tolerance of 30% + an additiontal tolerance of 5
if ( ($computed_energy < ($specified_energy * 0.7 - 5))
or ($computed_energy > ($specified_energy * 1.3 + 5)))
Expand Down
3 changes: 3 additions & 0 deletions stop_words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ aromatisées
arôme
auth
autocomplete
autocompletion
backend
backticks
barcode
Expand Down Expand Up @@ -59,6 +60,7 @@ dataset
datasets
de
dont
dropdown
ecoscore
eg
emb
Expand Down Expand Up @@ -139,6 +141,7 @@ malus
margarines
matche
md
memcached
métal
microservice
microservices
Expand Down
1 change: 1 addition & 0 deletions taxonomies/categories.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92455,6 +92455,7 @@ th:ใช้น้ำตาลเทียม
tr:Tatlandırıcı, Tatlandırıcılar
zh:糖精
wikidata:en:Q4368298
ignore_energy_calculated_error:en:yes

<en:Sweeteners
en:Sugars
Expand Down
36 changes: 35 additions & 1 deletion tests/unit/dataqualityfood.t
Original file line number Diff line number Diff line change
Expand Up @@ -374,12 +374,46 @@ $product_ref = {
}
};
ProductOpener::DataQuality::check_quality($product_ref);
ok(
!has_tag($product_ref, 'data_quality', 'en:energy-value-in-kj-does-not-match-value-computed-from-other-nutrients'),
'energy not matching nutrients but category possesses ignore_energy_calculated_error:en:yes tag'
) or diag explain $product_ref;

$product_ref = {
categories_tags => ['en:sweeteners'],
nutriments => {
"energy-kj_value" => 550,
"carbohydrates_value" => 10,
"fat_value" => 20,
"proteins_value" => 30,
"fiber_value" => 2,
}
};
ProductOpener::DataQuality::check_quality($product_ref);
is($product_ref->{nutriments}{"energy-kj_value_computed"}, 1436);
ok(
!has_tag($product_ref, 'data_quality', 'en:energy-value-in-kj-does-not-match-value-computed-from-other-nutrients'),
'energy not matching nutrients but category possesses ignore_energy_calculated_error:en:yes tag'
) or diag explain $product_ref;

$product_ref = {
categories_tags => ['en:sweet-spreads'],
nutriments => {
"energy-kj_value" => 8,
"fat_value" => 0.5,
"saturated-fat_value" => 0.1,
"carbohydrates_value" => 0.5,
"sugars_value" => 0.5,
"proteins_value" => 0.5,
"salt_value" => 0.01,
}
};
ProductOpener::DataQuality::check_quality($product_ref);
ok(
!has_tag($product_ref, 'data_quality', 'en:energy-value-in-kj-does-not-match-value-computed-from-other-nutrients'),
'energy not matching nutrients but energy is lower than 55 kj'
) or diag explain $product_ref;

# energy matches nutrients
$product_ref = {
nutriments => {
Expand Down Expand Up @@ -462,7 +496,7 @@ $product_ref = {
};
ProductOpener::DataQuality::check_quality($product_ref);
ok(has_tag($product_ref, 'data_quality', 'en:energy-value-in-kj-does-not-match-value-computed-from-other-nutrients'),
'energy not matching nutrient')
'energy not matching nutrient but lower than 55 kj')
or diag explain $product_ref;

# Erythritol is a polyol which does not contribute to energy
Expand Down
Loading