Skip to content

Commit

Permalink
Merge pull request #1568 from NASA-AMMOS/fix/save-activity-names
Browse files Browse the repository at this point in the history
Save activity names from procedural goals
  • Loading branch information
dandelany authored Oct 2, 2024
2 parents b4cc768 + 4328d4b commit 06bad80
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1156,5 +1156,22 @@ void executeEDSLAndProcedure() throws IOException {

assertEquals(52, activities.size());
}

/**
* Run a spec with one procedure and make sure the activity names are saved to the database
*/
@Test
void saveActivityName() throws IOException {
final var args = Json.createObjectBuilder().add("quantity", 2).build();
hasura.updateSchedulingSpecGoalArguments(procedureId.invocationId(), args);

final var resp = hasura.awaitScheduling(specId);

final var plan = hasura.getPlan(planId);
final var activities = plan.activityDirectives();

assertEquals(2, activities.size());
assertEquals("It's a bite banana activity", activities.getFirst().name());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ public record Plan(
int revision,
List<ActivityDirective> activityDirectives
) {
public record ActivityDirective(int id, int planId, String type, String startOffset, JsonObject arguments) {
public record ActivityDirective(int id, int planId, String type, String startOffset, JsonObject arguments, String name) {
public static ActivityDirective fromJSON(JsonObject json){
return new ActivityDirective(
json.getInt("id"),
json.getInt("plan_id"),
json.getString("type"),
json.getString("startOffset"),
json.getJsonObject("arguments"));
json.getJsonObject("arguments"),
json.getString("name")
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ query GetPlan($id: Int!) {
plan_id
startOffset: start_offset
type
name
}
constraint_specification {
constraint_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import gov.nasa.ammos.aerie.procedural.scheduling.plan.EditablePlan;
import gov.nasa.ammos.aerie.procedural.scheduling.Goal;
import gov.nasa.ammos.aerie.procedural.scheduling.annotations.SchedulingProcedure;
import gov.nasa.ammos.aerie.procedural.scheduling.plan.NewDirective;
import gov.nasa.ammos.aerie.procedural.timeline.payloads.activities.AnyDirective;
import gov.nasa.jpl.aerie.merlin.protocol.types.Duration;
import gov.nasa.ammos.aerie.procedural.timeline.payloads.activities.DirectiveStart;
import org.jetbrains.annotations.NotNull;
Expand All @@ -19,9 +21,12 @@ public void run(@NotNull final EditablePlan plan) {
var currentTime = firstTime;
for (var i = 0; i < quantity; i++) {
plan.create(
"BiteBanana",
new DirectiveStart.Absolute(currentTime),
Map.of()
new NewDirective(
new AnyDirective(Map.of()),
"It's a bite banana activity",
"BiteBanana",
new DirectiveStart.Absolute(currentTime)
)
);
currentTime = currentTime.plus(step);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public record SchedulingActivity(
ActivityDirectiveId topParent,
ActivityDirectiveId anchorId,
boolean anchoredToStart,
boolean isNew
boolean isNew,
String name
) {

public static SchedulingActivity of(
Expand All @@ -62,7 +63,8 @@ public static SchedulingActivity of(
null,
anchorId,
anchoredToStart,
isNew
isNew,
null
);
}

Expand All @@ -86,12 +88,13 @@ public static SchedulingActivity of(
topParent,
anchorId,
anchoredToStart,
isNew
isNew,
null
);
}

public SchedulingActivity withNewDuration(Duration duration){
return SchedulingActivity.of(
return new SchedulingActivity(
this.id,
this.type,
this.startOffset,
Expand All @@ -100,12 +103,13 @@ public SchedulingActivity withNewDuration(Duration duration){
this.topParent,
this.anchorId,
this.anchoredToStart,
this.isNew()
this.isNew(),
this.name
);
}

public SchedulingActivity withNewAnchor(ActivityDirectiveId anchorId, boolean anchoredToStart, Duration startOffset) {
return SchedulingActivity.of(
return new SchedulingActivity(
this.id,
this.type,
startOffset,
Expand All @@ -114,12 +118,13 @@ public SchedulingActivity withNewAnchor(ActivityDirectiveId anchorId, boolean an
this.topParent,
anchorId,
anchoredToStart,
this.isNew
this.isNew,
this.name
);
}

public SchedulingActivity withNewDirectiveId(ActivityDirectiveId id) {
return SchedulingActivity.of(
return new SchedulingActivity(
id,
this.type,
startOffset,
Expand All @@ -128,12 +133,13 @@ public SchedulingActivity withNewDirectiveId(ActivityDirectiveId id) {
this.topParent,
this.anchorId,
this.anchoredToStart,
this.isNew
this.isNew,
this.name
);
}

public SchedulingActivity withNewTopParent(ActivityDirectiveId topParent) {
return SchedulingActivity.of(
return new SchedulingActivity(
this.id,
this.type,
startOffset,
Expand All @@ -142,12 +148,13 @@ public SchedulingActivity withNewTopParent(ActivityDirectiveId topParent) {
topParent,
this.anchorId,
this.anchoredToStart,
this.isNew
this.isNew,
this.name
);
}

public static SchedulingActivity fromExistingActivityDirective(ActivityDirectiveId id, ActivityDirective activity, ActivityType type, Duration duration){
return SchedulingActivity.of(
return new SchedulingActivity(
id,
type,
activity.startOffset(),
Expand All @@ -156,7 +163,8 @@ public static SchedulingActivity fromExistingActivityDirective(ActivityDirective
null,
activity.anchorId(),
activity.anchoredToStart(),
false
false,
null
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,8 @@ public Duration valueAt(Duration start, final EquationSolvingAlgorithms.History<
null,
null,
true,
true
true,
null
);
Duration computedDuration = null;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ data class InMemoryEditablePlan(
is DirectiveStart.Absolute -> true
is DirectiveStart.Anchor -> s.anchorPoint == DirectiveStart.Anchor.AnchorPoint.Start
},
isNew
isNew,
name
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,8 @@ mutation createAllPlanActivityDirectives($activities: [activity_directive_insert
.add("start_offset", act.startOffset().toString())
.add("anchored_to_start", act.anchoredToStart());

if (act.name() != null) insertionObject = insertionObject.add("name", act.name());

//add duration to parameters if controllable
final var insertionObjectArguments = Json.createObjectBuilder();
if(act.getType().getDurationType() instanceof DurationType.Controllable durationType){
Expand Down

0 comments on commit 06bad80

Please sign in to comment.