-
Notifications
You must be signed in to change notification settings - Fork 0
Added sorting functionality #767
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
Changes from all commits
f137f6b
4597ee8
27a5131
d955cd4
33bf821
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,10 +8,12 @@ | |
|
||
import typing | ||
import http | ||
import json | ||
|
||
import pydantic | ||
|
||
from simvue.api.objects.alert.user import UserAlert | ||
from simvue.api.objects.base import Sort | ||
from simvue.api.request import get_json_from_response | ||
from simvue.api.request import get as sv_get | ||
from .events import EventsAlert | ||
|
@@ -21,6 +23,15 @@ | |
AlertType = EventsAlert | UserAlert | MetricsThresholdAlert | MetricsRangeAlert | ||
|
||
|
||
class AlertSort(Sort): | ||
@pydantic.field_validator("column") | ||
@classmethod | ||
def check_column(cls, column: str) -> str: | ||
if column and column not in ("name", "created"): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be really useful to have a column which sorts by time set to critical, no idea if thats possible |
||
raise ValueError(f"Invalid sort column for alerts '{column}'") | ||
return column | ||
|
||
|
||
class Alert: | ||
"""Generic Simvue alert retrieval class""" | ||
|
||
|
@@ -50,11 +61,13 @@ def __new__(cls, identifier: str, **kwargs) -> AlertType: | |
raise RuntimeError(f"Unknown source type '{_alert_pre.source}'") | ||
|
||
@classmethod | ||
@pydantic.validate_call | ||
def get( | ||
cls, | ||
offline: bool = False, | ||
count: int | None = None, | ||
offset: int | None = None, | ||
sorting: list[AlertSort] | None = None, | ||
**kwargs, | ||
) -> typing.Generator[tuple[str, AlertType], None, None]: | ||
"""Fetch all alerts from the server for the current user. | ||
|
@@ -65,6 +78,8 @@ def get( | |
limit the number of results, default of None returns all. | ||
offset : int, optional | ||
start index for returned results, default of None starts at 0. | ||
sorting : list[dict] | None, optional | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not really clear what this would be, what does each item in the list correspond to? Wouldnt you just want one sorting parameter for all the things youre getting? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the low level API so just mirrors the RestAPI which expects a list in the form |
||
list of sorting definitions in the form {'column': str, 'descending': bool} | ||
|
||
Yields | ||
------ | ||
|
@@ -80,11 +95,15 @@ def get( | |
|
||
_class_instance = AlertBase(_local=True, _read_only=True) | ||
_url = f"{_class_instance._base_url}" | ||
_params: dict[str, int | str] = {"start": offset, "count": count} | ||
|
||
if sorting: | ||
_params["sorting"] = json.dumps([sort.to_params() for sort in sorting]) | ||
|
||
_response = sv_get( | ||
_url, | ||
headers=_class_instance._headers, | ||
params={"start": offset, "count": count} | kwargs, | ||
params=_params | kwargs, | ||
) | ||
|
||
_label: str = _class_instance.__class__.__name__.lower() | ||
|
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.
Wait what is this? You can delay the start of an alert?
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.
If that's the case then we should also add this functionality into the Run class in another MR :)
Uh oh!
There was an error while loading. Please reload this page.
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.
Not sure, this is just a value available in the RestAPI response, @alahiff ?