diff --git a/src/aerie_cli/commands/models.py b/src/aerie_cli/commands/models.py index 093c1376..ef339df8 100644 --- a/src/aerie_cli/commands/models.py +++ b/src/aerie_cli/commands/models.py @@ -111,4 +111,4 @@ def list(): ) console = Console() - console.print(table) + console.print(table) \ No newline at end of file diff --git a/src/aerie_cli/commands/plans.py b/src/aerie_cli/commands/plans.py index 1d5db0c3..172f395a 100644 --- a/src/aerie_cli/commands/plans.py +++ b/src/aerie_cli/commands/plans.py @@ -313,5 +313,4 @@ def clean(): for activity_plan in resp: client.delete_plan(activity_plan.id) - typer.echo(f"All activity plans have been deleted") - + typer.echo(f"All activity plans have been deleted") \ No newline at end of file diff --git a/src/aerie_cli/commands/scheduling.py b/src/aerie_cli/commands/scheduling.py index 0ccad565..cacd4804 100644 --- a/src/aerie_cli/commands/scheduling.py +++ b/src/aerie_cli/commands/scheduling.py @@ -1,24 +1,45 @@ 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", prompt=True + 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""" + """Upload scheduling goal to single plan or to all plans in a model""" + + 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(choice == choices[0]): + plan_id = int(typer.prompt('Plan ID')) + else: + 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') + 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: @@ -27,24 +48,37 @@ 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) - resp = client.upload_scheduling_goals(upload_obj) + if(plan_id is not None): + #uploading to single plan + resp = client.upload_scheduling_goals(upload_obj) - typer.echo(f"Uploaded scheduling goals to venue.") - - 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) - - 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"Uploaded scheduling goals to venue.") + + 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) + + 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: + #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}") + 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) + + typer.echo(f"Assigned goals in priority order to all plans with model ID {model_id}.") @app.command() def delete(