From 9a292eafc027924e298b0183c8bfa56098617bfb Mon Sep 17 00:00:00 2001 From: tooyosi Date: Tue, 1 Oct 2024 18:09:06 +0100 Subject: [PATCH 1/4] implement batch aggregation on cli --- panoptes_cli/commands/workflow.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/panoptes_cli/commands/workflow.py b/panoptes_cli/commands/workflow.py index d02c513..256f689 100644 --- a/panoptes_cli/commands/workflow.py +++ b/panoptes_cli/commands/workflow.py @@ -4,7 +4,7 @@ from panoptes_cli.scripts.panoptes import cli from panoptes_client import Workflow - +from panoptes_client.panoptes import PanoptesAPIException @cli.group() def workflow(): @@ -229,6 +229,32 @@ def delete(force, workflow_ids): ) workflow.delete() +@workflow.command() +@click.argument('workflow-id', required=True, type=int) +@click.argument('user-id', required=True, type=int) +@click.option('--delete-if-exists', '-d', is_flag=True, help='Delete if it exists.') +def run_aggregation(workflow_id, user_id, delete_if_exists): + agg = Workflow(workflow_id).run_aggregation(user_id, delete_if_exists) + try: + click.echo(agg.raw) + except PanoptesAPIException as err: + click.echo(err) + +@workflow.command() +@click.argument('workflow-id', required=True, type=int) +def get_batch_aggregations(workflow_id): + agg = Workflow(workflow_id).get_batch_aggregations() + click.echo(agg.object_list) + +@workflow.command() +@click.argument('workflow-id', required=True, type=int) +def check_batch_aggregation_run_status(workflow_id): + click.echo(Workflow(workflow_id).check_batch_aggregation_run_status()) + +@workflow.command() +@click.argument('workflow-id', required=True, type=int) +def get_batch_aggregation_links(workflow_id): + click.echo(Workflow(workflow_id).get_batch_aggregation_links()) def echo_workflow(workflow): click.echo( From 61eeed28ab25ce7882407fdbbce32086b1541d53 Mon Sep 17 00:00:00 2001 From: tooyosi Date: Tue, 1 Oct 2024 18:26:10 +0100 Subject: [PATCH 2/4] hound cleanups --- panoptes_cli/commands/workflow.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/panoptes_cli/commands/workflow.py b/panoptes_cli/commands/workflow.py index 256f689..d97544b 100644 --- a/panoptes_cli/commands/workflow.py +++ b/panoptes_cli/commands/workflow.py @@ -229,10 +229,14 @@ def delete(force, workflow_ids): ) workflow.delete() + @workflow.command() @click.argument('workflow-id', required=True, type=int) @click.argument('user-id', required=True, type=int) -@click.option('--delete-if-exists', '-d', is_flag=True, help='Delete if it exists.') +@click.option('--delete-if-exists', + '-d', + is_flag=True, + help='Delete if it exists.') def run_aggregation(workflow_id, user_id, delete_if_exists): agg = Workflow(workflow_id).run_aggregation(user_id, delete_if_exists) try: @@ -240,22 +244,26 @@ def run_aggregation(workflow_id, user_id, delete_if_exists): except PanoptesAPIException as err: click.echo(err) + @workflow.command() @click.argument('workflow-id', required=True, type=int) def get_batch_aggregations(workflow_id): agg = Workflow(workflow_id).get_batch_aggregations() click.echo(agg.object_list) + @workflow.command() @click.argument('workflow-id', required=True, type=int) def check_batch_aggregation_run_status(workflow_id): click.echo(Workflow(workflow_id).check_batch_aggregation_run_status()) + @workflow.command() @click.argument('workflow-id', required=True, type=int) def get_batch_aggregation_links(workflow_id): click.echo(Workflow(workflow_id).get_batch_aggregation_links()) + def echo_workflow(workflow): click.echo( u'{} {}'.format( From bb28c4532ddc0d5129c288dd32a0f46a2d15e2ed Mon Sep 17 00:00:00 2001 From: tooyosi Date: Tue, 1 Oct 2024 18:29:03 +0100 Subject: [PATCH 3/4] hound cleanups --- panoptes_cli/commands/workflow.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/panoptes_cli/commands/workflow.py b/panoptes_cli/commands/workflow.py index d97544b..c51ab1e 100644 --- a/panoptes_cli/commands/workflow.py +++ b/panoptes_cli/commands/workflow.py @@ -233,10 +233,11 @@ def delete(force, workflow_ids): @workflow.command() @click.argument('workflow-id', required=True, type=int) @click.argument('user-id', required=True, type=int) -@click.option('--delete-if-exists', - '-d', - is_flag=True, - help='Delete if it exists.') +@click.option( + '--delete-if-exists', + '-d', + is_flag=True, + help='Delete if it exists.') def run_aggregation(workflow_id, user_id, delete_if_exists): agg = Workflow(workflow_id).run_aggregation(user_id, delete_if_exists) try: From ee71d9d6b1452251a1326b3dae14480638c92775 Mon Sep 17 00:00:00 2001 From: tooyosi Date: Fri, 4 Oct 2024 13:03:36 +0100 Subject: [PATCH 4/4] add doc to readme and aggregation functions --- README.md | 34 ++++++++++++++++++++++++++++--- panoptes_cli/commands/workflow.py | 8 ++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 879a8d3..127aeda 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ the API behind [the Zooniverse](https://www.zooniverse.org/). The Panoptes CLI is written in Python, so in order to install it you will need to install Python 3 along with `pip`. Please note: while still compatible with Python 2.7, we have ended support for use of the CLI with this deprecated version. -macOS and Linux already come with Python installed, so run this to see if you +macOS and Linux already come with Python installed, so run this to see if you already have everything you need: ``` @@ -18,7 +18,7 @@ $ python --version && pip --version If you see an error like `python: command not found` or `pip: command not found` then you will need to install this: -- [Python installation](https://wiki.python.org/moin/BeginnersGuide/Download) +- [Python installation](https://wiki.python.org/moin/BeginnersGuide/Download) (or [Miniconda installation](https://docs.conda.io/en/latest/miniconda.html)) - [Pip installation](https://pip.pypa.io/en/stable/installing/) @@ -280,6 +280,34 @@ $ panoptes workflow retire-subjects 101 2001 2002 $ panoptes workflow unretire-subjects 101 2001 2002 ``` +### Run aggregations + +``` +# for running batch aggregation on workflow with id 101, user id 2001 and conditional delete flag -d +$ panoptes workflow run-aggregation 101 2001 -d +``` + +### Get batch aggregations + +``` +# for fetching existing batch aggregation on workflow with id 101 +$ panoptes workflow get-batch-aggregations 101 +``` + +### Check batch aggregation run status + +``` +# for checking existing batch aggregation status on workflow with id 101 +$ panoptes workflow check-batch-aggregation-run-status 101 +``` + +### Get batch aggregation links + +``` +# for fetching links to the run aggregation on workflow with id 101 +$ panoptes workflow get-batch-aggregation-links 101 +``` + #### By subject sets, i.e. for all the linked subjects in a subject set ``` @@ -325,7 +353,7 @@ Optional: include an updated_since timestamp (string) to include only observatio $ panoptes inaturalist import-observations --taxon-id 46017 --subject-set-id 999999 --updated-since 2022-12-03 ``` -The `--updated-since` argument is a standard ISO timestamp, such as '2022-12-03' or `2022-12-03T18:56:06+00:00'. It is passed directly to the iNat Observations v2 API as the 'updated_since' query parameter. +The `--updated-since` argument is a standard ISO timestamp, such as '2022-12-03' or `2022-12-03T18:56:06+00:00'. It is passed directly to the iNat Observations v2 API as the 'updated_since' query parameter. diff --git a/panoptes_cli/commands/workflow.py b/panoptes_cli/commands/workflow.py index c51ab1e..6a48593 100644 --- a/panoptes_cli/commands/workflow.py +++ b/panoptes_cli/commands/workflow.py @@ -239,6 +239,8 @@ def delete(force, workflow_ids): is_flag=True, help='Delete if it exists.') def run_aggregation(workflow_id, user_id, delete_if_exists): + """Kicks off a new aggregation job.""" + agg = Workflow(workflow_id).run_aggregation(user_id, delete_if_exists) try: click.echo(agg.raw) @@ -249,6 +251,8 @@ def run_aggregation(workflow_id, user_id, delete_if_exists): @workflow.command() @click.argument('workflow-id', required=True, type=int) def get_batch_aggregations(workflow_id): + """Gets existing batch aggregations.""" + agg = Workflow(workflow_id).get_batch_aggregations() click.echo(agg.object_list) @@ -256,12 +260,16 @@ def get_batch_aggregations(workflow_id): @workflow.command() @click.argument('workflow-id', required=True, type=int) def check_batch_aggregation_run_status(workflow_id): + """Fetches the run status of existing aggregation.""" + click.echo(Workflow(workflow_id).check_batch_aggregation_run_status()) @workflow.command() @click.argument('workflow-id', required=True, type=int) def get_batch_aggregation_links(workflow_id): + """Fetches batch aggregation download links.""" + click.echo(Workflow(workflow_id).get_batch_aggregation_links())