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: updated test for serving_size for nutrition table #8685

Merged
merged 1 commit into from
Jul 12, 2023

Conversation

benbenben2
Copy link
Collaborator

Reminder: serving_size is the input from the contributor, serving_quantity is the extracted quantity from the serving_size

  1. Nutrition data per serving - Serving quantity is unknown

  2. Nutrition data per serving - Serving quantity is not recognized

  3. Nutrition data per serving - Serving quantity is 0 --> only when we actually get "0 g" or similar

  4. would be exact same as: en:nutrition-data-per-serving-missing-serving-size
    previously it was a warning
    updated to be an error

Remark about 2 & 3)

input "une crepe 25 grammes" -> output serving_quantity=25 (special case, supposedly due to unit_equivalences_list in Units.pm)
input "100 milliliter" -> output serving_quantity not in result
input "3 pcs" -> output serving_quantity not in result
2 comprimés -> missing
1 container -> missing
serving -> 0
input "1/4 cup" -> output serving_quantity=0

Reason is that normalize_serving_size subroutine in Units.pm returns 0 if it cannot extract the serving otherwise it returns the result of the subroutine unit_to_g, and this latter return either something or nothing (i.e., not 0)

  1. (new) en:nutrition-data-per-serving-serving-quantity-is-not-recognized
    This covers both cases:
    2)a) Serving quantity is not recognized - but regex did work) and
    2)b) Serving quantity is not recognized - and regex to extract "quantity" and "unit" does not work
    This should never be 0

  2. en:nutrition-data-per-serving-serving-quantity-is-0
    For "0 g" or "0 mL"

  3. (from feat: add data quality warning for serving size without digit #8057) en:Nutrition data per serving - Serving size is missing digits

tested locally:
input - result
10 ml - ok
empty - 1
serving - 2 and 4
0g - 3
0 mL - 3

@benbenben2 benbenben2 requested a review from a team as a code owner July 11, 2023 17:28
@github-actions github-actions bot added 🧬 Taxonomies https://wiki.openfoodfacts.org/Global_taxonomies 🧽 Data quality https://wiki.openfoodfacts.org/Quality 🧪 tests labels Jul 11, 2023
@sonarcloud
Copy link

sonarcloud bot commented Jul 11, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

Copy link
Member

@alexgarel alexgarel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot @benbenben2

Comment on lines +572 to +586
check_quality_and_test_product_has_quality_tag(
$product_ref,
'en:nutrition-data-per-serving-missing-serving-size',
'serving size should be provided if "per serving" is selected', 0
);
check_quality_and_test_product_has_quality_tag(
$product_ref,
'en:nutrition-data-per-serving-serving-quantity-is-0',
'serving size equal to 0 is unexpected', 0
);
check_quality_and_test_product_has_quality_tag(
$product_ref,
'en:nutrition-data-per-serving-serving-quantity-is-not-recognized',
'serving size cannot be parsed', 1
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I see we reapeat the test 3 times, shan't we change check_quality_and_test_product_has_quality_tag to have a list of tags to check for presence, and a list of tags to check for absence ?

Of course in another PR.

@alexgarel alexgarel merged commit 6f5a88b into main Jul 12, 2023
@alexgarel alexgarel deleted the quality_facet_nutrition_serving_size branch July 12, 2023 08:27
@CharlesNepote
Copy link
Member

Very good! Thanks a lot @benbenben2 this is far more clear and useful as before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🧽 Data quality https://wiki.openfoodfacts.org/Quality 🧬 Taxonomies https://wiki.openfoodfacts.org/Global_taxonomies 🧪 tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Quality facet - Nutrition - list products where serving size can't be parsed
3 participants