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 all 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
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")
76 changes: 55 additions & 21 deletions src/aerie_cli/commands/scheduling.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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(
Expand Down