-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #970 from JGreenlee/faster_localdate_queries
for yyyy_mm_dd metrics, query by fmt_time instead of local_dt
- Loading branch information
Showing
6 changed files
with
97 additions
and
70 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from builtins import object | ||
|
||
class FmtTimeQuery(object): | ||
""" | ||
Object that encapsulates a query for an inclusive range between two ISO-format strings. | ||
Useful for querying based on the local date/time at which data was collected, | ||
like with timeType of "data.fmt_time" or "data.start_fmt_time". | ||
e.g. FmtTimeQuery("data.fmt_time", "2024-01", "2024-03") # first quarter of 2024 | ||
e.g. FmtTimeQuery("data.fmt_time", "2024-05-01", "2024-05-31") # all of May 2024 | ||
e.g. FmtTimeQuery("data.fmt_time", "2024-06-03T08:00", "2024-06-03T16:59") # work hours on Jun 3 2024 | ||
""" | ||
def __init__(self, timeType: str, startIso: str, endIso: str) -> None: | ||
self.timeType = timeType | ||
self.startIso = startIso | ||
# append 'Z' to make the end range inclusive | ||
# (because Z is greater than any other character that can appear in an ISO string) | ||
self.endIso = endIso + 'Z' | ||
|
||
def get_query(self) -> dict: | ||
time_key = self.timeType | ||
ret_query = {time_key: {"$lte": self.endIso}} | ||
if (self.startIso is not None): | ||
ret_query[time_key].update({"$gte": self.startIso}) | ||
return ret_query | ||
|
||
def __repr__(self) -> str: | ||
return f"FmtTimeQuery {self.timeType} with range [{self.startIso}, {self.endIso})" |
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