From 4285188f8ec5dd2ea6eb2b09a73d7838824fde20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Gigandet?= Date: Fri, 1 Dec 2023 18:31:45 +0100 Subject: [PATCH 1/3] fix: use ciqual_proxy_food_code --- ciqual/nutrients.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ciqual/nutrients.py b/ciqual/nutrients.py index d3f5837..a1af6f6 100644 --- a/ciqual/nutrients.py +++ b/ciqual/nutrients.py @@ -52,10 +52,10 @@ def parse_value(ciqual_nutrient): def get_ciqual_code(ingredient_id): ingredient = ingredients_taxonomy.get(ingredient_id, None) if ingredient is None: - print(ingredient_id + ' not found') + print(ingredient_id + ' not found') return None - ciqual_code = ingredient.get('ciqual_food_code', None) + ciqual_code = ingredient.get('ciqual_food_code', ingredient.get('ciqual_proxy_food_code', None)) if ciqual_code: return ciqual_code['en'] @@ -77,7 +77,7 @@ def setup_ingredients(ingredients): setup_ingredients(ingredient['ingredients']) else: - ciqual_code = ingredient.get('ciqual_food_code') + ciqual_code = ingredient.get('ciqual_food_code', ingredient.get('ciqual_proxy_food_code', None)) if (ciqual_code is None): ciqual_code = get_ciqual_code(ingredient['id']) @@ -98,6 +98,7 @@ def setup_ingredients(ingredients): ingredient_nutrients[nutrient['off_id']] = {'percent_min': value, 'percent_max': value} ingredient['nutrients'] = ingredient_nutrients + ingredient['ciqual_food_code_used'] = ciqual_code def prepare_product(product): From c2cd86cc8da6ce1bbf01e1371ad12d434cc855ff Mon Sep 17 00:00:00 2001 From: John Gomersall Date: Mon, 11 Dec 2023 10:01:24 +0000 Subject: [PATCH 2/3] Fixed requirements.txt --- requirements.txt | Bin 1502 -> 788 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/requirements.txt b/requirements.txt index ac809cd53e5cfccb27003734e4fcc9b024887ffd..04997b6324d921843617ee2afc5ae0f93fbfbccb 100644 GIT binary patch literal 788 zcmYk4F>~86425_87xOGik?ny)*IaX#yG)&WG(|~_DUu~2$Lg=|gPft8009pVA84*M z9P*}hBRhE%CT>1y-O64naSg`av{tQb@XNYFe)NcsO36mald!WX)zKlQvY6oiy27n{ zaq!%FM$ihILMmo4S|2f_7elOhqd7%r$rjRXF+LpbkQfXlh@eY0!ac0ZpQsyW+tCwrYhRB3!ky6Fz#I;^-&# zbVQ-2I+!>)j7BpS29Q@DKaG0ssKlEow>5v55#yf!mo0Ax_aGN5T%!#rAQji;NmzB* zDwWU5tGDtD7O8yOyTG1O?MY-nHW@_<|8n-Z`w(v|n*= zDT&f`9kuSHYH%x&H!MRQA_zeOi3MD7>JF$|gybq|eZqnE2-i6b37gz^Sm@#!&Ms>p zpG`qEmV?y$_Up&nPpx}+EAGzgT8vQu(YvXGpBvXPT z+K;EWn9>sXy+~77tW>xob`K=GZmZbmAXm#_MbV literal 1502 zcmZvcO>fg+5QO)P#7{|8J8eo19JnGXA#vh_oWx1o#&NKne(>Xgd3OEUDMFU>;hmk` z*&V-seiyc~&JH%SlfBwUU720kjqYoEZ||(Iqn=mRcx~`EZI2$yjVRfX zxwg_;>y^9J4RfwYt_u{Och0i5y;xdxQ3^d%y+;3PJv%7xm$Q)lFFVmx`@>LqJ}@@Q zg{5#Fvaf|e)xr@QRq0%Duj-BdMSoXbCHgNtxANIM4c%v=0LoTcNNes9H zQ#$CXwAcBlC-?J`cbyrZHG8&+N8-$hE$|sE&+a15MAV@mrUxSP>4o#372)J=#P+D) KY0BY`sP-2wy4NWH From 34718649416900d8c8d74babff69bba5a06268cd Mon Sep 17 00:00:00 2001 From: John Gomersall Date: Mon, 11 Dec 2023 10:01:55 +0000 Subject: [PATCH 3/3] Added test for proxy code --- ciqual/nutrients_test.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ciqual/nutrients_test.py b/ciqual/nutrients_test.py index 7d3bac7..ef22f51 100644 --- a/ciqual/nutrients_test.py +++ b/ciqual/nutrients_test.py @@ -1,5 +1,4 @@ -import pytest -from ciqual.nutrients import prepare_product +from ciqual.nutrients import get_ciqual_code, prepare_product def test_prepare_product_populates_nutrients(): product = {'ingredients': [{'id':'en:tomato', 'ciqual_food_code': '20047'}]} @@ -39,4 +38,6 @@ def test_prepare_product_creates_a_max_range_entry_if_ingredient_not_found(): assert carbs['percent_min'] >= 0 assert carbs['percent_max'] <= 100 - +def test_get_ciqual_code_should_use_proxy_if_no_main_code(): + ciqual_code = get_ciqual_code('en:tomato-sauce') + assert ciqual_code == '11107'