Source code for kappa_sdk.enumerator.data_enumeration
from datetime import datetime, timezone
from typing import List, Iterator
from .data_enumerator_point import DataEnumeratorPoint
from .data_point import DataPoint
from ..vector import Vector
[docs]
class DataEnumeration(list): # type: ignore[type-arg]
""" Result produced by the :class:`DataEnumerator`.
Inherited from the list, it allows iterating over a list of :class:`DataEnumeratorPoint`, and also contains the last common date of data enumeration inputs.
.. note:: Should not be instantiated directly.
"""
def __init__(self, vectors: List[Vector], last_points: List[DataPoint]) -> None:
points = [DataEnumeratorPoint(vectors[0].dates[i], [vector.values[i] for vector in vectors]) for i in range(0, len(vectors[0].dates))]
super().__init__(points)
self.__last_points: List[DataPoint] = last_points
self.__last_common_date = min(p.date for p in self.__last_points) if len(self.__last_points) > 0 else datetime.min.replace(tzinfo=timezone.utc)
self.__vectors: List[Vector] = vectors
def __iter__(self) -> Iterator[DataEnumeratorPoint]:
return iter(list.__iter__(self))
@property
def last_points(self) -> List[DataPoint]:
"""
Returns the last points of the enumerated inputs.
"""
return self.__last_points
@property
def last_common_date(self) -> datetime:
"""
Returns the last common date of the enumerated inputs.
"""
return self.__last_common_date
@property
def vectors(self) -> List[Vector]:
"""
Returns the enumeration values as :class: 'Vector'
"""
return self.__vectors