-
Notifications
You must be signed in to change notification settings - Fork 1
Add Maximum Size for Metrics #916
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c90f22d
✨ Added threshold definition capability to dispatcher
kzscisoft b065616
Added additional tests and fixed inconsistency across dispatchers
kzscisoft 43c6133
Fix base class structure for dispatch.add_item
kzscisoft 8a93b9c
Fixed non-explicit arguments in inherited add_item for dispatch
kzscisoft 5285015
Lower grid limit to 50k
kzscisoft 6a24696
Improved docstrings
kzscisoft 79aae2d
Merge branch 'dev' into feature/metric-size-limit
kzscisoft 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 hidden or 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 hidden or 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,103 @@ | ||
| import threading | ||
| import abc | ||
| import typing | ||
|
|
||
| from simvue.exception import ObjectDispatchError | ||
|
|
||
|
|
||
| class DispatcherBaseClass(abc.ABC): | ||
| """Base class to all dispatchers. | ||
|
|
||
| A dispatcher is an object which sends data to a location, | ||
| in this case it executes a callback based on criteria. | ||
| """ | ||
|
|
||
| def __init__( | ||
| self, | ||
| *, | ||
| callback: typing.Callable[[list[typing.Any], str], None], | ||
| object_types: list[str], | ||
| termination_trigger: threading.Event, | ||
| thresholds: dict[str, int | float] | None = None, | ||
| ) -> None: | ||
| """Initialise a dispatcher. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| callback : Callable[[list[Any]], str] | None | ||
| callback to execute on data. | ||
| object_types : list[str] | ||
| categories of items for separate handling | ||
| termination_trigger : Event | ||
| trigger for closing this dispatcher | ||
| thresholds : dict[str, int | float] | None, optional | ||
| any additional thresholds to consider when handling items. | ||
| This assumes metadata defining the values to compare to | ||
| such thresholds is included when appending. | ||
| """ | ||
| super().__init__() | ||
| self._thresholds: dict[str, int | float] = thresholds or {} | ||
| self._object_types: list[str] = object_types | ||
| self._termination_trigger = termination_trigger | ||
| self._callback = callback | ||
|
|
||
| def add_item( | ||
| self, | ||
| item: typing.Any, | ||
| *, | ||
| object_type: str, | ||
| metadata: dict[str, int | float] | None = None, | ||
| **__, | ||
| ) -> None: | ||
| """Add an item to the dispatcher. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| item : Any | ||
| item to add to dispatch | ||
| object_type : str | ||
| category of item | ||
| metadata : dict[str, int | float] | None, optional | ||
| additional metadata relating to the item to be | ||
| used for threshold comparisons | ||
| """ | ||
| _ = item | ||
| _ = object_type | ||
| if not metadata: | ||
| return | ||
| for key, threshold in self._thresholds.items(): | ||
| if key in metadata and metadata[key] > threshold: | ||
| raise ObjectDispatchError( | ||
| label=key, threshold=threshold, value=metadata[key] | ||
| ) | ||
|
|
||
| @abc.abstractmethod | ||
| def run(self) -> None: | ||
| """Start the dispatcher.""" | ||
| pass | ||
|
|
||
| @abc.abstractmethod | ||
| def start(self) -> None: | ||
| """Not used, this allows the class to be similar to a thread.""" | ||
| pass | ||
|
|
||
| @abc.abstractmethod | ||
| def join(self) -> None: | ||
| """Not used, this allows the class to be similar to a thread.""" | ||
| pass | ||
|
|
||
| @abc.abstractmethod | ||
| def purge(self) -> None: | ||
| """Clear the dispatcher of items.""" | ||
| pass | ||
|
|
||
| @abc.abstractmethod | ||
| def is_alive(self) -> bool: | ||
| """Whether the dispatcher is operating correctly.""" | ||
| pass | ||
|
|
||
| @property | ||
| @abc.abstractmethod | ||
| def empty(self) -> bool: | ||
| """Whether the dispatcher is empty.""" | ||
| pass | ||
This file contains hidden or 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 hidden or 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 hidden or 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.