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: manufacturing place + origins of ingredients knowledge panels + Normalize all panels #6069

Merged
merged 5 commits into from
Nov 15, 2021

Conversation

stephanegigandet
Copy link
Contributor

  • Added a new "map" element to the knowledge panel API, with a list of pointers with geo coordinates
  • Web implementation of the map element (reusing the code we have for packaging codes on pages like https://uk.openfoodfacts.org/packager-code/uk-uw020-ec ) --> this uses leaflet and openstreetmap.
  • Added a manufacturing place knowledge panel, with the coordinates of the first packaging code of the product (a few products have more than one packaging code, but it's very rare)
  • Added an origins of ingredients knowledge panel (slightly different from the one for the Eco-Score bonus for origins of ingredients)

To test:

https://uk.openfoodfacts.dev/product/3266980033613/l-escalope-cordon-bleu-de-poulet-x2-le-gaulois

Knowledge panels JSON:

https://fr.openfoodfacts.dev/api/v2/produit/3266980033613/l-escalope-cordon-bleu-de-poulet-x2-le-gaulois?fields=knowledge_panels

image

To do: evaluate the manufacturing place good / average / bad with the distance to the user.

@stephanegigandet stephanegigandet added the 📖 Knowledge Panels https://wiki.openfoodfacts.org/Knowledge_panels label Nov 10, 2021
@stephanegigandet stephanegigandet requested a review from a team as a code owner November 10, 2021 16:13
@stephanegigandet stephanegigandet changed the title Feat: manufacturing place + origins of ingredients knowledge panels Feat: manufacturing place + origins of ingredients knowledge panels + Normalize all panels Nov 12, 2021
@stephanegigandet
Copy link
Contributor Author

After discussing with @jasmeet0817 , we decided to make some changes to the knowledge panels API and to normalize all of them:

  • Added a "root" panel that lists in order all the panels we want to display directly on the product page (currently only the "environment_card" panel)
  • Removed "panel_parent_id"
  • Removed the panel "type" for most panels, kept only a "type": "card" for the environment card.
  • Made "expanded" a boolean
  • Removed "type" for tables

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.

LGTM, some minor comments.

};
};

$template_data_ref->{encode_json} = sub($) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
$template_data_ref->{encode_json} = sub($) {
# add json encoding function to templates
$template_data_ref->{encode_json} = sub($) {

Copy link
Contributor Author

@stephanegigandet stephanegigandet Nov 12, 2021

Choose a reason for hiding this comment

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

There's a comment above that code:
# Add functions and values that are passed to all templates
So I'm not sure if it makes sense to have 1 comment per function too.

$log->debug("create_manufacturing_place_panel", { code => $product_ref->{code} }) if $log->is_debug();

# Go through the product packaging codes, keep the first one with associated geo coordinates
if (defined $product_ref->{emb_codes_tags}) {
Copy link
Member

Choose a reason for hiding this comment

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

you changed indent width ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mmmh, I probably copy/pasted the $log line, and it put a tab, which in my VSCode is 4 spaces.

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I'm guessing github only use indent_size 2, but does not switch to 4 for Perl files as defined in .editorconfig

[*]
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

Perl files: tab indentation (4 spaces)

[*.{pm,pl,t}]
indent_style = tab
indent_size = 4

Python files: 4 spaces indentation

[*.py]
indent_size = 4


# Go through the product packaging codes, keep the first one with associated geo coordinates
if (defined $product_ref->{emb_codes_tags}) {
foreach my $packager_code_tagid (@{$product_ref->{emb_codes_tags}}) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
foreach my $packager_code_tagid (@{$product_ref->{emb_codes_tags}}) {
# we will create panel for the first known localtion
foreach my $packager_code_tagid (@{$product_ref->{emb_codes_tags}}) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, I'm adding it

packager_code_data => $packager_codes{$packager_code_tagid},
lat => $lat + 0.0,
lng => $lng + 0.0,
};
Copy link
Member

Choose a reason for hiding this comment

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

Not necessarily for action, but as we talked about de-intricating modules:

This is typically a case, where I think we could separate concerns :

  1. you want to find a valid packager location from a list of packages codes --> this is a good function to have in the packager code package (and an iterator would even be better)
  2. having this, you use it here to get the data and generate your template.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, filed #6072 to do it later.

"subtitle": "[% panel.packager_code_data.provincia_localidad %]",
[% ELSIF panel.packager_code_data.cc == 'uk' %]
"subtitle": "[% panel.packager_code_data.district %]",
[% END %]
Copy link
Member

Choose a reason for hiding this comment

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

Wow that seems not very scalable ! Why do we have different fields name based on the country ?

We should at least hide it in a perl function…

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well it's complicated: each country has a registry of packaging codes to companies, but each of them has completely different fields for them. So far we chose to include all the fields they have, but we have not attempted to map fields to common names.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So here in fact I think it's more of a display choice: for each country, which field do we want to use as title, and which field do we want to use as subtitle. We can't always use the same field (e.g. the company name, or the city + the country) because those fields may not be available for that country.

@sonarcloud
Copy link

sonarcloud bot commented Nov 12, 2021

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
0.0% 0.0% Duplication

@stephanegigandet stephanegigandet merged commit d37011a into main Nov 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📖 Knowledge Panels https://wiki.openfoodfacts.org/Knowledge_panels
Projects
Development

Successfully merging this pull request may close these issues.

2 participants