Skip to content
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

Ability to Upload Scheduling Goals to All Plans with Mission Model ID #70

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/aerie_cli/aerie_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,20 @@ 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_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 = """
Expand Down
2 changes: 1 addition & 1 deletion src/aerie_cli/commands/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,4 @@ def list():
)

console = Console()
console.print(table)
console.print(table)
3 changes: 1 addition & 2 deletions src/aerie_cli/commands/plans.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
36 changes: 25 additions & 11 deletions src/aerie_cli/commands/scheduling.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
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=True
help="Plan ID (optional)", default=-1, prompt=True #how to make this optional
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the user still be prompted for the plan-id if it's now optional?

Right now, I still have it prompting the user for the plan-id, but if the user does not input anything and skips past it, then the default value is -1 (not a valid plan-id).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need to set prompt to False. IMO, the intuitive interface here would be to specify either the Plan ID or a Model ID, but not both, and throw an error if the user specifies both. If you want to preserve some sort of prompts, you can manually implement the logic with a menu (i.e., prompt the user to select whether they upload to a single plan or all plans for a given model). I have a utility that should make this easier.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the Model ID is used within the the scheduling upload object, so I'm not sure if model id still needs to be an input when there is also a plan id. I could also query the model ID from the plan ID in order to assert that both are not inputted.
I will still make a selection menu so the user knows the two options and set both model id and plan id prompts to False.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point -- yeah, you should be able to get the model ID from the plan ID (using the same list_all_activity_plans method as below, if you want).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to not throw an error when both model id and plan id are inputted. I added a check if the model id is not inputted, then I find the model id from list_all_activity_plans.
I’m also making a couple checks to ensure the inputs that are needed are there using the select_from_list method. I set the schedule prompt to False to keep it consistent with the other inputs so they all inputs are prompted together.

),
schedule: str = typer.Option(
..., help="Text file with one path on each line to a scheduling rule file, in decreasing priority order", prompt=True
Expand All @@ -29,22 +29,36 @@ 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]

#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)
#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]
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 = client.get_all_activity_plans_by_model(model_id)

client.add_goals_to_specifications(upload_to_spec)
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]

typer.echo(f"Assigned goals in priority order to plan ID {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)

typer.echo(f"Assigned goals in priority order to all plans with model ID {model_id}.")

@app.command()
def delete(
Expand Down