Skip to content

Commit

Permalink
fix: indicate some attributes have only mandatory / not_important opt…
Browse files Browse the repository at this point in the history
…ions (#10846)

This changes the result of
http://wold.openfoodfacts.org/api/v2/attribute_groups to add a "values"
array to list the possible values for each attribute.

Fixes #9370

Most attributes have 4:

values: [
"not_important",
"important",
"very_important",
"mandatory"
]

Allergens + vegan and vegetarian have 2:

values: [
"not_important",
"mandatory"
]


Full file:

```
[
{
attributes: [
{
default: "very_important",
icon_url: "http://static.openfoodfacts.localhost/images/attributes/dist/nutriscore-a.svg",
id: "nutriscore",
name: "Nutri-Score",
panel_id: "nutriscore",
setting_name: "Good nutritional quality (Nutri-Score)",
setting_note: "The Nutri-Score is computed and can be taken into account for all products, even if is not displayed on the packaging.",
values: [
"not_important",
"important",
"very_important",
"mandatory"
]
},
{
icon_url: "http://static.openfoodfacts.localhost/images/attributes/dist/nutrient-level-salt-low.svg",
id: "low_salt",
name: "Salt",
setting_name: "Salt in low quantity",
setting_note: "The salt level is taken into account by the Nutri-Score. Use this setting only if you are specifically on a low salt diet.",
values: [
"not_important",
"important",
"very_important",
"mandatory"
]
},
{
icon_url: "http://static.openfoodfacts.localhost/images/attributes/dist/nutrient-level-sugars-low.svg",
id: "low_sugars",
name: "Sugars",
setting_name: "Sugars in low quantity",
setting_note: "The sugars level is taken into account by the Nutri-Score. Use this setting only if you are specifically on a low sugars diet.",
values: [
"not_important",
"important",
"very_important",
"mandatory"
]
},
{
icon_url: "http://static.openfoodfacts.localhost/images/attributes/dist/nutrient-level-fat-low.svg",
id: "low_fat",
name: "Fat",
setting_name: "Fat in low quantity",
setting_note: "The fat level is taken into account by the Nutri-Score. Use this setting only if you are specifically on a low fat diet.",
values: [
"not_important",
"important",
"very_important",
"mandatory"
]
},
{
icon_url: "http://static.openfoodfacts.localhost/images/attributes/dist/nutrient-level-saturated-fat-low.svg",
id: "low_saturated_fat",
name: "Saturated fat",
setting_name: "Saturated fat in low quantity",
setting_note: "The saturated fat level is taken into account by the Nutri-Score. Use this setting only if you are specifically on a low saturated fat diet.",
values: [
"not_important",
"important",
"very_important",
"mandatory"
]
}
],
id: "nutritional_quality",
name: "Nutritional quality"
},
{
attributes: [
{
default: "important",
icon_url: "http://static.openfoodfacts.localhost/images/attributes/dist/nova-group-1.svg",
id: "nova",
name: "NOVA group",
panel_id: "nova",
setting_name: "No or little food processing (NOVA group)",
values: [
"not_important",
"important",
"very_important",
"mandatory"
]
},
{
icon_url: "http://static.openfoodfacts.localhost/images/attributes/dist/0-additives.svg",
id: "additives",
name: "Additives",
panel_id: "additives",
setting_name: "No or few additives",
setting_note: "Additives are markers of food processing, and excess consumption of some of them have undesirable health impacts.",
values: [
"not_important",
"important",
"very_important",
"mandatory"
]
}
],
id: "processing",
name: "Food processing"
},
{
attributes: [
{
icon_url: "http://static.openfoodfacts.localhost/images/attributes/dist/no-gluten.svg",
id: "allergens_no_gluten",
name: "Gluten",
setting_name: "Without Gluten",
values: [
"not_important",
"mandatory"
]
},
{
icon_url: "http://static.openfoodfacts.localhost/images/attributes/dist/no-milk.svg",
id: "allergens_no_milk",
name: "Milk",
setting_name: "Without Milk",
values: [
"not_important",
"mandatory"
]
},
{
icon_url: "http://static.openfoodfacts.localhost/images/attributes/dist/no-eggs.svg",
id: "allergens_no_eggs",
name: "Eggs",
setting_name: "Without Eggs",
values: [
"not_important",
"mandatory"
]
},
{
icon_url: "http://static.openfoodfacts.localhost/images/attributes/dist/no-nuts.svg",
id: "allergens_no_nuts",
name: "Nuts",
setting_name: "Without Nuts",
values: [
"not_important",
"mandatory"
]
},
{
icon_url: "http://static.openfoodfacts.localhost/images/attributes/dist/no-peanuts.svg",
id: "allergens_no_peanuts",
name: "Peanuts",
setting_name: "Without Peanuts",
values: [
"not_important",
"mandatory"
]
},
{
icon_url: "http://static.openfoodfacts.localhost/images/attributes/dist/no-sesame-seeds.svg",
id: "allergens_no_sesame_seeds",
name: "Sesame seeds",
setting_name: "Without Sesame seeds",
values: [
"not_important",
"mandatory"
]
},
{
icon_url: "http://static.openfoodfacts.localhost/images/attributes/dist/no-soybeans.svg",
id: "allergens_no_soybeans",
name: "Soybeans",
setting_name: "Without Soybeans",
values: [
"not_important",
"mandatory"
]
},
{
icon_url: "http://static.openfoodfacts.localhost/images/attributes/dist/no-celery.svg",
id: "allergens_no_celery",
name: "Celery",
setting_name: "Without Celery",
values: [
"not_important",
"mandatory"
]
},
{
icon_url: "http://static.openfoodfacts.localhost/images/attributes/dist/no-mustard.svg",
id: "allergens_no_mustard",
name: "Mustard",
setting_name: "Without Mustard",
values: [
"not_important",
"mandatory"
]
},
{
icon_url: "http://static.openfoodfacts.localhost/images/attributes/dist/no-lupin.svg",
id: "allergens_no_lupin",
name: "Lupin",
setting_name: "Without Lupin",
values: [
"not_important",
"mandatory"
]
},
{
icon_url: "http://static.openfoodfacts.localhost/images/attributes/dist/no-fish.svg",
id: "allergens_no_fish",
name: "Fish",
setting_name: "Without Fish",
values: [
"not_important",
"mandatory"
]
},
{
icon_url: "http://static.openfoodfacts.localhost/images/attributes/dist/no-crustaceans.svg",
id: "allergens_no_crustaceans",
name: "Crustaceans",
setting_name: "Without Crustaceans",
values: [
"not_important",
"mandatory"
]
},
{
icon_url: "http://static.openfoodfacts.localhost/images/attributes/dist/no-molluscs.svg",
id: "allergens_no_molluscs",
name: "Molluscs",
setting_name: "Without Molluscs",
values: [
"not_important",
"mandatory"
]
},
{
icon_url: "http://static.openfoodfacts.localhost/images/attributes/dist/no-sulphur-dioxide-and-sulphites.svg",
id: "allergens_no_sulphur_dioxide_and_sulphites",
name: "Sulphur dioxide and sulphites",
setting_name: "Without Sulphur dioxide and sulphites",
values: [
"not_important",
"mandatory"
]
}
],
id: "allergens",
name: "Allergens",
warning: "There is always a possibility that data about allergens may be missing, incomplete, incorrect or that the product's composition has changed. If you are allergic, always check the information on the actual product packaging."
},
{
attributes: [
{
icon_url: "http://static.openfoodfacts.localhost/images/attributes/dist/vegan.svg",
id: "vegan",
name: "Vegan",
setting_name: "Vegan",
setting_note: "To determine whether a product is vegan, we only rely on the list of ingredients.",
values: [
"not_important",
"mandatory"
]
},
{
icon_url: "http://static.openfoodfacts.localhost/images/attributes/dist/vegetarian.svg",
id: "vegetarian",
name: "Vegetarian",
setting_name: "Vegetarian",
setting_note: "To determine whether a product is vegetarian, we only rely on the list of ingredients.",
values: [
"not_important",
"mandatory"
]
},
{
icon_url: "http://static.openfoodfacts.localhost/images/attributes/dist/palm-oil-free.svg",
id: "palm_oil_free",
name: "Palm oil free",
setting_name: "Palm oil free",
values: [
"not_important",
"important",
"very_important",
"mandatory"
]
}
],
id: "ingredients_analysis",
name: "Ingredients"
},
{
attributes: [
{
description: "Organic farming aims to protect the environment and to conserve biodiversity by prohibiting or limiting the use of synthetic fertilizers, pesticides and food additives.",
description_short: "Organic products promote ecological sustainability and biodiversity.",
icon_url: "http://static.openfoodfacts.localhost/images/attributes/dist/organic.svg",
id: "labels_organic",
name: "Organic farming",
setting_name: "Organic farming",
values: [
"not_important",
"important",
"very_important",
"mandatory"
]
},
{
description: "When you buy fair trade products, producers in developing countries are paid an higher and fairer price, which helps them improve and sustain higher social and often environmental standards.",
description_short: "Fair trade products help producers in developing countries.",
icon_url: "http://static.openfoodfacts.localhost/images/attributes/dist/fair-trade.svg",
id: "labels_fair_trade",
name: "Fair trade",
setting_name: "Fair trade",
values: [
"not_important",
"important",
"very_important",
"mandatory"
]
}
],
id: "labels",
name: "Labels"
},
{
attributes: [
{
default: "important",
icon_url: "http://static.openfoodfacts.localhost/images/attributes/dist/ecoscore-a.svg",
id: "ecoscore",
name: "Eco-Score",
panel_id: "ecoscore",
setting_name: "Low environmental impact (Eco-Score)",
setting_note: "The Eco-Score is an environmental score (ecoscore) from A to E which makes it easy to compare the impact of food products on the environment.",
values: [
"not_important",
"important",
"very_important",
"mandatory"
]
},
{
icon_url: "http://static.openfoodfacts.localhost/images/attributes/dist/forest-footprint-a.svg",
id: "forest_footprint",
name: "Forest footprint",
setting_name: "Low risk of deforestation (Forest footprint)",
setting_note: "The forest footprint corresponds to the risk of deforestation associated with its ingredients.",
values: [
"not_important",
"important",
"very_important",
"mandatory"
]
}
],
id: "environment",
name: "Environment"
}
]
```
  • Loading branch information
stephanegigandet authored Oct 2, 2024
1 parent e83c9dd commit 258dc8f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/ProductOpener/Attributes.pm
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ sub list_attributes ($target_lc) {
foreach my $attribute_id (@{$attributes_ref}) {

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

# Add the possible values for the attribute
$attribute_ref->{values}
= deep_get(\%options, "attribute_values", $attribute_id) || $options{attribute_values_default};

push @{$group_ref->{attributes}}, $attribute_ref;
}

Expand Down
23 changes: 23 additions & 0 deletions lib/ProductOpener/Config_off.pm
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,29 @@ $options{attribute_groups} = [
["environment", ["ecoscore", "forest_footprint",]],
];

# By default attributes have 4 possible values: not_important, important, very_important, mandatory
# For some attributes, like allergens or vegan, we can limit to 2 values: not_important, mandatory
$options{attribute_values_default} = ["not_important", "important", "very_important", "mandatory"];

$options{attribute_values} = {
"allergens_no_gluten" => ["not_important", "mandatory"],
"allergens_no_milk" => ["not_important", "mandatory"],
"allergens_no_eggs" => ["not_important", "mandatory"],
"allergens_no_nuts" => ["not_important", "mandatory"],
"allergens_no_peanuts" => ["not_important", "mandatory"],
"allergens_no_sesame_seeds" => ["not_important", "mandatory"],
"allergens_no_soybeans" => ["not_important", "mandatory"],
"allergens_no_celery" => ["not_important", "mandatory"],
"allergens_no_mustard" => ["not_important", "mandatory"],
"allergens_no_lupin" => ["not_important", "mandatory"],
"allergens_no_fish" => ["not_important", "mandatory"],
"allergens_no_crustaceans" => ["not_important", "mandatory"],
"allergens_no_molluscs" => ["not_important", "mandatory"],
"allergens_no_sulphur_dioxide_and_sulphites" => ["not_important", "mandatory"],
"vegan" => ["not_important", "mandatory"],
"vegetarian" => ["not_important", "mandatory"],
};

# default preferences for attributes
$options{attribute_default_preferences} = {
"nutriscore" => "very_important",
Expand Down

0 comments on commit 258dc8f

Please sign in to comment.