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: New Nutri-Score formula (v2) for food (2022) and beverages (2023) - ready for review #8832

Merged
merged 40 commits into from
Aug 29, 2023

Conversation

stephanegigandet
Copy link
Contributor

@stephanegigandet stephanegigandet commented Aug 10, 2023

What

Implement the new formula for the Nutri-Score.

At this point the new Nutri-Score is not displayed: we still compute and display the old Nutri-Score, but the new Nutri-Score is visible through the API (new "nutriscore" structure) and there are new misc facets values to compare the old and previous Nutri-Score:

image

  • Refactored the compute_nutriscore() function in Food.pm
  • Duplicated functions in Nutriscore.pm so that we can compute both versions, and then easily remove the older version when not needed anymore
  • A new "nutriscore" structure contains the nutriscore input data and results for both the 2021 and 2023 versions (and possibly upcoming new versions). When the old nutriscore is completely retired, we will remove the 2021 data and computations.
  • New /nutri-score , /nutri-score-2021 and /nutri-score-2023 facets (the last 2 are temporary, for debugging purposes), the first one will at some point replace the /nutritional-grades facet which contains the same values.
  • Added some tests

Still missing

  • Proper estimation of the % of fruits / vegetables / legumes. Currently we still use the estimation from the 2021 Nutri-Score which includes nuts and olive / walnut / rapeseed oil. To do this correctly, we first need to add Eurocodes properties to the ingredients taxonomy: Add Eurocode 2 groups as properties in the ingredients taxonomy #8825
  • Actually showing the new Nutri-Score on the app and mobile app (possibly at first alongside the old Nutri-Score)

Testing

This PR has been deployed on the dev server:

Part of

@stephanegigandet stephanegigandet requested a review from a team as a code owner August 10, 2023 14:10
@github-actions github-actions bot added Data import 🚦Nutri-Score https://world.openfoodfacts.org/nutriscore 🧪 tests 🏭 Producers Platform https://wiki.openfoodfacts.org/Platform_for_producers 🥗🔍 Ingredients analysis https://wiki.openfoodfacts.org/Ingredients_Extraction_and_Analysis Food.pm Products update all products labels Aug 10, 2023
@codecov-commenter
Copy link

codecov-commenter commented Aug 10, 2023

Codecov Report

Merging #8832 (ad362d6) into main (bfd66b5) will decrease coverage by 3.07%.
Report is 2 commits behind head on main.
The diff coverage is 76.19%.

@@            Coverage Diff             @@
##             main    #8832      +/-   ##
==========================================
- Coverage   45.54%   42.47%   -3.07%     
==========================================
  Files          64       61       -3     
  Lines       19527    19421     -106     
  Branches     4740     4738       -2     
==========================================
- Hits         8893     8250     -643     
- Misses       9458    10035     +577     
+ Partials     1176     1136      -40     
Files Changed Coverage Δ
lib/ProductOpener/Import.pm 30.67% <0.00%> (-12.10%) ⬇️
lib/ProductOpener/Nutriscore.pm 64.06% <62.80%> (-5.61%) ⬇️
lib/ProductOpener/Food.pm 66.86% <89.06%> (+1.78%) ⬆️
lib/ProductOpener/Products.pm 42.67% <100.00%> (-4.48%) ⬇️

... and 20 files with indirect coverage changes

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

if ($is_beverage) {

if ($is_water) {
$grade = 'a';
Copy link
Member

@teolemon teolemon Aug 28, 2023

Choose a reason for hiding this comment

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

this could be a nice place to include an explanatory comment for the knowledge panel in the structure

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The structure already has the structured data with the is_water field. The comment will need to be localized, it will be loaded in the knowledge panel template.

po/tags/en.po Outdated Show resolved Hide resolved
po/tags/tags.pot Outdated Show resolved Hide resolved
@@ -97765,6 +97869,8 @@ agribalyse_food_code:en:20901
ciqual_food_code:en:20901
ciqual_food_name:en:Soybean, whole grain
ciqual_food_name:fr:Soja, graine entière
wco_hs_heading:en: 12.01
wco_hs_code:en: 1201.10
Copy link
Member

Choose a reason for hiding this comment

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

do you have a spreadsheet somewhere where you track associations if you need help ? @stephanegigandet

# eurocode_2_group_2:en: 8.25
# eurocode_2_group_3:en: 8.25.50
# are from https://web.archive.org/web/20170712020557/http://www.ianunwin.demon.co.uk/eurocode/docmn/ec99/ecmgintr.htm#MGList

Copy link
Member

Choose a reason for hiding this comment

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

do you have a spreadsheet somewhere where you track associations if you need help ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't have a spreadsheet, we could create one

@@ -1171,6 +1175,73 @@
"sodium_100g" : 0.1,
"sugars_100g" : 25
},
"nutriscore" : {
Copy link
Member

Choose a reason for hiding this comment

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

Why does attribute receive such a detailed structure ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the attribute tests, we save the whole product, not just the attributes related fields. It's very useful to debug the attributes.

"fiber_points" : 3,
"fruits_vegetables_legumes" : 100,
"fruits_vegetables_legumes_points" : 5,
"is_beverage" : 0,
Copy link
Member

Choose a reason for hiding this comment

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

same Q here.

@github-actions github-actions bot removed the 💥 Merge Conflicts 💥 Merge Conflicts label Aug 28, 2023
stephanegigandet and others added 2 commits August 29, 2023 10:32
Co-authored-by: Pierre Slamich <pierre@openfoodfacts.org>
@github-actions github-actions bot added the 💥 Merge Conflicts 💥 Merge Conflicts label Aug 29, 2023
@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 merged commit 8ce0abc into main Aug 29, 2023
@stephanegigandet stephanegigandet deleted the nutriscore-v2 branch August 29, 2023 17:15
@teolemon teolemon added 🚦 Nutri-Score and removed 🚦Nutri-Score https://world.openfoodfacts.org/nutriscore labels May 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
categories Data import Food.pm 🥗🔍 Ingredients analysis https://wiki.openfoodfacts.org/Ingredients_Extraction_and_Analysis 💥 Merge Conflicts 💥 Merge Conflicts 🚦 Nutri-Score 🏭 Producers Platform https://wiki.openfoodfacts.org/Platform_for_producers Products 🧬 Taxonomies https://wiki.openfoodfacts.org/Global_taxonomies 🧪 tests Translations We use a non-standard version of GetText, lack language variants support translate.openfoodfacts.org update all products
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants