-
-
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
feat: display insight/prediction for a product #815
Conversation
…t the data by timestamp
E AssertionError: assert ['11', '10', '9', '8', '7'] == ['0', '1', '2', '3', '4'] |
…hub.com/openfoodfacts/robotoff into display-insight-productions-for-product
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.
Here is my first review.
robotoff/app/core.py
Outdated
query = query.order_by(ProductInsight.timestamp.desc()) | ||
|
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.
you should add this only if we have a order_by == "most_recent" parameter, not always, because you are going to change existing code in an unpredictable manner.
This is what makes the test failed by the way (because your line removes previous ordering).
…to display-insight-productions-for-product
robotoff/app/api.py
Outdated
count: int = req.get_param_as_int("count", min_value=1, default=25) | ||
keep_types: Optional[List[str]] = req.get_param_as_list( | ||
"insight_types", required=False | ||
) | ||
barcode: Optional[str] = req.get_param("barcode") | ||
value_tag: str = req.get_param("value_tag") | ||
brands = req.get_param_as_list("brands") or None | ||
server_domain: Optional[str] = req.get_param("server_domain") | ||
|
||
if keep_types: | ||
# Limit the number of types to prevent slow SQL queries | ||
keep_types = keep_types[:10] | ||
|
||
if brands is not None: | ||
# Limit the number of brands to prevent slow SQL queries | ||
brands = brands[:10] |
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.
I think we can factor this code between InsightCollection and DisplayInsightPredictionForProducts.
The idea, is that the function can return a dict (say query_params
), and then simply use:
get_predictions = functools.partial(get_predictions, **query_params)
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.
Here is to unblock you.
robotoff/app/api.py
Outdated
api.add_route( | ||
"/api/v1/insights/predictions/display", DisplayInsightPredictionForProducts() | ||
) |
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.
Why not just "/api/v1/insights/predictions"
to be coherent with the url for insights ?
Co-authored-by: Alex Garel <[email protected]>
…hub.com/openfoodfacts/robotoff into display-insight-productions-for-product
Codecov Report
@@ Coverage Diff @@
## master #815 +/- ##
==========================================
+ Coverage 44.73% 51.47% +6.74%
==========================================
Files 96 92 -4
Lines 6981 6840 -141
==========================================
+ Hits 3123 3521 +398
+ Misses 3858 3319 -539
Help us with your feedback. Take ten seconds to tell us how you rate us. |
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.
We have to add more tests:
- Right now your test is just testing status_code, it should check response content
- also you should then add a test where you create some predictions (PredictionFactory will help you do that) and check that it returns predictions to you
- Also you should check some filters to see they are working
- You should also add some tests on get_predictions (there again using PredictionFactory)
…to display-insight-productions-for-product
…hub.com/openfoodfacts/robotoff into display-insight-productions-for-product
tests/integration/test_api.py
Outdated
PredictionFactory(barcode="123", keep_types="category", value_tag="en:seeds") | ||
PredictionFactory(type="category") | ||
PredictionFactory(value_tag="en:seeds") | ||
PredictionFactory(type="brand") |
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.
I would like those creations to reflect the data proposal here : #815 (comment)
More over it's better to keep created predictions in variables (prediction1, prediction2…), so that you can check for ids in you test (first request you assert the fields, but then you just assert ids).
Co-authored-by: Alex Garel <[email protected]>
Co-authored-by: Alex Garel <[email protected]>
tests/integration/test_api.py
Outdated
assert actual_items2[0]["barcode"] == "123" | ||
assert actual_items2[0]["type"] == "brand" | ||
assert actual_items2[0]["value_tag"] == "en:seeds" | ||
assert prediction2.id == prediction1.id + 1 |
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.
I am not sure about this line though
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.
you should not have to test that. First it's not related to your test (you are not supposed to be testing PredictionFactory here), and second it's not garanteed to be true.
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.
Great @Jagrutiti, we are almost there, some small changes and it will be ok.
tests/integration/test_api.py
Outdated
assert actual_items2[0]["barcode"] == "123" | ||
assert actual_items2[0]["type"] == "brand" | ||
assert actual_items2[0]["value_tag"] == "en:seeds" | ||
assert prediction2.id == prediction1.id + 1 |
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.
you should not have to test that. First it's not related to your test (you are not supposed to be testing PredictionFactory here), and second it's not garanteed to be true.
Co-authored-by: Alex Garel <[email protected]>
Co-authored-by: Alex Garel <[email protected]>
Co-authored-by: Alex Garel <[email protected]>
Co-authored-by: Alex Garel <[email protected]>
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.
Ok let's merge it :-)
(I will just commit my suggestion first)
make result predictible by sorting them
4aff732
to
8791743
Compare
1e80093
to
c0d3817
Compare
Kudos, SonarCloud Quality Gate passed! |
Working on displaying insight/prediction etc to a product.
Following the steps listed in the description.
Currently: list all ProductInsight for this barcode - sort them in a predictable way : type - timestamp - id
Relates to