generated from MinBZK/python-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4d68d9a
commit 376c8f7
Showing
26 changed files
with
14,567 additions
and
206 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import logging | ||
from collections.abc import Sequence | ||
|
||
from amt.clients.clients import TaskRegistryAPIClient, TaskType | ||
from amt.core.exceptions import AMTNotFound | ||
from amt.schema.measure import Measure | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class MeasuresService: | ||
def __init__(self) -> None: | ||
self.client = TaskRegistryAPIClient() | ||
|
||
def fetch_measures(self, urns: str | Sequence[str] | None = None) -> list[Measure]: | ||
""" | ||
This functions returns measures with given URN's. If urns contains an URN that is not a | ||
valid URN of an measure it is simply ignored. | ||
@param: URN's of measures to fetch. If empty, function returns all measures. | ||
@return: List of measures with given URN's in 'urns'. | ||
""" | ||
|
||
if isinstance(urns, str): | ||
urns = [urns] | ||
|
||
all_valid_urns = self.fetch_urns() | ||
|
||
if urns is None: | ||
return [Measure(**self.client.get_task_by_urn(TaskType.MEASURES, urn)) for urn in all_valid_urns] | ||
|
||
measures: list[Measure] = [] | ||
for urn in urns: | ||
try: | ||
logger.info(f"adding measure with URN {urn}") | ||
measures.append(Measure(**self.client.get_task_by_urn(TaskType.MEASURES, urn))) | ||
except AMTNotFound: | ||
logger.warning(f"cannot find measure with URN {urn}") | ||
|
||
return measures | ||
|
||
def fetch_urns(self) -> list[str]: | ||
""" | ||
Fetches all valid measure URN's. | ||
""" | ||
content_list = self.client.get_list_of_task(TaskType.MEASURES) | ||
return [content.urn for content in content_list.root] |
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,47 @@ | ||
import logging | ||
from collections.abc import Sequence | ||
|
||
from amt.clients.clients import TaskRegistryAPIClient, TaskType | ||
from amt.core.exceptions import AMTNotFound | ||
from amt.schema.requirement import Requirement | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class RequirementsService: | ||
def __init__(self) -> None: | ||
self.client = TaskRegistryAPIClient() | ||
|
||
def fetch_requirements(self, urns: str | Sequence[str] | None = None) -> list[Requirement]: | ||
""" | ||
This functions returns requirement with given URN's. If urns contains an URN that is not a | ||
valid URN of an requirement it is simply ignored. | ||
@param: URN's of requirements to fetch. If empty, function returns all requirements. | ||
@return: List of requirements with given URN's in 'urns'. | ||
""" | ||
|
||
if isinstance(urns, str): | ||
urns = [urns] | ||
|
||
all_valid_urns = self.fetch_urns() | ||
|
||
if urns is None: | ||
return [Requirement(**self.client.get_task_by_urn(TaskType.REQUIREMENTS, urn)) for urn in all_valid_urns] | ||
|
||
requirements: list[Requirement] = [] | ||
for urn in urns: | ||
try: | ||
requirements.append(Requirement(**self.client.get_task_by_urn(TaskType.REQUIREMENTS, urn))) | ||
except AMTNotFound: | ||
logger.warning(f"cannot find instrument with URN {urn}") | ||
|
||
return requirements | ||
|
||
|
||
def fetch_urns(self) -> list[str]: | ||
""" | ||
Fetches all valid requirement URN's. | ||
""" | ||
content_list = self.client.get_list_of_task(TaskType.REQUIREMENTS) | ||
return [content.urn for content in content_list.root] |
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
Oops, something went wrong.