Skip to content

Commit

Permalink
Allow lists in event query
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelCourtney authored and pranav-super committed Nov 4, 2024
1 parent 03dd1e1 commit de18d9f
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package gov.nasa.ammos.aerie.procedural.examples.fooprocedures.procedures;

import gov.nasa.ammos.aerie.procedural.scheduling.annotations.SchedulingProcedure;
import gov.nasa.ammos.aerie.procedural.scheduling.Goal;
import gov.nasa.ammos.aerie.procedural.scheduling.plan.EditablePlan;
import gov.nasa.ammos.aerie.procedural.timeline.payloads.activities.DirectiveStart;
import gov.nasa.jpl.aerie.merlin.protocol.types.SerializedValue;
import org.jetbrains.annotations.NotNull;

import java.util.Map;

@SchedulingProcedure
public record ExternalEventsTest() implements Goal {
@Override
public void run(@NotNull final EditablePlan plan) {
for (final var e: plan.events("Derivation Test Default")) {
plan.create("BiteBanana", new DirectiveStart.Absolute(e.getInterval().start), Map.of("biteSize", SerializedValue.of(1)));
}

plan.commit();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,31 @@ package gov.nasa.ammos.aerie.procedural.timeline.plan

/** Fields for filtering events as they are queried. */
data class EventQuery(
/** The derivation group the events belong to. */
val derivationGroup: String?,
/**
* A nullable list of derivation groups; the event must belong to one of them if present.
*
* If null, all derivation groups are allowed.
*/
val derivationGroups: List<String>?,

/** The event type to query for. */
val type: String?,
/**
* A nullable list of types; the event must belong to one of them if present.
*
* If null, all types are allowed.
*/
val types: List<String>?,

/** The event source the event came from. */
val source: String?,
)
/**
* A nullable list of sources; the event must belong to one of them if present.
*
* If null, all sources are allowed.
*/
val sources: List<String>?,
) {
constructor(derivationGroup: String?, type: String?, source: String?): this(
derivationGroup?.let { listOf(it) },
type?.let { listOf(it) },
source?.let { listOf(it) }
)
constructor(): this(null as String?, null, null)
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ interface Plan {
/** Get external events belonging to a given derivation group associated with this plan. */
fun events(derivationGroup: String) = events(EventQuery(derivationGroup, null, null))
/** Get all external events in all derivation groups associated with this plan. */
fun events() = events(EventQuery(null, null, null))
fun events() = events(EventQuery())
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@ data class SchedulerToProcedurePlanAdapter(
}

override fun events(query: EventQuery): ExternalEvents {
var result = if (query.derivationGroup != null) eventsByDerivationGroup[query.derivationGroup]
?: throw Error("derivation group either doesn't exist or isn't associated with plan: ${query.derivationGroup}")
var result = if (query.derivationGroups != null) query.derivationGroups!!.flatMap {
eventsByDerivationGroup[it]
?: throw Error("derivation group either doesn't exist or isn't associated with plan: $it")
}
else eventsByDerivationGroup.values.flatten()
if (query.type != null) result = result.filter { it.type == query.type }
if (query.source != null) result = result.filter { it.source == query.source }
if (query.types != null) result = result.filter { it.type in query.types!! }
if (query.sources != null) result = result.filter { it.source in query.sources!! }
return ExternalEvents(result)
}
override fun <V : Any, TL : SerialSegmentOps<V, TL>> resource(
Expand Down

0 comments on commit de18d9f

Please sign in to comment.