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: compute percent of vegetables for Nutri-Score after removing water for canned vegetables #9210

Merged
merged 4 commits into from
Oct 27, 2023

Conversation

stephanegigandet
Copy link
Contributor

Some categories of products typically have nutrition facts for the "drained product" (produit égoutté in French). We need to take that into account when computing the % of fruits/vegetables.

We don't record if the nutrition facts is for the drained product, so we take a guess that products in the "canned vegetables" category have nutrition facts for the drained product. There are counter examples, but usually those counter examples have little water anyway.

"IS THE NUTRI-SCORE CALCULATED FOR THE PRODUCT WITH THE COVERING LIQUID?
The nutritional score is calculated using the nutritional data listed on the package for 100 g of the product,
whose nutrients form part of the mandatory nutritional declaration or are included as supplemental
information, in accordance with Article 30 of the INCO regulation no. 1169/2011.
If the covering liquid is taken into account in the mandatory nutritional declaration, the Nutri-Score should
also be calculated for the product + the covering liquid and vice versa. To calculate the percent of “fruits,
vegetables, pulses, nuts and oils », you have to use the same basis as the table of nutritional values. If the
covering liquid is taken into account, the calculation should include it. If the nutritional values do not take
the covering liquid into account, then it should be recalculated without the covering liquid."

@stephanegigandet stephanegigandet requested a review from a team as a code owner October 26, 2023 15:33
@github-actions github-actions bot added 🥗 Ingredients 🧪 tests 🥗🔍 Ingredients analysis https://wiki.openfoodfacts.org/Ingredients_Extraction_and_Analysis Food.pm nutriscore labels Oct 26, 2023
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.

I have a comment that needs either a change or a comment in the code.

All good for the rest 👍

$water_percent += $sub_ingredients_water_percent;
}
# Keep track of water
elsif (is_a("ingredients", $ingredient_ref->{id}, 'en:water')) {
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure why it's an elsif here ?

Are we sure that water never match ? Why not a simple if ? Or, maybe, put it as first condition ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was avoid double counting water if we have something like "flavoured water (water, flavour)", but I'll do it differently.

Copy link
Member

Choose a reason for hiding this comment

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

A comment maybe enough then

@alexgarel
Copy link
Member

alexgarel commented Oct 26, 2023

Also you need a make lint !

@codecov-commenter
Copy link

Codecov Report

Merging #9210 (a9373da) into main (f228a4b) will increase coverage by 0.02%.
Report is 6 commits behind head on main.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #9210      +/-   ##
==========================================
+ Coverage   47.95%   47.97%   +0.02%     
==========================================
  Files          65       65              
  Lines       20223    20231       +8     
  Branches     4914     4916       +2     
==========================================
+ Hits         9697     9706       +9     
+ Misses       9271     9270       -1     
  Partials     1255     1255              
Files Coverage Δ
lib/ProductOpener/Food.pm 70.83% <ø> (ø)
lib/ProductOpener/Ingredients.pm 92.81% <100.00%> (+0.08%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@sonarqubecloud
Copy link

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

@stephanegigandet stephanegigandet enabled auto-merge (squash) October 27, 2023 08:13
@stephanegigandet stephanegigandet merged commit 273d120 into main Oct 27, 2023
13 checks passed
@stephanegigandet stephanegigandet deleted the drain-the-canned-vegetables branch October 27, 2023 08:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Food.pm 🥗🔍 Ingredients analysis https://wiki.openfoodfacts.org/Ingredients_Extraction_and_Analysis 🥗 Ingredients 🧪 tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants