tspy.data_structures.observations.TRS module¶
-
class
tspy.data_structures.observations.TRS.
TRS
(tsc, granularity, start_time, j_trs=None)¶ Bases:
object
Time reference system (TRS) is a local, regional or global system used to identify time. A time reference system defines a specific projection for forward and reverse mapping between timestamp and its numeric representation. A common example that most of us are familiar with is UTC time, which maps a timestamp (Jan 1, 2019 12am midnight GMT) into a 64-bit integer value (1546300800000) that captures the number of milliseconds that have elapsed since Jan 1, 1970 12am (midnight) GMT. Generally speaking, the timestamp value is better suited for human readability, while the numeric representation is better suited for machine processing.
Notes
A timestamp is mapped into a numeric representation by computing the number of elapsed time-ticks since the offset. A numeric representation is scaled by the time-tick and shifted by the offset when it is mapped back to a timestamp.
forward + reverse projections may be lossy. For instance, if the true time granularity of a time-series is in seconds, then forward and reverse mapping of timestamps 9:00:01 and 9:00:02 (to be read as hh:mm:ss) to a time-tick of one minute would result in timestamps 9:00:00 and 9:00:00 (respectively). In this example a time-series whose granularity is in seconds is being mapped to minutes and thus the reverse mapping looses information. However, the mapped granularity is higher than the granularity of the input time-series (more specifically if the time-series granularity is an integral multiple of the mapped granularity) then the forward + reverse projection is guaranteed to be lossless. For example, mapping a time-series whose granularity is in minutes to seconds and reverse projecting it to minutes would result in lossless reconstruction of the timestamps.
By default, Granularity is one millisecond, and Start-Time is 1st Jan 1970 00:00:00
- Attributes
granularity
datetime.timedeltaReturns
start_time
datetimeReturns
Methods
to_index
(time)get the given millisecond long as a time-tick index
to_long_lower
(index)get the given time-tick as a millisecond long (lower bound)
to_long_upper
(index)get the given time-tick as a millisecond long (upper bound)
-
property
granularity
¶ - Returns
- granularitydatetime.timedelta
granularity that captures time-tick granularity (e.g., 1 minute)
-
property
start_time
¶ - Returns
- start_timedatetime
start-time that captures an offset (e.g., 1st Jan 2019 12am midnight US Eastern Daylight Savings Time) to the start time of the time-series)
-
to_index
(time)¶ get the given millisecond long as a time-tick index
- Parameters
- timeint or datetime
the time to convert to an index
- Returns
- int
a time-tick index
-
to_long_lower
(index)¶ get the given time-tick as a millisecond long (lower bound)
- Parameters
- indexint
the time-tick to convert
- Returns
- int
a millisecond long
-
to_long_upper
(index)¶ get the given time-tick as a millisecond long (upper bound)
- Parameters
- indexint
the time-tick to convert
- Returns
- int
a millisecond long