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

[monitorlib] Clean up geotemporal business objects #316

Merged

Conversation

BenjaminPelletier
Copy link
Member

@BenjaminPelletier BenjaminPelletier commented Nov 4, 2023

This PR works on cleaning up our geotemporal business objects. Doing this will hopefully make things easier and clearer going forward. The main changes are:

  • Split purely-temporal objects out of geotemporal.py into temporal.py
  • Move method-like functions into methods of the class they are acting on (e.g., resolve_volume4d)
  • Change TCollections to inherit from List[T] rather than having a dict wrapper (e.g., Volume4DCollection, Volume4DTemplateCollection)
  • Use Time business objects instead of datetime for temporal routines and data structures

Regarding the TCollections, ImplicitDict's jsonschema generation doesn't currently support types that inherit non-dict types whose schema can be defined (e.g., class Volume4DCollection(List[Volume4D]):). This is fixed in this PR, but in the mean time, the JSON Schema will still work, they just won't describe the content in those classes. I suggest that it's worth moving forward with this cleanup before fixing the jsonschema generation, and fixing jsonschema generation can be a follow-on task. When that fix is incorporated, the constructors of the two TCollection objects in this PR can be removed.

@BenjaminPelletier BenjaminPelletier marked this pull request as ready for review November 4, 2023 01:58
Copy link
Contributor

@mickmis mickmis left a comment

Choose a reason for hiding this comment

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

Nice improvement!

Comment on lines +225 to +230
def __init__(self, iterator: Iterator[dict]):
parsed_values = [
v if isinstance(v, Volume4D) else ImplicitDict.parse(v, Volume4D)
for v in iterator
]
super(Volume4DCollection, self).__init__(parsed_values)
Copy link
Contributor

Choose a reason for hiding this comment

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

Neat :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, but actually this constructor code will go away with this fix :)


@property
def rect_bounds(self) -> s2sphere.LatLngRect:
if not self.volumes:
if not self:
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Is this meant to catch the case where the collection is an empty list? If so I find it more explicit to use len(self) == 0, as I don't believe there should another case where self evaluates as False

Copy link
Member Author

Choose a reason for hiding this comment

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

Checking emptiness with if not x is Pythonic per PEP8 ("For sequences, (strings, lists, tuples), use the fact that empty sequences are false"), but I agree in many cases, and in one or two instances, I've been bitten by the fact that checking this way does not always work properly in combination with other checks. So, I use both methods depending on the circumstance.

@BenjaminPelletier BenjaminPelletier merged commit 079c92b into interuss:main Nov 7, 2023
8 checks passed
@BenjaminPelletier BenjaminPelletier deleted the clean-up-geotemporal branch November 7, 2023 15:03
github-actions bot added a commit that referenced this pull request Nov 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants