-
-
Notifications
You must be signed in to change notification settings - Fork 383
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
Changes from all commits
9b330aa
0228dcf
97cf26d
976cc82
f9c41b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -124,8 +124,8 @@ sub create_knowledge_panels($$$$) { | |||||||
$product_ref->{"knowledge_panels_" . $target_lc} = {}; | ||||||||
|
||||||||
# Test panel to test the start of the API | ||||||||
|
||||||||
if ($product_ref->{code} eq "3017620422003") { | ||||||||
# Disabled, kept as reference when we create a "Do you know" panel | ||||||||
if ($product_ref->{code} eq "3017620422003--disabled") { | ||||||||
|
||||||||
my $test_panel_ref = { | ||||||||
parent_panel_id => "root", | ||||||||
|
@@ -165,6 +165,10 @@ sub create_knowledge_panels($$$$) { | |||||||
create_ecoscore_panel($product_ref, $target_lc, $target_cc); | ||||||||
|
||||||||
create_environment_card_panel($product_ref, $target_lc, $target_cc); | ||||||||
|
||||||||
# Create the root panel that contains the panels we want to show directly on the product page | ||||||||
create_panel_from_json_template("root", "api/knowledge-panels/root.tt.json", | ||||||||
{}, $product_ref, $target_lc, $target_cc); | ||||||||
} | ||||||||
|
||||||||
|
||||||||
|
@@ -525,11 +529,80 @@ sub create_environment_card_panel($$$) { | |||||||
|
||||||||
# Tell the environment card template to include packaging recycling panel | ||||||||
$panel_data_ref->{packaging_recycling} = 1; | ||||||||
|
||||||||
|
||||||||
# Create panel for manufacturing place | ||||||||
$panel_data_ref->{manufacturing_place} = create_manufacturing_place_panel($product_ref, $target_lc, $target_cc); | ||||||||
|
||||||||
# Origins of ingredients for the environment card | ||||||||
create_panel_from_json_template("origins_of_ingredients", "api/knowledge-panels/environment/origins_of_ingredients.tt.json", | ||||||||
$panel_data_ref, $product_ref, $target_lc, $target_cc); | ||||||||
|
||||||||
# Create the environment_card panel | ||||||||
create_panel_from_json_template("environment_card", "api/knowledge-panels/environment/environment_card.tt.json", | ||||||||
$panel_data_ref, $product_ref, $target_lc, $target_cc); | ||||||||
} | ||||||||
|
||||||||
|
||||||||
=head2 create_manufacturing_place_panel ( $product_ref, $target_lc, $target_cc ) | ||||||||
|
||||||||
Creates a knowledge panel when we know the location of the manufacturing place, | ||||||||
usually through a packaging code. | ||||||||
|
||||||||
=head3 Arguments | ||||||||
|
||||||||
=head4 product reference $product_ref | ||||||||
|
||||||||
Loaded from the MongoDB database, Storable files, or the OFF API. | ||||||||
|
||||||||
=head4 language code $target_lc | ||||||||
|
||||||||
Returned attributes contain both data and strings intended to be displayed to users. | ||||||||
This parameter sets the desired language for the user facing strings. | ||||||||
|
||||||||
=head4 country code $target_cc | ||||||||
|
||||||||
The Eco-Score depends on the country of the consumer (as the transport bonus/malus depends on it) | ||||||||
|
||||||||
=head3 Return value | ||||||||
|
||||||||
1 to indicate that the panel has been created | ||||||||
0 to indicate that the panel was not created (if we don't have enough data for the product) | ||||||||
|
||||||||
=cut | ||||||||
|
||||||||
sub create_manufacturing_place_panel($$$) { | ||||||||
|
||||||||
my $product_ref = shift; | ||||||||
my $target_lc = shift; | ||||||||
my $target_cc = shift; | ||||||||
|
||||||||
$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}) { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you changed indent width ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 [*] Perl files: tab indentation (4 spaces)[*.{pm,pl,t}] Python files: 4 spaces indentation[*.py] |
||||||||
foreach my $packager_code_tagid (@{$product_ref->{emb_codes_tags}}) { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, I'm adding it |
||||||||
# we will create a panel for the first known location | ||||||||
if (exists $packager_codes{$packager_code_tagid}) { | ||||||||
$log->debug("packager code found for the canon_tagid", { cc => $packager_codes{$packager_code_tagid}{cc} }) if $log->is_debug(); | ||||||||
my ($lat, $lng) = get_packager_code_coordinates($packager_code_tagid); | ||||||||
if ((defined $lat) and (defined $lng)) { | ||||||||
|
||||||||
my $panel_data_ref = { | ||||||||
packager_code_data => $packager_codes{$packager_code_tagid}, | ||||||||
lat => $lat + 0.0, | ||||||||
lng => $lng + 0.0, | ||||||||
}; | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 :
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, filed #6072 to do it later. |
||||||||
|
||||||||
create_panel_from_json_template("manufacturing_place", "api/knowledge-panels/environment/manufacturing_place.tt.json", | ||||||||
$panel_data_ref, $product_ref, $target_lc, $target_cc); | ||||||||
|
||||||||
return 1; | ||||||||
} | ||||||||
} | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
return 0; | ||||||||
} | ||||||||
|
||||||||
1; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
{ | ||
"parent_panel_id": "ecoscore", | ||
"type" : "score", | ||
"level" :"info", | ||
"topics": [ | ||
"environment" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
{ | ||
"parent_panel_id": "ecoscore", | ||
"level" :"info", | ||
"topics": [ | ||
"environment" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"level" :"info", | ||
"topics": [ | ||
"environment" | ||
], | ||
"evaluation": "neutral", | ||
"expanded": true, | ||
"title_element": { | ||
"title": "[% lang('manufacturing_places_s') FILTER ucfirst %]", | ||
[% IF panel.packager_code_data.cc == 'fr' %] | ||
"subtitle": "[% panel.packager_code_data.commune %] - [% display_taxonomy_tag('countries', 'en:france') %]", | ||
[% ELSIF panel.packager_code_data.cc == 'ch' %] | ||
"subtitle": "[% panel.packager_code_data.full_address %]", | ||
[% ELSIF panel.packager_code_data.cc == 'es' %] | ||
"subtitle": "[% panel.packager_code_data.provincia_localidad %]", | ||
[% ELSIF panel.packager_code_data.cc == 'uk' %] | ||
"subtitle": "[% panel.packager_code_data.district %]", | ||
[% END %] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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… There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
"icon_url": "[% static_subdomain %]/images/icons/dist/transportation.svg", | ||
"icon_color_from_evaluation": true, | ||
}, | ||
"elements": [ | ||
{ | ||
"element_type": "map", | ||
"map_element": { | ||
"pointers": [ | ||
{ | ||
"geo": { | ||
"lat": [% panel.lat %], | ||
"lng": [% panel.lng %], | ||
} | ||
} | ||
] | ||
} | ||
}, | ||
] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.