Skip to content

Commit

Permalink
fix: use prepared nutrition values to compute nutriscore of cocoa and…
Browse files Browse the repository at this point in the history
… chocolate powders (#6552)
  • Loading branch information
stephanegigandet authored Apr 5, 2022
1 parent 2fc8e67 commit fceefac
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/ProductOpener/Food.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1530,7 +1530,7 @@ sub compute_nutrition_score($) {
# unless we have nutrition data for the prepared product
# same for en:chocolate-powders, en:dessert-mixes and en:flavoured-syrups

foreach my $category_tag ("en:dried-products-to-be-rehydrated", "en:chocolate-powders", "en:dessert-mixes", "en:flavoured-syrups", "en:instant-beverages") {
foreach my $category_tag ("en:dried-products-to-be-rehydrated", "en:cocoa-and-chocolate-powders", "en:dessert-mixes", "en:flavoured-syrups", "en:instant-beverages") {

if (has_tag($product_ref, "categories", $category_tag)) {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
{
"categories" : "cocoa and chocolate powders",
"categories_hierarchy" : [
"en:cocoa-and-its-products",
"en:cocoa-and-chocolate-powders"
],
"categories_lc" : "en",
"categories_properties" : {
"agribalyse_proxy_food_code:en" : "18167"
},
"categories_properties_tags" : [
"all-products",
"categories-known",
"agribalyse-food-code-unknown",
"agribalyse-proxy-food-code-18167",
"agribalyse-proxy-food-code-known",
"ciqual-food-code-unknown",
"agribalyse-known",
"agribalyse-18167"
],
"categories_tags" : [
"en:cocoa-and-its-products",
"en:cocoa-and-chocolate-powders"
],
"food_groups_tags" : [],
"lc" : "en",
"misc_tags" : [
"en:nutrition-grade-computed-for-prepared-product",
"en:nutrition-no-fruits-vegetables-nuts",
"en:nutrition-no-fiber-or-fruits-vegetables-nuts",
"en:nutriscore-computed"
],
"nutriments" : {
"energy_prepared_100g" : 287,
"fat_prepared_100g" : 0,
"fiber_prepared_100g" : 1.9,
"nutrition-score-fr" : -1,
"nutrition-score-fr_100g" : -1,
"proteins_prepared_100g" : 3.8,
"saturated-fat_prepared_100g" : 1.1,
"sodium_prepared_100g" : 0.045,
"sugars_prepared_100g" : 6.3
},
"nutriscore_data" : {
"energy" : 287,
"energy_points" : 0,
"energy_value" : 287,
"fiber" : 1.9,
"fiber_points" : 1,
"fiber_value" : 1.9,
"fruits_vegetables_nuts_colza_walnut_olive_oils" : 0,
"fruits_vegetables_nuts_colza_walnut_olive_oils_points" : 0,
"fruits_vegetables_nuts_colza_walnut_olive_oils_value" : 0,
"grade" : "a",
"is_beverage" : 0,
"is_cheese" : 0,
"is_fat" : 0,
"is_water" : 0,
"negative_points" : 2,
"positive_points" : 3,
"proteins" : 3.8,
"proteins_points" : 2,
"proteins_value" : 3.8,
"saturated_fat" : 1.1,
"saturated_fat_points" : 1,
"saturated_fat_ratio" : 100,
"saturated_fat_ratio_points" : 10,
"saturated_fat_ratio_value" : 100,
"saturated_fat_value" : 1.1,
"score" : -1,
"sodium" : 45,
"sodium_points" : 0,
"sodium_value" : 45,
"sugars" : 6.3,
"sugars_points" : 1,
"sugars_value" : 6.3
},
"nutriscore_grade" : "a",
"nutriscore_score" : -1,
"nutriscore_score_opposite" : 1,
"nutrition_grade_fr" : "a",
"nutrition_grades" : "a",
"nutrition_grades_tags" : [
"a"
],
"nutrition_score_beverage" : 0,
"nutrition_score_debug" : "using prepared product data for category en:cocoa-and-chocolate-powders",
"nutrition_score_warning_no_fruits_vegetables_nuts" : 1,
"pnns_groups_1" : "unknown",
"pnns_groups_1_tags" : [
"unknown",
"missing-association"
],
"pnns_groups_2" : "unknown",
"pnns_groups_2_tags" : [
"unknown",
"missing-association"
]
}
2 changes: 2 additions & 0 deletions t/nutriscore.t
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ my @tests = (
["flavored-spring-water-no-nutrition", { lc=>"en", categories=>"flavoured spring water", nutriments=>{}}],
["flavored-spring-with-nutrition", { lc=>"en", categories=>"flavoured spring water", nutriments=>{energy_100g=>378, fat_100g=>0, "saturated-fat_100g"=>0, sugars_100g=>3, sodium_100g=>0, fiber_100g=>0, proteins_100g=>0}}],

# Cocoa and chocolate powders
["cocoa-and-chocolate-powders", { lc => "en", "categories" => "cocoa and chocolate powders", nutriments=>{energy_prepared_100g=>287, fat_prepared_100g=>0, "saturated-fat_prepared_100g"=>1.1, sugars_prepared_100g=>6.3, sodium_prepared_100g=>0.045, fiber_prepared_100g=>1.9, proteins_prepared_100g=>3.8}}],

);

Expand Down
5 changes: 5 additions & 0 deletions taxonomies/categories.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7505,6 +7505,7 @@ ciqual_food_code:en:18020
ciqual_food_name:en:Tea, brewed, without sugar
ciqual_food_name:fr:Thé infusé, non sucré

# Note: en:instant-beverages is a category that changes the computation of the Nutri-Score, the canonical name should not be changed without corresponding code changes
<en:Beverages
en:Instant beverages, Instant hot beverages
ca:Begudes instantànies
Expand Down Expand Up @@ -8711,6 +8712,7 @@ de:Mischgetränk, Mix-Getränk
nl:Gemengde dranken
wikidata:en:Q3246609

# Note: en:flavoured-syrups is a category that changes the computation of the Nutri-Score, the canonical name should not be changed without corresponding code changes
<en:Beverages
<en:Syrups
en:Flavoured syrups
Expand Down Expand Up @@ -30438,6 +30440,7 @@ pt:Produtos secos, produtos desidratados, Alimentos secos, Alimentos desidratado
ru:Обезвоженные продукты
th:อาหารแห้ง

# Note: en:dried-products-to-be-rehydrated is a category that changes the computation of the Nutri-Score, the canonical name should not be changed without corresponding code changes
<en:Dried products
en:Dried products to be rehydrated
ca:Productes assecats per a ser rehidratats
Expand Down Expand Up @@ -33144,6 +33147,7 @@ nl:Rauwe cacaobonen
fr:Grué de cacao
wikidata:en:Q3118262

# Note: en:cocoa-and-chocolate-powders is a category that changes the computation of the Nutri-Score, the canonical name should not be changed without corresponding code changes
<en:Cocoa and its products
en:Cocoa and chocolate powders, chocolate and cocoa powders
ca:Pols de coco i xocolata
Expand Down Expand Up @@ -33335,6 +33339,7 @@ ciqual_food_name:fr:Gâteau (aliment moyen)
# category/cakes has 6408 products @2019-05-20
# ingredient/fr:gâteau has 59 products in french @2019-02-06

# Note: en:dessert-mixes is a category that changes the computation of the Nutri-Score, the canonical name should not be changed without corresponding code changes
<en:Cooking helpers
en:Dessert mixes, Dessert mix
de:Nachtischmischungen, Nachtischmischung
Expand Down

0 comments on commit fceefac

Please sign in to comment.