From ab743569eb457b2b8d34821543a74b88ab60824e Mon Sep 17 00:00:00 2001 From: John Gomersall Date: Mon, 22 Jan 2024 11:47:37 +0000 Subject: [PATCH 1/8] Proposed documentation --- docs/api/ref/schemas/knowledge_panels/panel.yaml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/api/ref/schemas/knowledge_panels/panel.yaml b/docs/api/ref/schemas/knowledge_panels/panel.yaml index 8af6380cc86fe..b54440e4ad862 100644 --- a/docs/api/ref/schemas/knowledge_panels/panel.yaml +++ b/docs/api/ref/schemas/knowledge_panels/panel.yaml @@ -13,6 +13,20 @@ properties: expand_for: type: string description: 'If set to "large", the content of the panel should be expanded on large screens, but it should still be possible to unexpand it.' + name: + type: string + description: A short name of this panel, not including any actual values + value: + type: string + description: A simple summary value for the panel, e.g. a percentage, grade, number of, etc. + evaluation: + type: string + description: A simple assessment of the panel value, typically used to format fonts, et.c e.g. bad = red + enum: + - good + - average + - bad + - unknown title_element: $ref: ./elements/title_element.yaml elements: From 8c9e4e710754d0f4a1ecedd6cff104d055727275 Mon Sep 17 00:00:00 2001 From: John Gomersall Date: Mon, 22 Jan 2024 12:48:57 +0000 Subject: [PATCH 2/8] Implement evaluation for Nutrient Levels --- lib/ProductOpener/Display.pm | 3 +++ lib/ProductOpener/Food.pm | 12 ++++++++++++ .../health/nutrition/nutrient_level.tt.json | 2 ++ .../data_quality_knowledge_panel/data-quality.json | 6 ++++-- 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/ProductOpener/Display.pm b/lib/ProductOpener/Display.pm index 5e2c3df127bb0..1c340b56ab4d4 100644 --- a/lib/ProductOpener/Display.pm +++ b/lib/ProductOpener/Display.pm @@ -9048,6 +9048,9 @@ sub data_to_display_nutrient_levels ($product_ref) { push @{$result_data_ref->{nutrient_levels}}, { nid => $nid, nutrient_level => $product_ref->{nutrient_levels}{$nid}, + evaluation => evaluate_nutrient_level($nid, $product_ref->{nutrient_levels}{$nid}), + nutrient_name => display_taxonomy_tag($lc, "nutrients", "zz:$nid"), + # TODO: Percentage should be formatted according to region nutrient_quantity_in_grams => sprintf("%.2e", $product_ref->{nutriments}{$nid . $prepared . "_100g"}) + 0.0, nutrient_in_quantity => sprintf( diff --git a/lib/ProductOpener/Food.pm b/lib/ProductOpener/Food.pm index f7e526be62c49..f0a9c09424bc8 100644 --- a/lib/ProductOpener/Food.pm +++ b/lib/ProductOpener/Food.pm @@ -72,6 +72,7 @@ BEGIN { &compute_serving_size_data &compute_unknown_nutrients &compute_nutrient_levels + &evaluate_nutrient_level &compute_units_of_alcohol &compute_estimated_nutrients @@ -2424,6 +2425,17 @@ sub compute_nutrient_levels ($product_ref) { return; } +my %nutrient_level_evaluation_table = ( + low => "good", + moderate => "average", + high => "bad", +); + +sub evaluate_nutrient_level ($nid, $nutrient_level) { + # Will need different tables if we add nutrients that are good for you + return $nutrient_level_evaluation_table{$nutrient_level} // 'unknown'; +} + =head2 create_nutrients_level_taxonomy () C creates the source file for the nutrients level diff --git a/templates/api/knowledge-panels/health/nutrition/nutrient_level.tt.json b/templates/api/knowledge-panels/health/nutrition/nutrient_level.tt.json index 9d5407e556e94..5e7c7fb07731a 100644 --- a/templates/api/knowledge-panels/health/nutrition/nutrient_level.tt.json +++ b/templates/api/knowledge-panels/health/nutrition/nutrient_level.tt.json @@ -4,6 +4,8 @@ "health" ], "size": "small", + "name": "[% panel.nutrient_name %]", + "value": "[% panel.nutrient_quantity_in_grams %]%", "evaluation": "[% panel.evaluation %]", "title_element": { "title": "[% panel.nutrient_in_quantity %] ([% panel.nutrient_quantity_in_grams %]%)", diff --git a/tests/integration/expected_test_results/data_quality_knowledge_panel/data-quality.json b/tests/integration/expected_test_results/data_quality_knowledge_panel/data-quality.json index 48ed01d496c89..a5ae773a7027f 100644 --- a/tests/integration/expected_test_results/data_quality_knowledge_panel/data-quality.json +++ b/tests/integration/expected_test_results/data_quality_knowledge_panel/data-quality.json @@ -564,8 +564,9 @@ } } ], - "evaluation" : "", + "evaluation" : "bad", "level" : "info", + "name" : "Salt", "size" : "small", "title_element" : { "icon_size" : "small", @@ -574,7 +575,8 @@ }, "topics" : [ "health" - ] + ], + "value" : "120%" }, "nutriscore" : { "elements" : [ From cb28796e3401e93ad8d3a8fc0e52db025ce1b761 Mon Sep 17 00:00:00 2001 From: John Gomersall Date: Mon, 22 Jan 2024 13:07:51 +0000 Subject: [PATCH 3/8] Re-positioning values from PR comments --- .../schemas/knowledge_panels/elements/title_element.yaml | 6 ++++++ docs/api/ref/schemas/knowledge_panels/panel.yaml | 6 ------ .../health/nutrition/nutrient_level.tt.json | 4 ++-- .../data_quality_knowledge_panel/data-quality.json | 6 +++--- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/docs/api/ref/schemas/knowledge_panels/elements/title_element.yaml b/docs/api/ref/schemas/knowledge_panels/elements/title_element.yaml index 03972e2d67ca0..0f2fa00bb25a5 100644 --- a/docs/api/ref/schemas/knowledge_panels/elements/title_element.yaml +++ b/docs/api/ref/schemas/knowledge_panels/elements/title_element.yaml @@ -4,6 +4,12 @@ x-stoplight: type: object description: The title of a panel. properties: + name: + type: string + description: A short name of this panel, not including any actual values + value: + type: string + description: A simple summary value for the panel, e.g. a percentage, grade, number of, etc. title: type: string grade: diff --git a/docs/api/ref/schemas/knowledge_panels/panel.yaml b/docs/api/ref/schemas/knowledge_panels/panel.yaml index b54440e4ad862..b2542ce6f2f31 100644 --- a/docs/api/ref/schemas/knowledge_panels/panel.yaml +++ b/docs/api/ref/schemas/knowledge_panels/panel.yaml @@ -13,12 +13,6 @@ properties: expand_for: type: string description: 'If set to "large", the content of the panel should be expanded on large screens, but it should still be possible to unexpand it.' - name: - type: string - description: A short name of this panel, not including any actual values - value: - type: string - description: A simple summary value for the panel, e.g. a percentage, grade, number of, etc. evaluation: type: string description: A simple assessment of the panel value, typically used to format fonts, et.c e.g. bad = red diff --git a/templates/api/knowledge-panels/health/nutrition/nutrient_level.tt.json b/templates/api/knowledge-panels/health/nutrition/nutrient_level.tt.json index 5e7c7fb07731a..f889661a9a415 100644 --- a/templates/api/knowledge-panels/health/nutrition/nutrient_level.tt.json +++ b/templates/api/knowledge-panels/health/nutrition/nutrient_level.tt.json @@ -4,10 +4,10 @@ "health" ], "size": "small", - "name": "[% panel.nutrient_name %]", - "value": "[% panel.nutrient_quantity_in_grams %]%", "evaluation": "[% panel.evaluation %]", "title_element": { + "name": "[% panel.nutrient_name %]", + "value": "[% panel.nutrient_quantity_in_grams %]%", "title": "[% panel.nutrient_in_quantity %] ([% panel.nutrient_quantity_in_grams %]%)", "icon_url": "[% static_subdomain %]/images/misc/[% panel.nutrient_level %].svg", "icon_size": "small", diff --git a/tests/integration/expected_test_results/data_quality_knowledge_panel/data-quality.json b/tests/integration/expected_test_results/data_quality_knowledge_panel/data-quality.json index a5ae773a7027f..edbef883803dc 100644 --- a/tests/integration/expected_test_results/data_quality_knowledge_panel/data-quality.json +++ b/tests/integration/expected_test_results/data_quality_knowledge_panel/data-quality.json @@ -566,17 +566,17 @@ ], "evaluation" : "bad", "level" : "info", - "name" : "Salt", "size" : "small", "title_element" : { + "name" : "Salt", + "value" : "120%", "icon_size" : "small", "icon_url" : "http://static.openfoodfacts.localhost/images/misc/high.svg", "title" : "Salt in high quantity (120%)" }, "topics" : [ "health" - ], - "value" : "120%" + ] }, "nutriscore" : { "elements" : [ From a9b0d83404d8b0900e46504801be45377cdbb1dd Mon Sep 17 00:00:00 2001 From: John Gomersall Date: Mon, 22 Jan 2024 13:23:51 +0000 Subject: [PATCH 4/8] Introduce percentage enumeration on type so that value can be supplied as a number --- .../elements/title_element.yaml | 18 ++++++++++-------- lib/ProductOpener/Display.pm | 1 - .../health/nutrition/nutrient_level.tt.json | 3 ++- .../data-quality.json | 3 ++- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/docs/api/ref/schemas/knowledge_panels/elements/title_element.yaml b/docs/api/ref/schemas/knowledge_panels/elements/title_element.yaml index 0f2fa00bb25a5..86f4fa1a40bf0 100644 --- a/docs/api/ref/schemas/knowledge_panels/elements/title_element.yaml +++ b/docs/api/ref/schemas/knowledge_panels/elements/title_element.yaml @@ -7,14 +7,17 @@ properties: name: type: string description: A short name of this panel, not including any actual values - value: - type: string - description: A simple summary value for the panel, e.g. a percentage, grade, number of, etc. title: type: string + type: + type: string + enum: + - grade + - percentage + description: 'Used to indicate how the value of this item is measured, such as "grade" for Nutri-Score and Eco-Score or "percentage" for Salt' grade: type: string - description: Indicates that the panel corresponds to a A to E grade such as the Nutri-Score of the Eco-Score. + description: The value for this panel where it corresponds to a A to E grade such as the Nutri-Score of the Eco-Score. enum: - a - b @@ -22,6 +25,9 @@ properties: - d - e - unknown + value: + type: number + description: 'The numeric value of the panel, where the type is "percentage"' icon_url: type: string icon_color_from_evaluation: @@ -30,7 +36,3 @@ properties: type: string description: | If set to "small", the icon should be displayed at a small size. - type: - type: string - example: grade - description: 'Used to indicate a special type for the title, such as "grade" for Nutri-Score and Eco-Score.' diff --git a/lib/ProductOpener/Display.pm b/lib/ProductOpener/Display.pm index 1c340b56ab4d4..a54c9ee86177d 100644 --- a/lib/ProductOpener/Display.pm +++ b/lib/ProductOpener/Display.pm @@ -9050,7 +9050,6 @@ sub data_to_display_nutrient_levels ($product_ref) { nutrient_level => $product_ref->{nutrient_levels}{$nid}, evaluation => evaluate_nutrient_level($nid, $product_ref->{nutrient_levels}{$nid}), nutrient_name => display_taxonomy_tag($lc, "nutrients", "zz:$nid"), - # TODO: Percentage should be formatted according to region nutrient_quantity_in_grams => sprintf("%.2e", $product_ref->{nutriments}{$nid . $prepared . "_100g"}) + 0.0, nutrient_in_quantity => sprintf( diff --git a/templates/api/knowledge-panels/health/nutrition/nutrient_level.tt.json b/templates/api/knowledge-panels/health/nutrition/nutrient_level.tt.json index f889661a9a415..dc1d3517cfb0b 100644 --- a/templates/api/knowledge-panels/health/nutrition/nutrient_level.tt.json +++ b/templates/api/knowledge-panels/health/nutrition/nutrient_level.tt.json @@ -7,7 +7,8 @@ "evaluation": "[% panel.evaluation %]", "title_element": { "name": "[% panel.nutrient_name %]", - "value": "[% panel.nutrient_quantity_in_grams %]%", + "type": "percentage", + "value": [% panel.nutrient_quantity_in_grams %], "title": "[% panel.nutrient_in_quantity %] ([% panel.nutrient_quantity_in_grams %]%)", "icon_url": "[% static_subdomain %]/images/misc/[% panel.nutrient_level %].svg", "icon_size": "small", diff --git a/tests/integration/expected_test_results/data_quality_knowledge_panel/data-quality.json b/tests/integration/expected_test_results/data_quality_knowledge_panel/data-quality.json index edbef883803dc..e5f213153feb8 100644 --- a/tests/integration/expected_test_results/data_quality_knowledge_panel/data-quality.json +++ b/tests/integration/expected_test_results/data_quality_knowledge_panel/data-quality.json @@ -569,7 +569,8 @@ "size" : "small", "title_element" : { "name" : "Salt", - "value" : "120%", + "type" : "percentage", + "value" : 120, "icon_size" : "small", "icon_url" : "http://static.openfoodfacts.localhost/images/misc/high.svg", "title" : "Salt in high quantity (120%)" From e6bd0a3c53a04eabf83d82e0013579f9f6c35acd Mon Sep 17 00:00:00 2001 From: John Gomersall Date: Mon, 22 Jan 2024 14:25:07 +0000 Subject: [PATCH 5/8] Add name for nutriscore and ecoscore --- lib/ProductOpener/KnowledgePanels.pm | 2 ++ .../environment/ecoscore/ecoscore.tt.json | 3 ++- .../health/nutriscore/nutriscore.tt.json | 1 + .../get-fields-all-knowledge-panels.json | 2 ++ ...get-fields-attribute-groups-all-knowledge-panels.json | 2 ++ .../api_v2_product_read/get-knowledge-panels-fr.json | 2 ++ .../api_v2_product_read/get-knowledge-panels.json | 2 ++ .../get-fields-all-knowledge-panels.json | 2 ++ ...get-fields-attribute-groups-all-knowledge-panels.json | 2 ++ .../api_v3_product_read/get-knowledge-panels-fr.json | 2 ++ .../api_v3_product_read/get-knowledge-panels.json | 2 ++ ...fields-updated-attribute-groups-knowledge-panels.json | 1 + .../data_quality_knowledge_panel/data-quality.json | 9 +++++---- .../data_quality_knowledge_panel/no-data-quality.json | 1 + 14 files changed, 28 insertions(+), 5 deletions(-) diff --git a/lib/ProductOpener/KnowledgePanels.pm b/lib/ProductOpener/KnowledgePanels.pm index a17354ab553b1..ec850a2170ec4 100644 --- a/lib/ProductOpener/KnowledgePanels.pm +++ b/lib/ProductOpener/KnowledgePanels.pm @@ -544,6 +544,7 @@ sub create_ecoscore_panel ($product_ref, $target_lc, $target_cc, $options_ref) { "agribalyse_category_name" => $agribalyse_category_name, "agribalyse_score" => $agribalyse_score, "agribalyse_grade" => $agribalyse_grade, + "name" => lang_in_other_lc($target_lc, "attribute_ecoscore_name"), "score" => $score, "grade" => $grade, "title" => $title, @@ -875,6 +876,7 @@ sub create_nutriscore_panel ($product_ref, $target_lc, $target_cc, $options_ref) $panel_data_ref->{title} = lang_in_other_lc($target_lc, "attribute_nutriscore_" . $panel_data_ref->{nutriscore_grade} . "_description_short"); } + $panel_data_ref->{name} = lang_in_other_lc($target_lc, "attribute_nutriscore_name"); # Nutri-Score panel: score + details create_panel_from_json_template("nutriscore", "api/knowledge-panels/health/nutriscore/nutriscore.tt.json", diff --git a/templates/api/knowledge-panels/environment/ecoscore/ecoscore.tt.json b/templates/api/knowledge-panels/environment/ecoscore/ecoscore.tt.json index eba0a4d51523e..90c12b96f9fa9 100644 --- a/templates/api/knowledge-panels/environment/ecoscore/ecoscore.tt.json +++ b/templates/api/knowledge-panels/environment/ecoscore/ecoscore.tt.json @@ -4,10 +4,11 @@ "environment" ], "title_element": { + "name": "[% panel.name %]", "icon_url": "[% static_subdomain %]/images/attributes/dist/ecoscore-[% panel.grade %].svg", "title": "[% panel.title %]", "type": "grade", - "grade": "[% panel.grade %]", + "grade": "[% panel.grade %]" }, "elements": [ [% IF panel.transportation_warning.defined %] diff --git a/templates/api/knowledge-panels/health/nutriscore/nutriscore.tt.json b/templates/api/knowledge-panels/health/nutriscore/nutriscore.tt.json index 054d0e0564e73..d648cdfa7f1af 100644 --- a/templates/api/knowledge-panels/health/nutriscore/nutriscore.tt.json +++ b/templates/api/knowledge-panels/health/nutriscore/nutriscore.tt.json @@ -8,6 +8,7 @@ [% IF panel.nutriscore_unknown_reason_short %] "subtitle": "[% panel.nutriscore_unknown_reason_short %]", [% END %] + "name": "[% panel.name %]", "title": "[% panel.title %]", "type": "grade", "grade": "[% panel.nutriscore_grade %]", diff --git a/tests/integration/expected_test_results/api_v2_product_read/get-fields-all-knowledge-panels.json b/tests/integration/expected_test_results/api_v2_product_read/get-fields-all-knowledge-panels.json index 3b0605189da34..9037d3cd88426 100644 --- a/tests/integration/expected_test_results/api_v2_product_read/get-fields-all-knowledge-panels.json +++ b/tests/integration/expected_test_results/api_v2_product_read/get-fields-all-knowledge-panels.json @@ -876,6 +876,7 @@ "title_element" : { "grade" : "c", "icon_url" : "http://static.openfoodfacts.localhost/images/attributes/dist/ecoscore-c.svg", + "name" : "Eco-Score", "title" : "Eco-Score C - Moderate environmental impact", "type" : "grade" }, @@ -1545,6 +1546,7 @@ "title_element" : { "grade" : "c", "icon_url" : "http://static.openfoodfacts.localhost/images/attributes/dist/nutriscore-c.svg", + "name" : "Nutri-Score", "title" : "Average nutritional quality", "type" : "grade" }, diff --git a/tests/integration/expected_test_results/api_v2_product_read/get-fields-attribute-groups-all-knowledge-panels.json b/tests/integration/expected_test_results/api_v2_product_read/get-fields-attribute-groups-all-knowledge-panels.json index acfcfc26dfce0..cf3d30a756fd4 100644 --- a/tests/integration/expected_test_results/api_v2_product_read/get-fields-attribute-groups-all-knowledge-panels.json +++ b/tests/integration/expected_test_results/api_v2_product_read/get-fields-attribute-groups-all-knowledge-panels.json @@ -1524,6 +1524,7 @@ "title_element" : { "grade" : "c", "icon_url" : "http://static.openfoodfacts.localhost/images/attributes/dist/ecoscore-c.svg", + "name" : "Eco-Score", "title" : "Eco-Score C - Moderate environmental impact", "type" : "grade" }, @@ -2193,6 +2194,7 @@ "title_element" : { "grade" : "c", "icon_url" : "http://static.openfoodfacts.localhost/images/attributes/dist/nutriscore-c.svg", + "name" : "Nutri-Score", "title" : "Average nutritional quality", "type" : "grade" }, diff --git a/tests/integration/expected_test_results/api_v2_product_read/get-knowledge-panels-fr.json b/tests/integration/expected_test_results/api_v2_product_read/get-knowledge-panels-fr.json index 18a1de0db0d76..4256e092fd8eb 100644 --- a/tests/integration/expected_test_results/api_v2_product_read/get-knowledge-panels-fr.json +++ b/tests/integration/expected_test_results/api_v2_product_read/get-knowledge-panels-fr.json @@ -185,6 +185,7 @@ "title_element" : { "grade" : "c", "icon_url" : "http://static.openfoodfacts.localhost/images/attributes/dist/ecoscore-c.svg", + "name" : "Eco-Score", "title" : "Eco-Score C - Impact modéré sur l'environnement", "type" : "grade" }, @@ -854,6 +855,7 @@ "title_element" : { "grade" : "c", "icon_url" : "http://static.openfoodfacts.localhost/images/attributes/dist/nutriscore-c.svg", + "name" : "Nutri-Score", "title" : "Qualité nutritionnelle moyenne", "type" : "grade" }, diff --git a/tests/integration/expected_test_results/api_v2_product_read/get-knowledge-panels.json b/tests/integration/expected_test_results/api_v2_product_read/get-knowledge-panels.json index 22e474d88c3a5..cd45676e9837d 100644 --- a/tests/integration/expected_test_results/api_v2_product_read/get-knowledge-panels.json +++ b/tests/integration/expected_test_results/api_v2_product_read/get-knowledge-panels.json @@ -185,6 +185,7 @@ "title_element" : { "grade" : "c", "icon_url" : "http://static.openfoodfacts.localhost/images/attributes/dist/ecoscore-c.svg", + "name" : "Eco-Score", "title" : "Eco-Score C - Moderate environmental impact", "type" : "grade" }, @@ -854,6 +855,7 @@ "title_element" : { "grade" : "c", "icon_url" : "http://static.openfoodfacts.localhost/images/attributes/dist/nutriscore-c.svg", + "name" : "Nutri-Score", "title" : "Average nutritional quality", "type" : "grade" }, diff --git a/tests/integration/expected_test_results/api_v3_product_read/get-fields-all-knowledge-panels.json b/tests/integration/expected_test_results/api_v3_product_read/get-fields-all-knowledge-panels.json index 437845525bd78..3bbcc51668ad8 100644 --- a/tests/integration/expected_test_results/api_v3_product_read/get-fields-all-knowledge-panels.json +++ b/tests/integration/expected_test_results/api_v3_product_read/get-fields-all-knowledge-panels.json @@ -878,6 +878,7 @@ "title_element" : { "grade" : "c", "icon_url" : "http://static.openfoodfacts.localhost/images/attributes/dist/ecoscore-c.svg", + "name" : "Eco-Score", "title" : "Eco-Score C - Moderate environmental impact", "type" : "grade" }, @@ -1547,6 +1548,7 @@ "title_element" : { "grade" : "c", "icon_url" : "http://static.openfoodfacts.localhost/images/attributes/dist/nutriscore-c.svg", + "name" : "Nutri-Score", "title" : "Average nutritional quality", "type" : "grade" }, diff --git a/tests/integration/expected_test_results/api_v3_product_read/get-fields-attribute-groups-all-knowledge-panels.json b/tests/integration/expected_test_results/api_v3_product_read/get-fields-attribute-groups-all-knowledge-panels.json index 394887f26ce12..cf22b66fefffe 100644 --- a/tests/integration/expected_test_results/api_v3_product_read/get-fields-attribute-groups-all-knowledge-panels.json +++ b/tests/integration/expected_test_results/api_v3_product_read/get-fields-attribute-groups-all-knowledge-panels.json @@ -1526,6 +1526,7 @@ "title_element" : { "grade" : "c", "icon_url" : "http://static.openfoodfacts.localhost/images/attributes/dist/ecoscore-c.svg", + "name" : "Eco-Score", "title" : "Eco-Score C - Moderate environmental impact", "type" : "grade" }, @@ -2195,6 +2196,7 @@ "title_element" : { "grade" : "c", "icon_url" : "http://static.openfoodfacts.localhost/images/attributes/dist/nutriscore-c.svg", + "name" : "Nutri-Score", "title" : "Average nutritional quality", "type" : "grade" }, diff --git a/tests/integration/expected_test_results/api_v3_product_read/get-knowledge-panels-fr.json b/tests/integration/expected_test_results/api_v3_product_read/get-knowledge-panels-fr.json index 565595c5ccb78..162bf66377e97 100644 --- a/tests/integration/expected_test_results/api_v3_product_read/get-knowledge-panels-fr.json +++ b/tests/integration/expected_test_results/api_v3_product_read/get-knowledge-panels-fr.json @@ -186,6 +186,7 @@ "title_element" : { "grade" : "c", "icon_url" : "http://static.openfoodfacts.localhost/images/attributes/dist/ecoscore-c.svg", + "name" : "Eco-Score", "title" : "Eco-Score C - Impact modéré sur l'environnement", "type" : "grade" }, @@ -855,6 +856,7 @@ "title_element" : { "grade" : "c", "icon_url" : "http://static.openfoodfacts.localhost/images/attributes/dist/nutriscore-c.svg", + "name" : "Nutri-Score", "title" : "Qualité nutritionnelle moyenne", "type" : "grade" }, diff --git a/tests/integration/expected_test_results/api_v3_product_read/get-knowledge-panels.json b/tests/integration/expected_test_results/api_v3_product_read/get-knowledge-panels.json index e37d18c3855fe..449213f35b470 100644 --- a/tests/integration/expected_test_results/api_v3_product_read/get-knowledge-panels.json +++ b/tests/integration/expected_test_results/api_v3_product_read/get-knowledge-panels.json @@ -186,6 +186,7 @@ "title_element" : { "grade" : "c", "icon_url" : "http://static.openfoodfacts.localhost/images/attributes/dist/ecoscore-c.svg", + "name" : "Eco-Score", "title" : "Eco-Score C - Moderate environmental impact", "type" : "grade" }, @@ -855,6 +856,7 @@ "title_element" : { "grade" : "c", "icon_url" : "http://static.openfoodfacts.localhost/images/attributes/dist/nutriscore-c.svg", + "name" : "Nutri-Score", "title" : "Average nutritional quality", "type" : "grade" }, diff --git a/tests/integration/expected_test_results/api_v3_product_write/patch-request-fields-updated-attribute-groups-knowledge-panels.json b/tests/integration/expected_test_results/api_v3_product_write/patch-request-fields-updated-attribute-groups-knowledge-panels.json index e989ed12d88b3..92ac518c369b7 100644 --- a/tests/integration/expected_test_results/api_v3_product_write/patch-request-fields-updated-attribute-groups-knowledge-panels.json +++ b/tests/integration/expected_test_results/api_v3_product_write/patch-request-fields-updated-attribute-groups-knowledge-panels.json @@ -545,6 +545,7 @@ "title_element" : { "grade" : "unknown", "icon_url" : "http://static.openfoodfacts.localhost/images/attributes/dist/nutriscore-unknown.svg", + "name" : "Nutri-Score", "subtitle" : "Missing category and nutrition facts", "title" : "Missing data to compute the Nutri-Score", "type" : "grade" diff --git a/tests/integration/expected_test_results/data_quality_knowledge_panel/data-quality.json b/tests/integration/expected_test_results/data_quality_knowledge_panel/data-quality.json index e5f213153feb8..eeb4c26dff9e3 100644 --- a/tests/integration/expected_test_results/data_quality_knowledge_panel/data-quality.json +++ b/tests/integration/expected_test_results/data_quality_knowledge_panel/data-quality.json @@ -568,12 +568,12 @@ "level" : "info", "size" : "small", "title_element" : { - "name" : "Salt", - "type" : "percentage", - "value" : 120, "icon_size" : "small", "icon_url" : "http://static.openfoodfacts.localhost/images/misc/high.svg", - "title" : "Salt in high quantity (120%)" + "name" : "Salt", + "title" : "Salt in high quantity (120%)", + "type" : "percentage", + "value" : 120 }, "topics" : [ "health" @@ -614,6 +614,7 @@ "title_element" : { "grade" : "unknown", "icon_url" : "http://static.openfoodfacts.localhost/images/attributes/dist/nutriscore-unknown.svg", + "name" : "Nutri-Score", "subtitle" : "Missing nutrition facts", "title" : "Missing data to compute the Nutri-Score", "type" : "grade" diff --git a/tests/integration/expected_test_results/data_quality_knowledge_panel/no-data-quality.json b/tests/integration/expected_test_results/data_quality_knowledge_panel/no-data-quality.json index 0de636c5d4dc5..39867f045a4bd 100644 --- a/tests/integration/expected_test_results/data_quality_knowledge_panel/no-data-quality.json +++ b/tests/integration/expected_test_results/data_quality_knowledge_panel/no-data-quality.json @@ -531,6 +531,7 @@ "title_element" : { "grade" : "unknown", "icon_url" : "http://static.openfoodfacts.localhost/images/attributes/dist/nutriscore-unknown.svg", + "name" : "Nutri-Score", "subtitle" : "Missing nutrition facts", "title" : "Missing data to compute the Nutri-Score", "type" : "grade" From 78eb10eb337f7d8f35369d6f3157f8ddd2eec588 Mon Sep 17 00:00:00 2001 From: John Gomersall Date: Mon, 22 Jan 2024 15:10:53 +0000 Subject: [PATCH 6/8] Added neutral evaluation --- docs/api/ref/schemas/knowledge_panels/panel.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/api/ref/schemas/knowledge_panels/panel.yaml b/docs/api/ref/schemas/knowledge_panels/panel.yaml index b2542ce6f2f31..5c3e47082e019 100644 --- a/docs/api/ref/schemas/knowledge_panels/panel.yaml +++ b/docs/api/ref/schemas/knowledge_panels/panel.yaml @@ -19,6 +19,7 @@ properties: enum: - good - average + - neutral - bad - unknown title_element: From c90d70408b71d76a89fb30139274318f137e84bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Gigandet?= Date: Thu, 26 Sep 2024 17:14:50 +0200 Subject: [PATCH 7/8] add "half_width_on_mobile": true --- .../api/knowledge-panels/health/nutrition/nutrient_level.tt.json | 1 + 1 file changed, 1 insertion(+) diff --git a/templates/api/knowledge-panels/health/nutrition/nutrient_level.tt.json b/templates/api/knowledge-panels/health/nutrition/nutrient_level.tt.json index dc1d3517cfb0b..c81f3ea356abf 100644 --- a/templates/api/knowledge-panels/health/nutrition/nutrient_level.tt.json +++ b/templates/api/knowledge-panels/health/nutrition/nutrient_level.tt.json @@ -4,6 +4,7 @@ "health" ], "size": "small", + "half_width_on_mobile": true, "evaluation": "[% panel.evaluation %]", "title_element": { "name": "[% panel.nutrient_name %]", From 4a296683bd5c1b1ecce139293dea3a1e278c5869 Mon Sep 17 00:00:00 2001 From: Open Food Facts Bot Date: Fri, 27 Sep 2024 15:47:42 +0000 Subject: [PATCH 8/8] test: Update tests results --- .../get-fields-all-knowledge-panels.json | 32 ++++++++++++++----- ...attribute-groups-all-knowledge-panels.json | 32 ++++++++++++++----- ...edge-panels_excluded-environment_card.json | 32 ++++++++++++++----- ...included-health_card-environment_card.json | 32 ++++++++++++++----- .../get-knowledge-panels-fr.json | 32 ++++++++++++++----- .../get-knowledge-panels.json | 32 ++++++++++++++----- 6 files changed, 144 insertions(+), 48 deletions(-) diff --git a/tests/integration/expected_test_results/api_v2_product_read/get-fields-all-knowledge-panels.json b/tests/integration/expected_test_results/api_v2_product_read/get-fields-all-knowledge-panels.json index bc1f408f88724..e6cbf11c6d423 100644 --- a/tests/integration/expected_test_results/api_v2_product_read/get-fields-all-knowledge-panels.json +++ b/tests/integration/expected_test_results/api_v2_product_read/get-fields-all-knowledge-panels.json @@ -1572,13 +1572,17 @@ } } ], - "evaluation" : "", + "evaluation" : "average", + "half_width_on_mobile" : true, "level" : "info", "size" : "small", "title_element" : { "icon_size" : "small", "icon_url" : "http://static.openfoodfacts.localhost/images/misc/moderate.svg", - "title" : "Fat in moderate quantity (8.5%)" + "name" : "Fat", + "title" : "Fat in moderate quantity (8.5%)", + "type" : "percentage", + "value" : 8.5 }, "topics" : [ "health" @@ -1614,13 +1618,17 @@ } } ], - "evaluation" : "", + "evaluation" : "good", + "half_width_on_mobile" : true, "level" : "info", "size" : "small", "title_element" : { "icon_size" : "small", "icon_url" : "http://static.openfoodfacts.localhost/images/misc/low.svg", - "title" : "Salt in low quantity (0.0502%)" + "name" : "Salt", + "title" : "Salt in low quantity (0.0502%)", + "type" : "percentage", + "value" : 0.0502 }, "topics" : [ "health" @@ -1646,13 +1654,17 @@ } } ], - "evaluation" : "", + "evaluation" : "bad", + "half_width_on_mobile" : true, "level" : "info", "size" : "small", "title_element" : { "icon_size" : "small", "icon_url" : "http://static.openfoodfacts.localhost/images/misc/high.svg", - "title" : "Saturated fat in high quantity (5.6%)" + "name" : "Saturated fat", + "title" : "Saturated fat in high quantity (5.6%)", + "type" : "percentage", + "value" : 5.6 }, "topics" : [ "health" @@ -1678,13 +1690,17 @@ } } ], - "evaluation" : "", + "evaluation" : "average", + "half_width_on_mobile" : true, "level" : "info", "size" : "small", "title_element" : { "icon_size" : "small", "icon_url" : "http://static.openfoodfacts.localhost/images/misc/moderate.svg", - "title" : "Sugars in moderate quantity (12.5%)" + "name" : "Sugars", + "title" : "Sugars in moderate quantity (12.5%)", + "type" : "percentage", + "value" : 12.5 }, "topics" : [ "health" diff --git a/tests/integration/expected_test_results/api_v2_product_read/get-fields-attribute-groups-all-knowledge-panels.json b/tests/integration/expected_test_results/api_v2_product_read/get-fields-attribute-groups-all-knowledge-panels.json index f92f84934c1df..e4c525b64071b 100644 --- a/tests/integration/expected_test_results/api_v2_product_read/get-fields-attribute-groups-all-knowledge-panels.json +++ b/tests/integration/expected_test_results/api_v2_product_read/get-fields-attribute-groups-all-knowledge-panels.json @@ -2228,13 +2228,17 @@ } } ], - "evaluation" : "", + "evaluation" : "average", + "half_width_on_mobile" : true, "level" : "info", "size" : "small", "title_element" : { "icon_size" : "small", "icon_url" : "http://static.openfoodfacts.localhost/images/misc/moderate.svg", - "title" : "Fat in moderate quantity (8.5%)" + "name" : "Fat", + "title" : "Fat in moderate quantity (8.5%)", + "type" : "percentage", + "value" : 8.5 }, "topics" : [ "health" @@ -2270,13 +2274,17 @@ } } ], - "evaluation" : "", + "evaluation" : "good", + "half_width_on_mobile" : true, "level" : "info", "size" : "small", "title_element" : { "icon_size" : "small", "icon_url" : "http://static.openfoodfacts.localhost/images/misc/low.svg", - "title" : "Salt in low quantity (0.0502%)" + "name" : "Salt", + "title" : "Salt in low quantity (0.0502%)", + "type" : "percentage", + "value" : 0.0502 }, "topics" : [ "health" @@ -2302,13 +2310,17 @@ } } ], - "evaluation" : "", + "evaluation" : "bad", + "half_width_on_mobile" : true, "level" : "info", "size" : "small", "title_element" : { "icon_size" : "small", "icon_url" : "http://static.openfoodfacts.localhost/images/misc/high.svg", - "title" : "Saturated fat in high quantity (5.6%)" + "name" : "Saturated fat", + "title" : "Saturated fat in high quantity (5.6%)", + "type" : "percentage", + "value" : 5.6 }, "topics" : [ "health" @@ -2334,13 +2346,17 @@ } } ], - "evaluation" : "", + "evaluation" : "average", + "half_width_on_mobile" : true, "level" : "info", "size" : "small", "title_element" : { "icon_size" : "small", "icon_url" : "http://static.openfoodfacts.localhost/images/misc/moderate.svg", - "title" : "Sugars in moderate quantity (12.5%)" + "name" : "Sugars", + "title" : "Sugars in moderate quantity (12.5%)", + "type" : "percentage", + "value" : 12.5 }, "topics" : [ "health" diff --git a/tests/integration/expected_test_results/api_v2_product_read/get-fields-knowledge-panels-knowledge-panels_excluded-environment_card.json b/tests/integration/expected_test_results/api_v2_product_read/get-fields-knowledge-panels-knowledge-panels_excluded-environment_card.json index 5c0614da41739..85106b937310e 100644 --- a/tests/integration/expected_test_results/api_v2_product_read/get-fields-knowledge-panels-knowledge-panels_excluded-environment_card.json +++ b/tests/integration/expected_test_results/api_v2_product_read/get-fields-knowledge-panels-knowledge-panels_excluded-environment_card.json @@ -310,13 +310,17 @@ } } ], - "evaluation" : "", + "evaluation" : "average", + "half_width_on_mobile" : true, "level" : "info", "size" : "small", "title_element" : { "icon_size" : "small", "icon_url" : "http://static.openfoodfacts.localhost/images/misc/moderate.svg", - "title" : "Fat in moderate quantity (8.5%)" + "name" : "Fat", + "title" : "Fat in moderate quantity (8.5%)", + "type" : "percentage", + "value" : 8.5 }, "topics" : [ "health" @@ -352,13 +356,17 @@ } } ], - "evaluation" : "", + "evaluation" : "good", + "half_width_on_mobile" : true, "level" : "info", "size" : "small", "title_element" : { "icon_size" : "small", "icon_url" : "http://static.openfoodfacts.localhost/images/misc/low.svg", - "title" : "Salt in low quantity (0.0502%)" + "name" : "Salt", + "title" : "Salt in low quantity (0.0502%)", + "type" : "percentage", + "value" : 0.0502 }, "topics" : [ "health" @@ -384,13 +392,17 @@ } } ], - "evaluation" : "", + "evaluation" : "bad", + "half_width_on_mobile" : true, "level" : "info", "size" : "small", "title_element" : { "icon_size" : "small", "icon_url" : "http://static.openfoodfacts.localhost/images/misc/high.svg", - "title" : "Saturated fat in high quantity (5.6%)" + "name" : "Saturated fat", + "title" : "Saturated fat in high quantity (5.6%)", + "type" : "percentage", + "value" : 5.6 }, "topics" : [ "health" @@ -416,13 +428,17 @@ } } ], - "evaluation" : "", + "evaluation" : "average", + "half_width_on_mobile" : true, "level" : "info", "size" : "small", "title_element" : { "icon_size" : "small", "icon_url" : "http://static.openfoodfacts.localhost/images/misc/moderate.svg", - "title" : "Sugars in moderate quantity (12.5%)" + "name" : "Sugars", + "title" : "Sugars in moderate quantity (12.5%)", + "type" : "percentage", + "value" : 12.5 }, "topics" : [ "health" diff --git a/tests/integration/expected_test_results/api_v2_product_read/get-fields-knowledge-panels-knowledge-panels_included-health_card-environment_card.json b/tests/integration/expected_test_results/api_v2_product_read/get-fields-knowledge-panels-knowledge-panels_included-health_card-environment_card.json index dec9d9e03dfbe..61c6a778f681a 100644 --- a/tests/integration/expected_test_results/api_v2_product_read/get-fields-knowledge-panels-knowledge-panels_included-health_card-environment_card.json +++ b/tests/integration/expected_test_results/api_v2_product_read/get-fields-knowledge-panels-knowledge-panels_included-health_card-environment_card.json @@ -843,13 +843,17 @@ } } ], - "evaluation" : "", + "evaluation" : "average", + "half_width_on_mobile" : true, "level" : "info", "size" : "small", "title_element" : { "icon_size" : "small", "icon_url" : "http://static.openfoodfacts.localhost/images/misc/moderate.svg", - "title" : "Fat in moderate quantity (8.5%)" + "name" : "Fat", + "title" : "Fat in moderate quantity (8.5%)", + "type" : "percentage", + "value" : 8.5 }, "topics" : [ "health" @@ -885,13 +889,17 @@ } } ], - "evaluation" : "", + "evaluation" : "good", + "half_width_on_mobile" : true, "level" : "info", "size" : "small", "title_element" : { "icon_size" : "small", "icon_url" : "http://static.openfoodfacts.localhost/images/misc/low.svg", - "title" : "Salt in low quantity (0.0502%)" + "name" : "Salt", + "title" : "Salt in low quantity (0.0502%)", + "type" : "percentage", + "value" : 0.0502 }, "topics" : [ "health" @@ -917,13 +925,17 @@ } } ], - "evaluation" : "", + "evaluation" : "bad", + "half_width_on_mobile" : true, "level" : "info", "size" : "small", "title_element" : { "icon_size" : "small", "icon_url" : "http://static.openfoodfacts.localhost/images/misc/high.svg", - "title" : "Saturated fat in high quantity (5.6%)" + "name" : "Saturated fat", + "title" : "Saturated fat in high quantity (5.6%)", + "type" : "percentage", + "value" : 5.6 }, "topics" : [ "health" @@ -949,13 +961,17 @@ } } ], - "evaluation" : "", + "evaluation" : "average", + "half_width_on_mobile" : true, "level" : "info", "size" : "small", "title_element" : { "icon_size" : "small", "icon_url" : "http://static.openfoodfacts.localhost/images/misc/moderate.svg", - "title" : "Sugars in moderate quantity (12.5%)" + "name" : "Sugars", + "title" : "Sugars in moderate quantity (12.5%)", + "type" : "percentage", + "value" : 12.5 }, "topics" : [ "health" diff --git a/tests/integration/expected_test_results/api_v2_product_read/get-knowledge-panels-fr.json b/tests/integration/expected_test_results/api_v2_product_read/get-knowledge-panels-fr.json index daa28bbad2946..45860d65908c9 100644 --- a/tests/integration/expected_test_results/api_v2_product_read/get-knowledge-panels-fr.json +++ b/tests/integration/expected_test_results/api_v2_product_read/get-knowledge-panels-fr.json @@ -873,13 +873,17 @@ } } ], - "evaluation" : "", + "evaluation" : "average", + "half_width_on_mobile" : true, "level" : "info", "size" : "small", "title_element" : { "icon_size" : "small", "icon_url" : "http://static.openfoodfacts.localhost/images/misc/moderate.svg", - "title" : "Matières grasses en quantité modérée (8.5%)" + "name" : "Matières grasses", + "title" : "Matières grasses en quantité modérée (8.5%)", + "type" : "percentage", + "value" : 8.5 }, "topics" : [ "health" @@ -915,13 +919,17 @@ } } ], - "evaluation" : "", + "evaluation" : "good", + "half_width_on_mobile" : true, "level" : "info", "size" : "small", "title_element" : { "icon_size" : "small", "icon_url" : "http://static.openfoodfacts.localhost/images/misc/low.svg", - "title" : "Sel en faible quantité (0.0502%)" + "name" : "Sel", + "title" : "Sel en faible quantité (0.0502%)", + "type" : "percentage", + "value" : 0.0502 }, "topics" : [ "health" @@ -947,13 +955,17 @@ } } ], - "evaluation" : "", + "evaluation" : "bad", + "half_width_on_mobile" : true, "level" : "info", "size" : "small", "title_element" : { "icon_size" : "small", "icon_url" : "http://static.openfoodfacts.localhost/images/misc/high.svg", - "title" : "Acides gras saturés en quantité élevée (5.6%)" + "name" : "Acides gras saturés", + "title" : "Acides gras saturés en quantité élevée (5.6%)", + "type" : "percentage", + "value" : 5.6 }, "topics" : [ "health" @@ -979,13 +991,17 @@ } } ], - "evaluation" : "", + "evaluation" : "average", + "half_width_on_mobile" : true, "level" : "info", "size" : "small", "title_element" : { "icon_size" : "small", "icon_url" : "http://static.openfoodfacts.localhost/images/misc/moderate.svg", - "title" : "Sucres en quantité modérée (12.5%)" + "name" : "Sucres", + "title" : "Sucres en quantité modérée (12.5%)", + "type" : "percentage", + "value" : 12.5 }, "topics" : [ "health" diff --git a/tests/integration/expected_test_results/api_v2_product_read/get-knowledge-panels.json b/tests/integration/expected_test_results/api_v2_product_read/get-knowledge-panels.json index e48babdbf710a..83340712e8621 100644 --- a/tests/integration/expected_test_results/api_v2_product_read/get-knowledge-panels.json +++ b/tests/integration/expected_test_results/api_v2_product_read/get-knowledge-panels.json @@ -873,13 +873,17 @@ } } ], - "evaluation" : "", + "evaluation" : "average", + "half_width_on_mobile" : true, "level" : "info", "size" : "small", "title_element" : { "icon_size" : "small", "icon_url" : "http://static.openfoodfacts.localhost/images/misc/moderate.svg", - "title" : "Fat in moderate quantity (8.5%)" + "name" : "Fat", + "title" : "Fat in moderate quantity (8.5%)", + "type" : "percentage", + "value" : 8.5 }, "topics" : [ "health" @@ -915,13 +919,17 @@ } } ], - "evaluation" : "", + "evaluation" : "good", + "half_width_on_mobile" : true, "level" : "info", "size" : "small", "title_element" : { "icon_size" : "small", "icon_url" : "http://static.openfoodfacts.localhost/images/misc/low.svg", - "title" : "Salt in low quantity (0.0502%)" + "name" : "Salt", + "title" : "Salt in low quantity (0.0502%)", + "type" : "percentage", + "value" : 0.0502 }, "topics" : [ "health" @@ -947,13 +955,17 @@ } } ], - "evaluation" : "", + "evaluation" : "bad", + "half_width_on_mobile" : true, "level" : "info", "size" : "small", "title_element" : { "icon_size" : "small", "icon_url" : "http://static.openfoodfacts.localhost/images/misc/high.svg", - "title" : "Saturated fat in high quantity (5.6%)" + "name" : "Saturated fat", + "title" : "Saturated fat in high quantity (5.6%)", + "type" : "percentage", + "value" : 5.6 }, "topics" : [ "health" @@ -979,13 +991,17 @@ } } ], - "evaluation" : "", + "evaluation" : "average", + "half_width_on_mobile" : true, "level" : "info", "size" : "small", "title_element" : { "icon_size" : "small", "icon_url" : "http://static.openfoodfacts.localhost/images/misc/moderate.svg", - "title" : "Sugars in moderate quantity (12.5%)" + "name" : "Sugars", + "title" : "Sugars in moderate quantity (12.5%)", + "type" : "percentage", + "value" : 12.5 }, "topics" : [ "health"