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: attribute for product without new nutriscore data #10915

Merged
merged 3 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions lib/ProductOpener/Attributes.pm
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ See https://wiki.openfoodfacts.org/Product_Attributes
If new attributes are added, make sure *to update the list of fields* fetched from MongoDB
in Display.pm (in search_and_display_products subroutine).


=cut

package ProductOpener::Attributes;
Expand Down Expand Up @@ -98,7 +97,7 @@ $options{attribute_groups} = [
# Build a hash of attribute groups to make it easier to retrieve all attributes of a specific group
my %attribute_groups = ();

# Build a hash of attributes to make it easier to retrieve all attributes
# Build a hash of attributes to make it easier to retrieve all attributes
my %attributes = ();

if (defined $options{attribute_groups}) {
Expand Down Expand Up @@ -472,11 +471,16 @@ sub compute_attribute_nutriscore ($product_ref, $target_lc, $target_cc) {

my $attribute_ref = initialize_attribute($attribute_id, $target_lc);

# Nutri-Score A, B, C, D or E
if ((defined $product_ref->{nutriscore_grade}) and ($product_ref->{nutriscore_grade} =~ /^[a-e]$/)) {
$attribute_ref->{status} = "known";
my $nutriscore_ref = deep_get($product_ref, "nutriscore", $version);

# Check that we have computed a Nutri-Score with the expected version
# and that the Nutri-Score is A, B, C, D or E

my $nutriscore_ref = $product_ref->{nutriscore}{$version};
if ( (defined $nutriscore_ref)
and (defined $product_ref->{nutriscore_grade})
and ($product_ref->{nutriscore_grade} =~ /^[a-e]$/))
{
$attribute_ref->{status} = "known";

my $is_beverage = $nutriscore_ref->{data}{is_beverage};
my $is_water = $nutriscore_ref->{data}{is_water};
Expand Down
1 change: 1 addition & 0 deletions stop_words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ lc
LCA
legumes
Lowercased
Malaceous
maltodextrine
malus
Expand Down
Loading