-
-
Notifications
You must be signed in to change notification settings - Fork 58
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: Do not apply nutriscore prediction if it does not match the current nutriscore of the product #772
Closed
Closed
fix: Do not apply nutriscore prediction if it does not match the current nutriscore of the product #772
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6680b9d
Testcase written.
Jagrutiti 201911f
Merge https://github.com/openfoodfacts/robotoff into robtoff-#115
Jagrutiti c570894
Modifying test cases
Jagrutiti a37d23f
Modifying test cases
Jagrutiti a0e2805
Modified test cases. They are still incomplete
Jagrutiti 92e91ed
Updated test cases
Jagrutiti File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,82 @@ | ||
import requests | ||
from PIL import Image | ||
from tests import data | ||
from robotoff.insights.extraction import get_predictions_from_image | ||
from robotoff.insights.importer import import_insights | ||
from unittest.mock import Mock | ||
|
||
from robotoff import settings | ||
from tests.integration.models_utils import PredictionFactory | ||
|
||
def test_import_insights_from_image(mock): | ||
|
||
def test_import_insights_from_image(mocker): | ||
barcode = "3302740030949" | ||
source_image = '/330/274/003/0949/6.jpg ' | ||
ocr_url = 'https://world.openfoodfacts.org/images/products/802/509/314/0251/4.json' | ||
server_domain = 'api.openfoodfacts.org' | ||
|
||
expected_predictions_all = [ | ||
PredictionFactory(type='label', barcode=3302740030949, data={"model": "nutriscore", "confidence": 0.871872, "bounding_box": [1441.3848, 1036.8024, 1685.6928, 1430.2488]}, value_tag="en:nutriscore-c", value="", automatic_processing=False), | ||
PredictionFactory(type='label', barcode=3302740030949, data={"model": "nutriscore", "confidence": 0.816114128, "bounding_box": [0.591395915, 0.477426708, 0.688566923, 0.624632716]}, value_tag="en:nutriscore-a", value="", automatic_processing=False), | ||
PredictionFactory(type='label', barcode=3302740030949, data={"model": "nutriscore", "confidence": 0.913557172, "bounding_box": [0.596912444, 0.429353863, 0.70557, 0.592592061]}, value_tag="en:nutriscore-c", value="", automatic_processing=False), | ||
PredictionFactory(type='label', barcode=3302740030949, data={"model": "nutriscore", "confidence": 0.99035, "bounding_box": [0.575399518, 0.472130537, 0.691237211, 0.625134587]}, value_tag="en:nutriscore-e", value="", automatic_processing=False) | ||
] | ||
source_image = "https://world.openfoodfacts.org/images/products/330/274/003/0949/front_fr.110.400.jpg" | ||
ocr_url = "https://world.openfoodfacts.org/images/products/802/509/314/0251/4.json" | ||
server_domain = settings.OFF_SERVER_DOMAIN | ||
|
||
get_predictions_from_image = mock.Mock(return_value=expected_predictions_all) | ||
image = Image.open(requests.get(source_image, stream=True).raw) | ||
|
||
get_product = {"code":"3302740030949","product":{"labels":"Sans colorants, Nutriscore, Nutriscore C, Fumé au bois de hêtre","product_name":"Pommes de terre gratinées aux lardons et champignons"},"status":1,"status_verbose":"product found"} | ||
mock_import_insights = mocker.patch( | ||
"robotoff.insights.importer.import_insights", return_value=4 | ||
) | ||
mock_get_predictions_from_image = mocker.patch( | ||
"robotoff.insights.extraction.get_predictions_from_image" | ||
) | ||
|
||
predictions_list = [ | ||
PredictionFactory( | ||
type="label", | ||
barcode=3302740030949, | ||
data={ | ||
"model": "nutriscore", | ||
"confidence": 0.871872, | ||
"bounding_box": [1441.3848, 1036.8024, 1685.6928, 1430.2488], | ||
}, | ||
value_tag="en:nutriscore-c", | ||
value="", | ||
automatic_processing=False, | ||
), | ||
PredictionFactory( | ||
type="label", | ||
barcode=3302740030949, | ||
data={ | ||
"model": "nutriscore", | ||
"confidence": 0.816114128, | ||
"bounding_box": [0.591395915, 0.477426708, 0.688566923, 0.624632716], | ||
}, | ||
value_tag="en:nutriscore-a", | ||
value="", | ||
automatic_processing=False, | ||
), | ||
PredictionFactory( | ||
type="label", | ||
barcode=3302740030949, | ||
data={ | ||
"model": "nutriscore", | ||
"confidence": 0.913557172, | ||
"bounding_box": [0.596912444, 0.429353863, 0.70557, 0.592592061], | ||
}, | ||
value_tag="en:nutriscore-c", | ||
value="", | ||
automatic_processing=False, | ||
), | ||
PredictionFactory( | ||
type="label", | ||
barcode=3302740030949, | ||
data={ | ||
"model": "nutriscore", | ||
"confidence": 0.99035, | ||
"bounding_box": [0.575399518, 0.472130537, 0.691237211, 0.625134587], | ||
}, | ||
value_tag="en:nutriscore-e", | ||
value="", | ||
automatic_processing=False, | ||
), | ||
] | ||
|
||
# import_insights = mock.Mock(return_value=) | ||
|
||
mock_import_insights.assert_called_once_with( | ||
predictions=predictions_list, | ||
server_domain=server_domain, | ||
automatic=True, | ||
) | ||
|
||
mock_get_predictions_from_image.assert_called_once_with( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both I was not able to resolve it. I did see the existing examples in the code. I read where to patch and tried to follow the steps in the document but no luck. |
||
barcode=barcode, image=image, source_image=source_image, ocr_url=ocr_url | ||
) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the code I was not able to figure out what will
get_predictions_from_image
return