-
Notifications
You must be signed in to change notification settings - Fork 19
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
[uss_qualifier] Use FlightInfoTemplate for flight intent storage #276
Merged
BenjaminPelletier
merged 4 commits into
interuss:main
from
BenjaminPelletier:flight-intent-storage
Oct 24, 2023
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
bbe174d
Use FlightInfoTemplate for flight intent storage
BenjaminPelletier 2aaaaa3
Merge branch 'main' into flight-intent-storage
BenjaminPelletier 50e1253
Address comments
BenjaminPelletier ee8e224
Merge remote-tracking branch 'interuss/main' into flight-intent-storage
BenjaminPelletier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 6 additions & 64 deletions
70
monitoring/uss_qualifier/resources/flight_planning/flight_intents_resource.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,27 @@ | ||
from datetime import timedelta | ||
import json | ||
from typing import Dict | ||
|
||
import arrow | ||
from implicitdict import ImplicitDict, StringBasedDateTime | ||
from implicitdict import ImplicitDict | ||
from monitoring.monitorlib.clients.flight_planning.flight_info_template import ( | ||
FlightInfoTemplate, | ||
) | ||
|
||
from monitoring.uss_qualifier.resources.files import load_dict | ||
from monitoring.uss_qualifier.resources.overrides import apply_overrides | ||
from monitoring.uss_qualifier.resources.resource import Resource | ||
from monitoring.uss_qualifier.resources.flight_planning.flight_intent import ( | ||
FlightIntentCollection, | ||
FlightIntentsSpecification, | ||
FlightIntent, | ||
FlightIntentID, | ||
) | ||
|
||
|
||
class FlightIntentsResource(Resource[FlightIntentsSpecification]): | ||
_planning_time: timedelta | ||
_intent_collection: FlightIntentCollection | ||
|
||
def __init__(self, specification: FlightIntentsSpecification): | ||
self._intent_collection = ImplicitDict.parse( | ||
load_dict(specification.file), FlightIntentCollection | ||
) | ||
self._planning_time = specification.planning_time.timedelta | ||
|
||
def get_flight_intents(self) -> Dict[FlightIntentID, FlightIntent]: | ||
"""Resolve the underlying delta flight intents and shift appropriately times.""" | ||
|
||
# process intents in order of dependency to resolve deltas | ||
processed_intents: Dict[FlightIntentID, FlightIntent] = {} | ||
unprocessed_intent_ids = list(self._intent_collection.intents.keys()) | ||
|
||
while unprocessed_intent_ids: | ||
nb_processed = 0 | ||
for intent_id in unprocessed_intent_ids: | ||
unprocessed_intent = self._intent_collection.intents[intent_id] | ||
processed_intent: FlightIntent | ||
|
||
# copy intent and resolve delta | ||
if unprocessed_intent.has_field_with_value("full"): | ||
processed_intent = ImplicitDict.parse( | ||
json.loads(json.dumps(unprocessed_intent.full)), FlightIntent | ||
) | ||
elif unprocessed_intent.has_field_with_value("delta"): | ||
if unprocessed_intent.delta.source not in processed_intents: | ||
# delta source has not been processed yet | ||
continue | ||
|
||
processed_intent = apply_overrides( | ||
processed_intents[unprocessed_intent.delta.source], | ||
unprocessed_intent.delta.mutation, | ||
) | ||
else: | ||
raise ValueError(f"{intent_id} is invalid") | ||
|
||
nb_processed += 1 | ||
processed_intents[intent_id] = processed_intent | ||
unprocessed_intent_ids.remove(intent_id) | ||
|
||
if nb_processed == 0 and unprocessed_intent_ids: | ||
raise ValueError( | ||
"Unresolvable dependency detected between intents: " | ||
+ ", ".join(i_id for i_id in unprocessed_intent_ids) | ||
) | ||
|
||
# shift times | ||
t0 = arrow.utcnow() + self._planning_time | ||
|
||
for intent_id, intent in processed_intents.items(): | ||
dt = t0 - intent.reference_time.datetime | ||
for volume in ( | ||
intent.request.operational_intent.volumes | ||
+ intent.request.operational_intent.off_nominal_volumes | ||
): | ||
volume.time_start.value = StringBasedDateTime( | ||
volume.time_start.value.datetime + dt | ||
) | ||
volume.time_end.value = StringBasedDateTime( | ||
volume.time_end.value.datetime + dt | ||
) | ||
|
||
return processed_intents | ||
def get_flight_intents(self) -> Dict[FlightIntentID, FlightInfoTemplate]: | ||
return self._intent_collection.resolve() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks; done