-
Notifications
You must be signed in to change notification settings - Fork 31
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 #448 from munrojm/main
Maggma API additions
- Loading branch information
Showing
21 changed files
with
1,216 additions
and
158 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
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,28 @@ | ||
from typing import Optional | ||
from maggma.api.query_operator import QueryOperator | ||
from maggma.api.utils import STORE_PARAMS | ||
from fastapi import HTTPException, Query | ||
|
||
|
||
class SortQuery(QueryOperator): | ||
""" | ||
Method to generate the sorting portion of a query | ||
""" | ||
|
||
def query( | ||
self, | ||
field: Optional[str] = Query(None, description="Field to sort with"), | ||
ascending: Optional[bool] = Query(None, description="Whether the sorting should be ascending",), | ||
) -> STORE_PARAMS: | ||
|
||
sort = {} | ||
|
||
if field and ascending is not None: | ||
sort.update({field: 1 if ascending else -1}) | ||
|
||
elif field or ascending is not None: | ||
raise HTTPException( | ||
status_code=400, detail="Must specify both a field and order for sorting.", | ||
) | ||
|
||
return {"sort": sort} |
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,49 @@ | ||
from typing import Optional | ||
from maggma.api.query_operator import QueryOperator | ||
from maggma.api.utils import STORE_PARAMS | ||
from fastapi import Query | ||
from datetime import datetime | ||
|
||
|
||
class SubmissionQuery(QueryOperator): | ||
""" | ||
Method to generate a query for submission data using status and datetime | ||
""" | ||
|
||
def __init__(self, status_enum): | ||
|
||
self.status_enum = status_enum | ||
|
||
def query( | ||
state: Optional[status_enum] = Query( | ||
None, description="Latest status of the submission" | ||
), | ||
last_updated: Optional[datetime] = Query( | ||
None, description="Minimum datetime of status update for submission", | ||
), | ||
) -> STORE_PARAMS: | ||
|
||
crit = {} # type: dict | ||
|
||
if state: | ||
s_dict = {"$expr": {"$eq": [{"$arrayElemAt": ["$state", -1]}, state.value]}} # type: ignore | ||
crit.update(s_dict) | ||
|
||
if last_updated: | ||
l_dict = { | ||
"$expr": { | ||
"$gt": [{"$arrayElemAt": ["$last_updated", -1]}, last_updated] | ||
} | ||
} | ||
crit.update(l_dict) | ||
|
||
if state and last_updated: | ||
crit = {"$and": [s_dict, l_dict]} | ||
|
||
return {"criteria": crit} | ||
|
||
self.query = query | ||
|
||
def query(self): | ||
" Stub query function for abstract class " | ||
pass |
Oops, something went wrong.