From 5fbc61944b2e67df36482fa8848a4a08a096027e Mon Sep 17 00:00:00 2001 From: zgoldberg Date: Tue, 15 Aug 2023 15:33:43 -0500 Subject: [PATCH 01/12] added to scheduling upload method to upload schedling goals to all plans within model --- src/aerie_cli/aerie_client.py | 18 ++++++++++++++++++ src/aerie_cli/commands/plans.py | 9 +++++++++ src/aerie_cli/commands/scheduling.py | 28 +++++++++++++++++++++------- 3 files changed, 48 insertions(+), 7 deletions(-) diff --git a/src/aerie_cli/aerie_client.py b/src/aerie_cli/aerie_client.py index 17821958..4528bc25 100644 --- a/src/aerie_cli/aerie_client.py +++ b/src/aerie_cli/aerie_client.py @@ -100,6 +100,24 @@ def list_all_activity_plans(self) -> List[ActivityPlanRead]: plan = ActivityPlanRead.from_api_read(plan) activity_plans.append(plan) return activity_plans + + def get_all_activity_plans_by_model(self, model_id: int) -> List[ActivityPlanRead]: + get_all_plans_by_model_query = """ + query get_plans_by_model($model_id: Int!) { + plan(where: {model_id: {_eq: $model_id}}) { + id + name + } + } + """ + + resp = self.host_session.post_to_graphql(get_all_plans_by_model_query, model_id=model_id) + model_activity_plans = [] + for plan in resp: + plan = ApiActivityPlanRead.from_dict(plan) + plan = ActivityPlanRead.from_api_read(plan) + model_activity_plans.append(plan) + return model_activity_plans def get_all_activity_plans(self, full_args: str = None) -> list[ActivityPlanRead]: get_all_plans_query = """ diff --git a/src/aerie_cli/commands/plans.py b/src/aerie_cli/commands/plans.py index 1d5db0c3..646a1a34 100644 --- a/src/aerie_cli/commands/plans.py +++ b/src/aerie_cli/commands/plans.py @@ -315,3 +315,12 @@ def clean(): typer.echo(f"All activity plans have been deleted") +@app.command() +def get_all_plans_from_id(model_id: int = typer.Option( + ..., help="The mission model ID to associate with the scheduling goal", prompt=True +)): + """Get all plans from model id test""" + client = CommandContext.get_client() + resp = client.get_all_activity_plans_by_model(model_id) + + Console().print(resp) \ No newline at end of file diff --git a/src/aerie_cli/commands/scheduling.py b/src/aerie_cli/commands/scheduling.py index 2e78b5de..7469ee0e 100644 --- a/src/aerie_cli/commands/scheduling.py +++ b/src/aerie_cli/commands/scheduling.py @@ -10,7 +10,7 @@ def upload( ..., help="The mission model ID to associate with the scheduling goal", prompt=True ), plan_id: int = typer.Option( - ..., help="Plan ID", prompt=True + ..., help="Plan ID", prompt=False #how do i make this optional?? ), schedule: str = typer.Option( ..., help="Text file with one path on each line to a scheduling rule file, in decreasing priority order", prompt=True @@ -35,15 +35,29 @@ def upload( uploaded_ids = [kv["id"] for kv in resp] - #priority order is order of filenames in decreasing priority order - #will append to existing goals in specification priority order - specification = client.get_specification_for_plan(plan_id) + if(plan_id): + #priority order is order of filenames in decreasing priority order + #will append to existing goals in specification priority order + specification = client.get_specification_for_plan(plan_id) + + upload_to_spec = [{"goal_id": goal_id, "specification_id": specification} for goal_id in uploaded_ids] + + client.add_goals_to_specifications(upload_to_spec) - upload_to_spec = [{"goal_id": goal_id, "specification_id": specification} for goal_id in uploaded_ids] + typer.echo(f"Assigned goals in priority order to plan ID {plan_id}.") + else: + #get all plan ids from model id if no plan id is provided + resp = CommandContext.get_client().get_all_activity_plans_by_model(model_id) + all_plans_in_model = resp + #may be too slow - create new query? + # all_plans_in_model = [plan for plan in resp if plan.model_id == model_id] - client.add_goals_to_specifications(upload_to_spec) + for plan in all_plans_in_model: + specification = client.get_specification_for_plan(plan.id) #will plans have id + upload_to_spec = [{"goal_id": goal_id, "specification_id": specification} for goal_id in uploaded_ids] + client.add_goals_to_specifications(upload_to_spec) - typer.echo(f"Assigned goals in priority order to plan ID {plan_id}.") + typer.echo(f"Assigned goals in priority order to all plans to model ID {model_id}.") @app.command() From 7276aa486e1a966f2d2b706099c2ee0837c0fa28 Mon Sep 17 00:00:00 2001 From: zgoldberg22 Date: Tue, 15 Aug 2023 16:34:01 -0500 Subject: [PATCH 02/12] fixes to query error --- src/aerie_cli/aerie_client.py | 9 +++++---- src/aerie_cli/commands/scheduling.py | 17 +++++++++-------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/aerie_cli/aerie_client.py b/src/aerie_cli/aerie_client.py index 4528bc25..8b993f9c 100644 --- a/src/aerie_cli/aerie_client.py +++ b/src/aerie_cli/aerie_client.py @@ -103,10 +103,11 @@ def list_all_activity_plans(self) -> List[ActivityPlanRead]: def get_all_activity_plans_by_model(self, model_id: int) -> List[ActivityPlanRead]: get_all_plans_by_model_query = """ - query get_plans_by_model($model_id: Int!) { - plan(where: {model_id: {_eq: $model_id}}) { - id - name + query get_all_plans_by_model_id(id: $model_id) { + mission_model_by_pk(id: $model_id) { + plans { + id + } } } """ diff --git a/src/aerie_cli/commands/scheduling.py b/src/aerie_cli/commands/scheduling.py index 7469ee0e..da5cd811 100644 --- a/src/aerie_cli/commands/scheduling.py +++ b/src/aerie_cli/commands/scheduling.py @@ -8,12 +8,12 @@ def upload( model_id: int = typer.Option( ..., help="The mission model ID to associate with the scheduling goal", prompt=True - ), - plan_id: int = typer.Option( - ..., help="Plan ID", prompt=False #how do i make this optional?? - ), + ), schedule: str = typer.Option( ..., help="Text file with one path on each line to a scheduling rule file, in decreasing priority order", prompt=True + ), + plan_id: int = typer.Option( + ..., help="Plan ID", prompt=False ) ): """Upload scheduling goal""" @@ -47,10 +47,11 @@ def upload( typer.echo(f"Assigned goals in priority order to plan ID {plan_id}.") else: #get all plan ids from model id if no plan id is provided - resp = CommandContext.get_client().get_all_activity_plans_by_model(model_id) - all_plans_in_model = resp - #may be too slow - create new query? - # all_plans_in_model = [plan for plan in resp if plan.model_id == model_id] + resp = CommandContext.get_client().list_all_activity_plans() + # resp = CommandContext.get_client().get_all_activity_plans_by_model(model_id) + # all_plans_in_model = resp + + all_plans_in_model = [plan for plan in resp if plan.model_id == model_id] for plan in all_plans_in_model: specification = client.get_specification_for_plan(plan.id) #will plans have id From 3d4819b4726ebda992370f4c9df71bd762fb80d0 Mon Sep 17 00:00:00 2001 From: zgoldberg22 Date: Tue, 15 Aug 2023 16:49:16 -0500 Subject: [PATCH 03/12] change default of plan_id in upload function --- src/aerie_cli/commands/scheduling.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/aerie_cli/commands/scheduling.py b/src/aerie_cli/commands/scheduling.py index da5cd811..82fed093 100644 --- a/src/aerie_cli/commands/scheduling.py +++ b/src/aerie_cli/commands/scheduling.py @@ -9,11 +9,11 @@ def upload( model_id: int = typer.Option( ..., help="The mission model ID to associate with the scheduling goal", prompt=True ), + plan_id: int = typer.Option( + default="", help="Plan ID", prompt=False + ), schedule: str = typer.Option( ..., help="Text file with one path on each line to a scheduling rule file, in decreasing priority order", prompt=True - ), - plan_id: int = typer.Option( - ..., help="Plan ID", prompt=False ) ): """Upload scheduling goal""" From 685af48c8c896b33bcb1ff882350fb2cd0bd5e6e Mon Sep 17 00:00:00 2001 From: zgoldberg22 Date: Tue, 15 Aug 2023 16:51:49 -0500 Subject: [PATCH 04/12] set prompt back to true --- src/aerie_cli/commands/scheduling.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aerie_cli/commands/scheduling.py b/src/aerie_cli/commands/scheduling.py index 82fed093..e0144829 100644 --- a/src/aerie_cli/commands/scheduling.py +++ b/src/aerie_cli/commands/scheduling.py @@ -10,7 +10,7 @@ def upload( ..., help="The mission model ID to associate with the scheduling goal", prompt=True ), plan_id: int = typer.Option( - default="", help="Plan ID", prompt=False + help="Plan ID (optional)", default="", prompt=True ), schedule: str = typer.Option( ..., help="Text file with one path on each line to a scheduling rule file, in decreasing priority order", prompt=True From aa24087a5bc0e821faf6f284abf1d5a056918f4b Mon Sep 17 00:00:00 2001 From: zgoldberg22 Date: Wed, 16 Aug 2023 08:35:49 -0500 Subject: [PATCH 05/12] fix query for all plans in model id and update upload method --- src/aerie_cli/aerie_client.py | 2 +- src/aerie_cli/commands/scheduling.py | 19 ++++++++----------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/aerie_cli/aerie_client.py b/src/aerie_cli/aerie_client.py index 8b993f9c..ab6208e6 100644 --- a/src/aerie_cli/aerie_client.py +++ b/src/aerie_cli/aerie_client.py @@ -103,7 +103,7 @@ def list_all_activity_plans(self) -> List[ActivityPlanRead]: def get_all_activity_plans_by_model(self, model_id: int) -> List[ActivityPlanRead]: get_all_plans_by_model_query = """ - query get_all_plans_by_model_id(id: $model_id) { + query get_all_plans_by_model_id($model_id: Int!) { mission_model_by_pk(id: $model_id) { plans { id diff --git a/src/aerie_cli/commands/scheduling.py b/src/aerie_cli/commands/scheduling.py index e0144829..88c20a1f 100644 --- a/src/aerie_cli/commands/scheduling.py +++ b/src/aerie_cli/commands/scheduling.py @@ -10,7 +10,7 @@ def upload( ..., help="The mission model ID to associate with the scheduling goal", prompt=True ), plan_id: int = typer.Option( - help="Plan ID (optional)", default="", prompt=True + help="Plan ID (optional)", default=-1, prompt=True #how to make this optional ), schedule: str = typer.Option( ..., help="Text file with one path on each line to a scheduling rule file, in decreasing priority order", prompt=True @@ -35,7 +35,7 @@ def upload( uploaded_ids = [kv["id"] for kv in resp] - if(plan_id): + if(plan_id != -1): #priority order is order of filenames in decreasing priority order #will append to existing goals in specification priority order specification = client.get_specification_for_plan(plan_id) @@ -47,19 +47,16 @@ def upload( typer.echo(f"Assigned goals in priority order to plan ID {plan_id}.") else: #get all plan ids from model id if no plan id is provided - resp = CommandContext.get_client().list_all_activity_plans() - # resp = CommandContext.get_client().get_all_activity_plans_by_model(model_id) - # all_plans_in_model = resp + # resp = CommandContext.get_client().list_all_activity_plans() + resp = CommandContext.get_client().get_all_activity_plans_by_model(model_id) + # all_plans_in_model = [plan for plan in resp if plan.model_id == model_id] - all_plans_in_model = [plan for plan in resp if plan.model_id == model_id] - - for plan in all_plans_in_model: - specification = client.get_specification_for_plan(plan.id) #will plans have id + for plan in resp: + specification = client.get_specification_for_plan(plan.id) upload_to_spec = [{"goal_id": goal_id, "specification_id": specification} for goal_id in uploaded_ids] client.add_goals_to_specifications(upload_to_spec) - typer.echo(f"Assigned goals in priority order to all plans to model ID {model_id}.") - + typer.echo(f"Assigned goals in priority order to all plans with model ID {model_id}.") @app.command() def delete( From 7093d27ec9a8328c5b01c4c629f3c2fd916b545e Mon Sep 17 00:00:00 2001 From: zgoldberg22 Date: Wed, 16 Aug 2023 08:57:29 -0500 Subject: [PATCH 06/12] added test command with methods to test query --- src/aerie_cli/aerie_client.py | 2 +- src/aerie_cli/commands/models.py | 9 +++++++++ src/aerie_cli/commands/plans.py | 12 +----------- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/aerie_cli/aerie_client.py b/src/aerie_cli/aerie_client.py index ab6208e6..fa8937ff 100644 --- a/src/aerie_cli/aerie_client.py +++ b/src/aerie_cli/aerie_client.py @@ -114,7 +114,7 @@ def get_all_activity_plans_by_model(self, model_id: int) -> List[ActivityPlanRea resp = self.host_session.post_to_graphql(get_all_plans_by_model_query, model_id=model_id) model_activity_plans = [] - for plan in resp: + for plan in resp['plans']: plan = ApiActivityPlanRead.from_dict(plan) plan = ActivityPlanRead.from_api_read(plan) model_activity_plans.append(plan) diff --git a/src/aerie_cli/commands/models.py b/src/aerie_cli/commands/models.py index 093c1376..4e51a87e 100644 --- a/src/aerie_cli/commands/models.py +++ b/src/aerie_cli/commands/models.py @@ -112,3 +112,12 @@ def list(): console = Console() console.print(table) + +@app.command() +def get_all_plans_from_id(model_id: int = typer.Option( + ..., help="The mission model ID to associate with the scheduling goal", prompt=True +)): + """Get all plans from model id test""" + resp = CommandContext.get_client().get_all_activity_plans_by_model(model_id) + + Console().print(resp) \ No newline at end of file diff --git a/src/aerie_cli/commands/plans.py b/src/aerie_cli/commands/plans.py index 646a1a34..172f395a 100644 --- a/src/aerie_cli/commands/plans.py +++ b/src/aerie_cli/commands/plans.py @@ -313,14 +313,4 @@ def clean(): for activity_plan in resp: client.delete_plan(activity_plan.id) - typer.echo(f"All activity plans have been deleted") - -@app.command() -def get_all_plans_from_id(model_id: int = typer.Option( - ..., help="The mission model ID to associate with the scheduling goal", prompt=True -)): - """Get all plans from model id test""" - client = CommandContext.get_client() - resp = client.get_all_activity_plans_by_model(model_id) - - Console().print(resp) \ No newline at end of file + typer.echo(f"All activity plans have been deleted") \ No newline at end of file From 40305e59878233cbb2fb95dd234aa53ef099408e Mon Sep 17 00:00:00 2001 From: zgoldberg22 Date: Wed, 16 Aug 2023 09:02:48 -0500 Subject: [PATCH 07/12] query response fix --- src/aerie_cli/aerie_client.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/aerie_cli/aerie_client.py b/src/aerie_cli/aerie_client.py index fa8937ff..cf07dfd9 100644 --- a/src/aerie_cli/aerie_client.py +++ b/src/aerie_cli/aerie_client.py @@ -113,12 +113,12 @@ def get_all_activity_plans_by_model(self, model_id: int) -> List[ActivityPlanRea """ resp = self.host_session.post_to_graphql(get_all_plans_by_model_query, model_id=model_id) - model_activity_plans = [] - for plan in resp['plans']: - plan = ApiActivityPlanRead.from_dict(plan) - plan = ActivityPlanRead.from_api_read(plan) - model_activity_plans.append(plan) - return model_activity_plans + # model_activity_plans = [] + # for plan in resp['plans']: + # plan = ApiActivityPlanRead.from_dict(plan) + # plan = ActivityPlanRead.from_api_read(plan) + # model_activity_plans.append(plan) + return resp['plans'] def get_all_activity_plans(self, full_args: str = None) -> list[ActivityPlanRead]: get_all_plans_query = """ From 43b959b14573f237c5e9f2f1d94fde29952d4229 Mon Sep 17 00:00:00 2001 From: zgoldberg22 Date: Wed, 16 Aug 2023 10:33:14 -0500 Subject: [PATCH 08/12] delete unnecessary code, fixed upload key id error --- src/aerie_cli/aerie_client.py | 5 ----- src/aerie_cli/commands/models.py | 11 +---------- src/aerie_cli/commands/scheduling.py | 4 +--- 3 files changed, 2 insertions(+), 18 deletions(-) diff --git a/src/aerie_cli/aerie_client.py b/src/aerie_cli/aerie_client.py index cf07dfd9..1c920ecb 100644 --- a/src/aerie_cli/aerie_client.py +++ b/src/aerie_cli/aerie_client.py @@ -113,11 +113,6 @@ def get_all_activity_plans_by_model(self, model_id: int) -> List[ActivityPlanRea """ resp = self.host_session.post_to_graphql(get_all_plans_by_model_query, model_id=model_id) - # model_activity_plans = [] - # for plan in resp['plans']: - # plan = ApiActivityPlanRead.from_dict(plan) - # plan = ActivityPlanRead.from_api_read(plan) - # model_activity_plans.append(plan) return resp['plans'] def get_all_activity_plans(self, full_args: str = None) -> list[ActivityPlanRead]: diff --git a/src/aerie_cli/commands/models.py b/src/aerie_cli/commands/models.py index 4e51a87e..ef339df8 100644 --- a/src/aerie_cli/commands/models.py +++ b/src/aerie_cli/commands/models.py @@ -111,13 +111,4 @@ def list(): ) console = Console() - console.print(table) - -@app.command() -def get_all_plans_from_id(model_id: int = typer.Option( - ..., help="The mission model ID to associate with the scheduling goal", prompt=True -)): - """Get all plans from model id test""" - resp = CommandContext.get_client().get_all_activity_plans_by_model(model_id) - - Console().print(resp) \ No newline at end of file + console.print(table) \ No newline at end of file diff --git a/src/aerie_cli/commands/scheduling.py b/src/aerie_cli/commands/scheduling.py index 88c20a1f..8bec961b 100644 --- a/src/aerie_cli/commands/scheduling.py +++ b/src/aerie_cli/commands/scheduling.py @@ -47,12 +47,10 @@ def upload( typer.echo(f"Assigned goals in priority order to plan ID {plan_id}.") else: #get all plan ids from model id if no plan id is provided - # resp = CommandContext.get_client().list_all_activity_plans() resp = CommandContext.get_client().get_all_activity_plans_by_model(model_id) - # all_plans_in_model = [plan for plan in resp if plan.model_id == model_id] for plan in resp: - specification = client.get_specification_for_plan(plan.id) + specification = client.get_specification_for_plan(plan["id"]) upload_to_spec = [{"goal_id": goal_id, "specification_id": specification} for goal_id in uploaded_ids] client.add_goals_to_specifications(upload_to_spec) From 7d4d38f745ddd5d018046afe8f6f994546fde277 Mon Sep 17 00:00:00 2001 From: zgoldberg22 Date: Wed, 16 Aug 2023 10:57:24 -0500 Subject: [PATCH 09/12] fixed scheduling unique goal id error --- src/aerie_cli/commands/scheduling.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/aerie_cli/commands/scheduling.py b/src/aerie_cli/commands/scheduling.py index 8bec961b..326cb80a 100644 --- a/src/aerie_cli/commands/scheduling.py +++ b/src/aerie_cli/commands/scheduling.py @@ -29,27 +29,31 @@ def upload( d = dict(zip(keys, [filename, model_id, f.read()])) upload_obj.append(d) - resp = client.upload_scheduling_goals(upload_obj) + if(plan_id != -1): + #uploading to single plan + resp = client.upload_scheduling_goals(upload_obj) - typer.echo(f"Uploaded scheduling goals to venue.") + typer.echo(f"Uploaded scheduling goals to venue.") - uploaded_ids = [kv["id"] for kv in resp] + uploaded_ids = [kv["id"] for kv in resp] - if(plan_id != -1): #priority order is order of filenames in decreasing priority order #will append to existing goals in specification priority order specification = client.get_specification_for_plan(plan_id) upload_to_spec = [{"goal_id": goal_id, "specification_id": specification} for goal_id in uploaded_ids] - client.add_goals_to_specifications(upload_to_spec) - typer.echo(f"Assigned goals in priority order to plan ID {plan_id}.") else: #get all plan ids from model id if no plan id is provided - resp = CommandContext.get_client().get_all_activity_plans_by_model(model_id) + resp = client.get_all_activity_plans_by_model(model_id) for plan in resp: + #each schedule goal needs own ID - add each goal for each plan + resp = client.upload_scheduling_goals(upload_obj) + typer.echo(f"Uploaded scheduling goals to venue.") + uploaded_ids = [kv["id"] for kv in resp] + specification = client.get_specification_for_plan(plan["id"]) upload_to_spec = [{"goal_id": goal_id, "specification_id": specification} for goal_id in uploaded_ids] client.add_goals_to_specifications(upload_to_spec) From 53f77aa27dcbdc9cef5be4b5d446d79dfb822caa Mon Sep 17 00:00:00 2001 From: zgoldberg22 Date: Wed, 16 Aug 2023 14:44:08 -0500 Subject: [PATCH 10/12] delete query, update user prompts --- src/aerie_cli/aerie_client.py | 14 -------------- src/aerie_cli/commands/scheduling.py | 28 +++++++++++++++++++++------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/aerie_cli/aerie_client.py b/src/aerie_cli/aerie_client.py index 1c920ecb..06c59035 100644 --- a/src/aerie_cli/aerie_client.py +++ b/src/aerie_cli/aerie_client.py @@ -101,20 +101,6 @@ def list_all_activity_plans(self) -> List[ActivityPlanRead]: activity_plans.append(plan) return activity_plans - def get_all_activity_plans_by_model(self, model_id: int) -> List[ActivityPlanRead]: - get_all_plans_by_model_query = """ - query get_all_plans_by_model_id($model_id: Int!) { - mission_model_by_pk(id: $model_id) { - plans { - id - } - } - } - """ - - resp = self.host_session.post_to_graphql(get_all_plans_by_model_query, model_id=model_id) - return resp['plans'] - def get_all_activity_plans(self, full_args: str = None) -> list[ActivityPlanRead]: get_all_plans_query = """ query get__all_plans { diff --git a/src/aerie_cli/commands/scheduling.py b/src/aerie_cli/commands/scheduling.py index 326cb80a..94ca6c97 100644 --- a/src/aerie_cli/commands/scheduling.py +++ b/src/aerie_cli/commands/scheduling.py @@ -1,22 +1,34 @@ import typer from aerie_cli.commands.command_context import CommandContext +from aerie_cli.utils.prompts import select_from_list app = typer.Typer() @app.command() def upload( model_id: int = typer.Option( - ..., help="The mission model ID to associate with the scheduling goal", prompt=True + None, '--model-id', '-m', help="The mission model ID to associate with the scheduling goal", prompt=False ), plan_id: int = typer.Option( - help="Plan ID (optional)", default=-1, prompt=True #how to make this optional + None, '--plan-id', '-p', help="Plan ID", prompt=False ), schedule: str = typer.Option( - ..., help="Text file with one path on each line to a scheduling rule file, in decreasing priority order", prompt=True + None, '--file-path', '-f', help="Text file with one path on each line to a scheduling rule file, in decreasing priority order", prompt=False ) ): """Upload scheduling goal""" + + if(model_id is None and plan_id is None and schedule is None): + choices = ["Upload goals to a single plan", "Upload goals to all plans for a specified model"] + choice = select_from_list(choices) + + if(choices.index(choice) == 0): + plan_id = typer.prompt('Plan ID') + + model_id = typer.prompt('Mission model ID to associate with the scheduling goal') + schedule = typer.prompt('Text file with one path on each line to a scheduling rule file, in decreasing priority order') + client = CommandContext.get_client() upload_obj = [] @@ -29,7 +41,7 @@ def upload( d = dict(zip(keys, [filename, model_id, f.read()])) upload_obj.append(d) - if(plan_id != -1): + if(plan_id is not None): #uploading to single plan resp = client.upload_scheduling_goals(upload_obj) @@ -46,15 +58,17 @@ def upload( typer.echo(f"Assigned goals in priority order to plan ID {plan_id}.") else: #get all plan ids from model id if no plan id is provided - resp = client.get_all_activity_plans_by_model(model_id) + resp = client.list_all_activity_plans() + all_plans_in_model = filter(lambda p: p.model_id == model_id, resp) - for plan in resp: + for plan in all_plans_in_model: + plan_id = plan.id #each schedule goal needs own ID - add each goal for each plan resp = client.upload_scheduling_goals(upload_obj) typer.echo(f"Uploaded scheduling goals to venue.") uploaded_ids = [kv["id"] for kv in resp] - specification = client.get_specification_for_plan(plan["id"]) + specification = client.get_specification_for_plan(plan_id) upload_to_spec = [{"goal_id": goal_id, "specification_id": specification} for goal_id in uploaded_ids] client.add_goals_to_specifications(upload_to_spec) From 89dd2759fea1fcd44ccfab125c32268b0d27f503 Mon Sep 17 00:00:00 2001 From: zgoldberg22 Date: Thu, 17 Aug 2023 10:00:50 -0500 Subject: [PATCH 11/12] added input checks --- src/aerie_cli/commands/scheduling.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/aerie_cli/commands/scheduling.py b/src/aerie_cli/commands/scheduling.py index 94ca6c97..1eadbfb1 100644 --- a/src/aerie_cli/commands/scheduling.py +++ b/src/aerie_cli/commands/scheduling.py @@ -17,20 +17,29 @@ def upload( None, '--file-path', '-f', help="Text file with one path on each line to a scheduling rule file, in decreasing priority order", prompt=False ) ): - """Upload scheduling goal""" + """Upload scheduling goal to single plan or to all plans in a model""" - if(model_id is None and plan_id is None and schedule is None): + if(model_id is None and plan_id is None): choices = ["Upload goals to a single plan", "Upload goals to all plans for a specified model"] choice = select_from_list(choices) - if(choices.index(choice) == 0): + if(choice == choices[0]): plan_id = typer.prompt('Plan ID') + else: + model_id = typer.prompt('Mission model ID to associate with the scheduling goal') - model_id = typer.prompt('Mission model ID to associate with the scheduling goal') + if(schedule is None): schedule = typer.prompt('Text file with one path on each line to a scheduling rule file, in decreasing priority order') client = CommandContext.get_client() + all_plans_list = client.list_all_activity_plans() + if(plan_id is not None and model_id is None): + #get model id if not specified + plan = next((p for p in all_plans_list if p.id == plan_id), None) + model_id = plan.model_id + assert(model_id is not None) + upload_obj = [] keys = ["name", "model_id", "definition"] with open(schedule, "r") as infile: @@ -39,7 +48,7 @@ def upload( filename = filepath.split("/")[-1] with open(filepath, "r") as f: d = dict(zip(keys, [filename, model_id, f.read()])) - upload_obj.append(d) + upload_obj.append(d) if(plan_id is not None): #uploading to single plan @@ -58,14 +67,13 @@ def upload( typer.echo(f"Assigned goals in priority order to plan ID {plan_id}.") else: #get all plan ids from model id if no plan id is provided - resp = client.list_all_activity_plans() - all_plans_in_model = filter(lambda p: p.model_id == model_id, resp) + all_plans_in_model = [p for p in all_plans_list if p.model_id == model_id] for plan in all_plans_in_model: plan_id = plan.id #each schedule goal needs own ID - add each goal for each plan resp = client.upload_scheduling_goals(upload_obj) - typer.echo(f"Uploaded scheduling goals to venue.") + typer.echo(f"Uploaded scheduling goals to venue for plan ID ${plan_id}") uploaded_ids = [kv["id"] for kv in resp] specification = client.get_specification_for_plan(plan_id) From 692e2c5e047599489c094bdbf29fb9ad717bdcd6 Mon Sep 17 00:00:00 2001 From: zgoldberg22 Date: Thu, 17 Aug 2023 10:25:24 -0500 Subject: [PATCH 12/12] conversion type error fix --- src/aerie_cli/commands/scheduling.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/aerie_cli/commands/scheduling.py b/src/aerie_cli/commands/scheduling.py index 1eadbfb1..556f4e1d 100644 --- a/src/aerie_cli/commands/scheduling.py +++ b/src/aerie_cli/commands/scheduling.py @@ -24,9 +24,9 @@ def upload( choice = select_from_list(choices) if(choice == choices[0]): - plan_id = typer.prompt('Plan ID') + plan_id = int(typer.prompt('Plan ID')) else: - model_id = typer.prompt('Mission model ID to associate with the scheduling goal') + model_id = int(typer.prompt('Mission model ID to associate with the scheduling goal')) if(schedule is None): schedule = typer.prompt('Text file with one path on each line to a scheduling rule file, in decreasing priority order') @@ -66,14 +66,12 @@ def upload( client.add_goals_to_specifications(upload_to_spec) typer.echo(f"Assigned goals in priority order to plan ID {plan_id}.") else: - #get all plan ids from model id if no plan id is provided - all_plans_in_model = [p for p in all_plans_list if p.model_id == model_id] - - for plan in all_plans_in_model: + #upload to all plans within model + for plan in filter(lambda p: p.model_id == model_id, all_plans_list): plan_id = plan.id #each schedule goal needs own ID - add each goal for each plan resp = client.upload_scheduling_goals(upload_obj) - typer.echo(f"Uploaded scheduling goals to venue for plan ID ${plan_id}") + typer.echo(f"Uploaded scheduling goals to venue for plan ID {plan_id}") uploaded_ids = [kv["id"] for kv in resp] specification = client.get_specification_for_plan(plan_id)