-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move QueryData to TimeSeriesId logic out of Res1D into an adapter.
- Loading branch information
1 parent
a912c4c
commit 5540ec7
Showing
3 changed files
with
92 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from typing import List | ||
|
||
from ..res1d import Res1D | ||
from .query_data import QueryData | ||
|
||
from ..quantities import TimeSeriesId | ||
|
||
|
||
class QueryDataAdapter: | ||
"""Adapter class for converting QueryData TimeSeriesId. | ||
Parameters | ||
---------- | ||
query : QueryData | ||
Query object to adapt. | ||
""" | ||
|
||
def __init__(self, query: QueryData): | ||
self._query = query | ||
|
||
def to_timeseries_id(self, res1d: Res1D) -> TimeSeriesId: | ||
"""Convert query to timeseries id.""" | ||
self._validate_query_with_res1d(res1d) | ||
|
||
time_series_id = self._query.to_timeseries_id() | ||
|
||
if not time_series_id.is_valid(res1d): | ||
self._query._check_invalid_values(None) | ||
|
||
return time_series_id | ||
|
||
def _validate_query_with_res1d(self, res1d: Res1D): | ||
"""Validate query with res1d object.""" | ||
query = self._query | ||
|
||
query._update_query(res1d) | ||
query._check_invalid_quantity(res1d) | ||
|
||
@staticmethod | ||
def convert_queries_to_time_series_ids( | ||
res1d: Res1D, queries: list[QueryData] | ||
) -> List[TimeSeriesId]: | ||
""" | ||
Convert queries to TimeSeriesId objects. | ||
Parameters | ||
---------- | ||
res1d : Res1D | ||
Res1D object (required for query validation) | ||
queries : list[QueryData] | ||
List of query objects to convert. | ||
Returns | ||
------- | ||
List[TimeSeriesId] | ||
List of timeseries ids. | ||
""" | ||
return [QueryDataAdapter(query).to_timeseries_id(res1d) for query in queries] |
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