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 v2 2023 knowledge panels #9689

Merged
merged 13 commits into from
Feb 6, 2024

Conversation

stephanegigandet
Copy link
Contributor

@stephanegigandet stephanegigandet commented Jan 24, 2024

  • Small refactor of nutrition traffic lights (now included in a new parent panel, not expanded by default on the app)
  • Refactor of the Nutri-Score computation explanation, to use knowledge panels.
  • New Nutri-Score "New formula" logos with a blue banner
  • New explanations for components of the Nutri-Score
  • New description of the Nutri-Score (see Add a short explainer of the Nutri-Score in panel #9659)

Initially I wanted to use modified nutrition traffic lights as sub panels of the Nutri-Score, in order to explain the points, but the scales really don't match between the UK traffic lights and the new Nutri-Score thresholds. It's very difficult as some nutrients have a maximum of very few points (e.g. 4, 5 or 6 for positive points), while some others can be 10, 15 or 20 (for salt).

I started a table to compare the Nutri-Score thresholds of the traffic lights points if you want to take a look:
https://docs.google.com/spreadsheets/d/16wzjt5yBghmhaA1Ztrh8Rq1N1Esc8br6Wl6mzSuVD-4/edit#gid=0

So instead I use squares so that it's easy to see at a glance what contributes to a good or bad Nutri-Score, added to the design @teolemon created on mockups on Figma: https://www.figma.com/file/nFMjewFAOa8c4ahtob7CAB/Mobile-App-Design-(Quentin)?type=design&node-id=4189-13160&mode=design

image


image


image

@stephanegigandet stephanegigandet requested a review from a team as a code owner January 24, 2024 19:08
@github-actions github-actions bot added 📖 Knowledge Panels https://wiki.openfoodfacts.org/Knowledge_panels Template::Toolkit The templating toolkit used by product opener. The starting point for HTML/JS/CSS fixes. icons Display 🚦 Nutri-Score labels Jan 24, 2024
@teolemon
Copy link
Member

teolemon commented Jan 25, 2024

  • One easy thing SpF would like solved is this: Add a short explainer of the Nutri-Score in panel #9659
  • Have you deployed it on .dev yet ? @stephanegigandet : I'd like to test how it feels in the app.
  • I'd like to test how it behaves when we have partial data
  • It would be interesting to explore if we can/should display a warning/acknowledgement when the Computer Vision detected Nutri-Score is different from the computed Nutri-Score

@github-actions github-actions bot added API Issues related to the Open Food Facts API. More specific labels exist & should be used (API WRITE…) 🧪 tests Food.pm Numbers 🧪 integration tests 🌐 Translations labels Jan 26, 2024
@stephanegigandet
Copy link
Contributor Author

stephanegigandet commented Jan 26, 2024

There is now an almost finished version on https://world.openfoodfacts.dev

The new Nutri-Score 2023 have not been recomputed on the dev server, so edit and save the product to see the changes.

@teolemon Note that the new panels are only served to admins, but it seems the app is not authenticating when reading products, so it doesn't get the new Nutri-Score panel.

@stephanegigandet stephanegigandet changed the title feat: new Nutri-Score panels (WIP) feat: new Nutri-Score v2 2023 knowledge panels Jan 26, 2024
@teolemon
Copy link
Member

The padding needs to be harmonized on the top and bottom

image

Reword

⚠️ Avertissement : Le taux de fruits, légumes et noix n'est pas indiqué sur l'étiquette, il a été estimé en fonction de la liste des ingrédients : 0
>>
⚠️ Avertissement : Le taux de fruits, légumes et noix (0%) n'est pas indiqué sur l'étiquette, il a été estimé en fonction de la liste des ingrédients.

Put in the protein subpanel ?

Les points pour les protéines ne sont pas comptés car les points négatifs sont supérieurs ou égaux à 11.

Put in one line at the beginning ?

Score nutritionnel : 18 (18 - 0)

Nutri-Score : D

Ce produit est Nutri-Score D, avec un score nutritionnel de 18 (18 - 0).

@teolemon
Copy link
Member

Turn this into a button

image

@stephanegigandet
Copy link
Contributor Author

The padding needs to be harmonized on the top and bottom

@teolemon I can't replicate this, which browser / settings / zoom / resolution etc. are you using?

This is what I have in Chrome and Firefox, and it works with all resolutions / zoom levels I tried.

image

@stephanegigandet
Copy link
Contributor Author

Turn this into a button

@teolemon Well it's a link, not a button. There's currently no concept of link buttons in knowledge panels. We could add one, but it would have to be supported in the app as well.

@stephanegigandet
Copy link
Contributor Author

Put in the protein subpanel ?

Les points pour les protéines ne sont pas comptés car les points négatifs sont supérieurs ou égaux à 11.

Well there's no protein subpanel if we don't count them.

Put in one line at the beginning ?
Score nutritionnel : 18 (18 - 0)
Nutri-Score : D
Ce produit est Nutri-Score D, avec un score nutritionnel de 18 (18 - 0).

I think it's better as-is, less text to read. This is much less useful than the visualization of the points for each component, so we can keep at the end. The numeric score is more for debugging, it's not directly interpretable.

@teolemon
Copy link
Member

Generally speaking, it's still a bit messy, my suggestion above are also around more structure, and a cleaner panel

@stephanegigandet
Copy link
Contributor Author

I'm now hiding the computation details, as those are not useful to end users, and are only useful to verify the score, for producers etc.

image

@teolemon teolemon linked an issue Jan 29, 2024 that may be closed by this pull request
@codecov-commenter
Copy link

codecov-commenter commented Jan 29, 2024

Codecov Report

Attention: 38 lines in your changes are missing coverage. Please review.

Comparison is base (acf96bb) 44.17% compared to head (59dc962) 44.32%.
Report is 32 commits behind head on main.

Files Patch % Lines
lib/ProductOpener/KnowledgePanels.pm 0.00% 26 Missing ⚠️
lib/ProductOpener/Display.pm 0.00% 12 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9689      +/-   ##
==========================================
+ Coverage   44.17%   44.32%   +0.14%     
==========================================
  Files          65       65              
  Lines       20557    20638      +81     
  Branches     4966     4979      +13     
==========================================
+ Hits         9082     9147      +65     
- Misses      10294    10321      +27     
+ Partials     1181     1170      -11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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 for this move in the right direction !

Two blockers and some more minor comments, otherwise LGTM.

Comment on lines 911 to 913
}
$panel_data_ref->{subtitle} = lang_in_other_lc($target_lc,
"attribute_nutriscore_" . $panel_data_ref->{nutriscore_grade} . "_description_short");
Copy link
Member

Choose a reason for hiding this comment

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

Aren't we missing a else here ? (otherwise you are over writing the subtitle attribute defined just above)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, fixing.

lib/ProductOpener/Food.pm Outdated Show resolved Hide resolved
lib/ProductOpener/Nutriscore.pm Outdated Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for putting in an adequate sub-folder.


my @files = glob "$dir/nutriscore-*.svg";

foreach my $lc ("en", "fr") {
Copy link
Member

Choose a reason for hiding this comment

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

Only french and english ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently yes.

Copy link
Member

Choose a reason for hiding this comment

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

For generated images, we could also consider not putting them in the git, but putting them in a data folder ?
We could also use javascript with gulp for this kind of things (so that files ends in the dist folders, and developer experience is still easy).

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's a good idea. Maybe we can do it later, especially if we add logos in more languages.

Copy link
Member

Choose a reason for hiding this comment

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

Is it normal to have a serif-font for "New formula" ? (seems a bit less integrated to me).

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's a sans-serif font (the one we use for "Nutri-Score"). In this file we keep the text as text, so that we can easily edit it, and add new languages. Then it has to be converted to paths and added to the .pl script.

<tspan
       sodipodi:role="line"
       id="tspan18501"
       x="39.753796"
       y="152.5134"
       style="font-style:normal;font-variant:normal;font-weight:800;font-stretch:normal;font-family:Raleway;-inkscape-font-specification:'Raleway Ultra-Bold';fill:#ffffff;stroke-width:0.530607">NEW FORMULA</tspan></text>

@@ -106,8 +106,30 @@ <h5>[% panel.title_element.subtitle %]</h5>
<div class="large-8 small-12 columns">
[% END %]

[% IF panel_group_element.icon_url.defined %]
<img src="[% panel_group_element.icon_url %]"
style="[% IF panel_group_element.icon_size == 'very_small' %]height: 24px;[% ELSIF panel_group_element.icon_size == 'small' %]height:36px;[% ELSE %]height:72px;[% END %]float:left;margin-right:1rem;"
Copy link
Member

Choose a reason for hiding this comment

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

couldn't we factor this kind of logic in a function ?

like choose_size(panel_group_element.icon_size, "24px", "36px", "72px")

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's an option. Or in that case it might be simpler to just create CSS classes, and make the size part of the class name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Filed #9752 so that we can take care of it later.

Copy link

sonarcloud bot commented Feb 5, 2024

Quality Gate Passed Quality Gate passed

Kudos, no new issues were introduced!

0 New issues
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@stephanegigandet stephanegigandet merged commit 8fb04fa into main Feb 6, 2024
13 checks passed
@stephanegigandet stephanegigandet deleted the nutriscore-panels branch February 6, 2024 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Issues related to the Open Food Facts API. More specific labels exist & should be used (API WRITE…) Display Food.pm icons 🧪 integration tests 📖 Knowledge Panels https://wiki.openfoodfacts.org/Knowledge_panels Numbers 🚦 Nutri-Score Template::Toolkit The templating toolkit used by product opener. The starting point for HTML/JS/CSS fixes. 🧪 tests 🌐 Translations
Projects
Development

Successfully merging this pull request may close these issues.

Make Nutri-Score computation easier to read
4 participants