-
Notifications
You must be signed in to change notification settings - Fork 27
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
implemet batch aggregation on the client #318
Conversation
Hey Is there a reason why we are not having Aggregation inherit from I think we can save a lot of code if we do something like
So that instead of The only custom aggregation method would possibly be |
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.
Hey Toyosi! I had a couple of questions on this PR that maybe you or Cliff can answer. Also don't forget to clear out any hound sniifs :)
@@ -24,6 +25,27 @@ def setUp(self): | |||
self.addCleanup(caesar_get_patch.stop) | |||
self.addCleanup(caesar_put_patch.stop) | |||
|
|||
batch_agg_run_aggregation_patch = patch.object(BatchAggregation, 'run_aggregation') |
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 feel like the batch agg patches are so far away from the actual related tests, its easy to forget about them existing.
I wonder if its worth having a separate class within the same file for these changes and rename the ones geared towards caesar to separate.
i.e.
class TestWorkflowCaesarFeatures(unittest.TestCase):
def setUp(self):
caesar test setup stuff
class TestWorkflowRunAggregation(unittest.TestCase):
def setUp(self):
BATCH AGG SETUP STUFF
def test_run_aggregation_stuff(self):
Another way to mitigate (other than splitting tests into classes ) is to patch on the test. eg
@patch('run_aggregation', return_value=EXPECTED RETURN VALUE)
def test_run_aggregation(self, mock_run_agregation):
WHATEVER TEST
Not really: the goal was to be clear about how Aggregations (the Panoptes resource) are intended to be used by developers. That was my first idea too, and after the conversation we just had it seems like it would be more straightforward to implement Aggregations as a model in the client that inherits from PanoptesObject. That would provide the get/post/delete methods required by the In a refactor, I would start by creating a new |
panoptes_client/__init__.py
Outdated
@@ -13,3 +13,4 @@ | |||
from panoptes_client.subject_workflow_status import SubjectWorkflowStatus | |||
from panoptes_client.caesar import Caesar | |||
from panoptes_client.inaturalist import Inaturalist | |||
from panoptes_client.batch_aggregation import BatchAggregation |
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.
Noting that if we want users to only interact with aggregations via the Workflow, we probably do not need this line.
panoptes_client/workflow.py
Outdated
""" | ||
This method will fetch existing aggregation status if any. | ||
""" | ||
return self.get_batch_aggregations()['aggregations'][0]['status'] |
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 there should be a check if there are no aggregations. i.e.
when self.get_batch_aggregations()['aggregations']
length of resulting array is 0.
Same with get_batch_aggregation_links
(method below on L578)
Re: zach's comment:
I don't entirely agree with this ^, since we want to be able to I think what we could do is...
Have this class be only imported in
I haven't fully tested this out, so I think that would work? And I might have some typos here and there cuz I'm just free coding 😆 but I think the code sniffs a bit better this way. |
Thanks for this @yuenmichelle1, makes alot of sense to rely on the existing methods on the PanoptesObject. I have reimplemented to reflect this change so you can re-review. cc @zwolf @lcjohnso |
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.
Hey Toyosi!
I had a couple small things but overall looks pretty good.
|
||
from panoptes_client.user import User | ||
from panoptes_client.aggregation import Aggregation | ||
import six |
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.
Quick question: looking into six
package, it's a python 2/3 compatibility library. Do we need this?
panoptes_client/workflow.py
Outdated
def _get_agg_property(self, param): | ||
try: | ||
aggs = self.get_batch_aggregations() | ||
next = six.next(aggs) |
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.
Possibly stylistic, but I'm not the biggest fan of declaring a variable next
, mainly because i worry it rewrites Python's built-in next
method. We could rename this variable to agg
or something.
Though, I think we could get away with
return getattr(next(aggs), param, None)
or something like that
Implementation of batch aggregation on the Workflows class.
Batch Aggregation guide: https://github.com/orgs/zooniverse/projects/44/views/2?sliceBy%5BcolumnId%5D=74376894&pane=issue&itemId=70649021
You can test with
Workflow(3819).run_batch_aggregation(1326469)