tspy.data_structures.observations.ObservationCollection module¶
-
class
tspy.data_structures.observations.ObservationCollection.ObservationCollection(tsc, j_observations=None)¶ Bases:
objectA special form of materialized time-series (sorted collection) whose values are of type
Observation.An observation-collection has the following properties:
Sorted by observation time-tick
Support for observations with duplicate time-ticks
Duplicate time-ticks will keep ordering
Examples
create an observation-collection
>>> import tspy >>> ts_builder = tspy.builder() >>> ts_builder.add(tspy.observation(1,1)) >>> ts_builder.add(tspy.observation(2,2)) >>> ts_builder.add(tspy.observation(1,3)) >>> observations = ts_builder.result() >>> observations [(1,1),(1,3),(2,2)]
iterate through this collection
>>> for o in observations: ...print(o.time_tick, ",", o.value) 1 , 1 1 , 3 2 , 2
Methods
Java()mapping to a compatible class in Java via Py4J
ceiling(time_tick)get the ceiling observation for the given time-tick.
contains(time_tick)Checks for containment of time-tick within the collection
first()get the first observation in this collection.
floor(time_tick)get the floor observation for the given time-tick.
higher(time_tick)get the higher observation for the given time-tick.
is_empty()checks if there is any observation
last()get the last observation in this collection.
lower(time_tick)get the lower observation for the given time-tick.
to_time_series([granularity, start_time])convert this collection to a time-series
-
class
Java¶ Bases:
objectmapping to a compatible class in Java via Py4J
-
implements= ['com.ibm.research.time_series.core.utils.ObservationCollection']¶
-
-
ceiling(time_tick)¶ get the ceiling observation for the given time-tick. The ceiling is defined as the the observation which bares the same time-tick as the given time-tick, or if one does not exist, the next higher observation. If no such observation exists that satisfies these arguments, in the collection, None will be returned.
- Parameters
- time_tickint
the time-tick
- Returns
Observationthe ceiling observation
-
contains(time_tick)¶ Checks for containment of time-tick within the collection
- Parameters
- time_tickint
the time-tick
- Returns
- bool
True if an observation in this collection has the given time-tick, otherwise False
-
first()¶ get the first observation in this collection. The first observation is that observation which has the lowest timestamp in the collection. If 2 observations have the same timestamp, the first observation that was in the collection will be the one returned.
- Returns
Observationthe first observation in this collection
-
floor(time_tick)¶ get the floor observation for the given time-tick. The floor is defined as the the observation which bares the same time-tick as the given time-tick, or if one does not exist, the next lower observation. If no such observation exists that satisfies these arguments, in the collection, None will be returned.
- Parameters
- time_tickint
the time-tick
- Returns
Observationthe floor observation
-
higher(time_tick)¶ get the higher observation for the given time-tick. The higher is defined as the the observation which bares a time-tick greater than the given time-tick. If no such observation exists that satisfies these arguments, in the collection, None will be returned.
- Parameters
- time_tickint
the time-tick
- Returns
Observationthe floor observation
-
is_empty()¶ checks if there is any observation
- Returns
- bool
True if no observations exist in this collection, otherwise False
-
last()¶ get the last observation in this collection. The last observation is that observation which has the highest timestamp in the collection. If 2 observations have the same timestamp, the last observation that was in the collection will be the one returned.
- Returns
Observationthe last observation in this collection
-
lower(time_tick)¶ get the lower observation for the given time-tick. The lower is defined as the the observation which bares a time-tick less than the given time-tick. If no such observation exists that satisfies these arguments, in the collection, None will be returned.
- Parameters
- time_tickint
the time-tick
- Returns
Observationthe floor observation
-
property
size¶ - Returns
- int
the number of observations in this collection
-
to_time_series(granularity=None, start_time=None)¶ convert this collection to a time-series
- Parameters
- granularitydatetime.timedelta, optional
the granularity for use in time-series
TRS(default is None if no start_time, otherwise 1ms)- start_timedatetime, optional
the starting date-time of the time-series (default is None if no granularity, otherwise 1970-01-01 UTC)
- Returns
TimeSeriesa new time-series
-
property
trs¶ - Returns
- TRS
TRS this time-series time-reference-system
- TRS