panoptes-python-client icon indicating copy to clipboard operation
panoptes-python-client copied to clipboard

How to detect if a subject is retired / Fetch retired subjects

Open freen opened this issue 9 years ago • 6 comments

I'm writing a workflow post-processing task which uses the panoptes-python-client.

On a cron schedule, the script will check the applicable workflow / subject_set for any subjects which have been retired / have met their classification threshold.

It will perform the necessary post-processing tasks based on the input for those retired subjects, and then set a subject metadata attribute which indicates that the subject has already been processed by this script (this subject will then be ignored by this script on subsequent runs.)

So far it's not clear to me how to detect, using panoptes-python-client, which subjects have been retired. I've inspected the code and the attributes of Subject, SubjectSet, Workflow, etc., but I don't see a retired or retired_subjects data point / link anywhere.

What's the best way to inspect this data?

Thanks in advance!

freen avatar Sep 15 '17 13:09 freen

Hi @freen we don't have any code in the python client to determine if its' retired.

The subject model could request the SubjectWorkflowStatus resource with ?subject_id=x&workflow_id=y params to isolate that subject workflow state. That resource will return the classificaitons_count and the retirement date time retired / reason.

We'd love a PR for this it could be similar to how we use the SetMemberSubject model to link the subject_sets & subjects here: https://github.com/zooniverse/panoptes-python-client/blob/061bf1b37a8d1ed63b9269a76ef5d48fd94df6b5/panoptes_client/subject_set.py#L27

camallen avatar Sep 15 '17 14:09 camallen

Thanks for your quick reply, @camallen. I'll take this into consideration.

I'm concerned that this approach might be rather inefficient, but as I'm not 100% familiar with the client internals, I could be mistaken.

The subject set which I'll be polling will have between 5k and 10k subjects. Fetching all of the thousands of subjects in a subject set, and then making another API request per subject to check if it's retired, seems like it would be quite expensive --- especially if my cron is running every 10 minutes.

I don't know far from reality this feature would be, but If there were an API parameter (mapped to the client's where) which allowed a client to filter for subjects which are retired, or else if the API simply included this additional data point in each subject's data in its response, this would seem like a less egregious use of network resources.

My current approach, failing this, is to fetch all classifications from the target workflow and aggregate them by subject, and then to take action on those subjects which have classification quantities matching the retirement threshold for the workflow, but this seems less intuitive than building a concept of retirement into the SubjectSet API interface --- this approach in turn will steadily balloon overtime, pulling growing quantities of classification records which have already been addressed.

freen avatar Sep 15 '17 15:09 freen

The subject set which I'll be polling will have between 5k and 10k subjects. Fetching all of the thousands of subjects in a subject set, and then making another API request per subject to check if it's retired, seems like it would be quite expensive --- especially if my cron is running every 10 minutes.

Any reason you are polling this? Most sets don't change over time...you can use a subjects csv export to get the data and use this as a base state.

I don't know far from reality this feature would be, but If there were an API parameter (mapped to the client's where) which allowed a client to filter for subjects which are retired

Subjects can be reused across many sets / workflows / projects. So we don't serialize all the state for a subject (normally only 1 set / 1 workflow), e.g. retired state, etc.

That said we could add some query param filtering on /subjects/ & /subjects/:id here to modify the query scope on a subject, e.g. ?retired=true&workflow_id: X to only return retired data. Those fields should be indexed lookups so should be ok to add in. We could do this on the workflow resource as well.

or else if the API simply included this additional data point in each subject's data in its response, this would seem like a less egregious use of network resources.

Yeah - the data model doesn't lend itself to cheaply serialize this info though i can look into it as an optional scope that can be activated by a query param.

My current approach, failing this, is to fetch all classifications from the target workflow and aggregate them by subject, and then to take action on those subjects which have classification quantities matching the retirement threshold for the workflow, but this seems less intuitive than building a concept of retirement into the SubjectSet API interface --- this approach in turn will steadily balloon overtime, pulling growing quantities of classification records which have already been addressed.

Fetching classifications is slow and has issues (https://github.com/zooniverse/Panoptes/issues/2319). I'd avoid that path generally till we fix it and you raise valid issues with this implementation.

We do have a new system (https://github.com/zooniverse/caesar) that listens to the classification stream and makes decisions around data as it comes in. It can retire, move subjects, etc. We've been successfully using this system and I'd be happy to help you test it on your workflows as it sounds like you've got a use case for it.

camallen avatar Sep 15 '17 16:09 camallen

Any reason you are polling this? Most sets don't change over time...you can use a subjects csv export to get the data and use this as a base state.

Good point. Originally our custom post-processing tasks were to apply to multiple workflow steps, most of which had variable subject sets, and the one generic interface was the API. With Caesar the scope of that changed, and now the cron task I'm developing is only interacting with a static subject set, so the base CSV will be a good optimization.

We do have a new system (https://github.com/zooniverse/caesar) that listens to the classification stream and makes decisions around data as it comes in. It can retire, move subjects, etc. We've been successfully using this system and I'd be happy to help you test it on your workflows as it sounds like you've got a use case for it.

We're doing custom image processing which requires a custom post-processing workflow task.

Fetching classifications is slow and has issues (zooniverse/Panoptes#2319). I'd avoid that path generally till we fix it and you raise valid issues with this implementation.

The image processing / post-processing workflow work we're doing requires the classification data in order to do it's job. It needs to be automatic and have a pretty high frequency (ten-minutely.)

For my classifications API call, I'm currently limiting the scope of the query by project ID and workflow ID.

Can you recommend a different way of automating the classification export? Apologies if I've missed anything obvious.

freen avatar Sep 16 '17 14:09 freen

Hi @freen

Caesar has the ability to link to external web systems for extracts and reductions. We can register your web service and send any resulting classification data to your service for custom processing. You could use this hook to populate a local db of classification data as it comes in (stream not batch).

The classifications api call you have may very well work now, but will become incredibly slow with a lot of data as you page into it. It's on my list to fix but it's non-trivial.

A simple way to load the classification data is to combine our csv exports (1 every 24 hours) and upserts from the caesar payloads. You could look at just populating from caesar but if your service is down or overloaded it may not backfill correctly (i'm not 100% on this, i believe it eventually gives up trying to contact your unreachable service). Having the ability to merge the data sources should ensure you can backfill any gaps.

I don't think this helps but may be useful. We also have a public stream of events (classifications, comments, etc) available via pusher(https://pusher.com/). It doesn't have the annotation data but does have other metadata about events. you could filter (workflow_id / project_id) the stream to pick up classification ids for your project and then backfill with a request via the API with the classification id.

Let me know how we can get you working.

camallen avatar Sep 22 '17 14:09 camallen

I'm going to close this for now. We can reopen it in the future if a way to export/fetch retired subjects becomes available in the API.

adammcmaster avatar Oct 25 '17 15:10 adammcmaster