## Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending#""" This module provides support for replaying historical data. """importjpyfromdeephavenimportDHError,timefromdeephaven._wrapperimportJObjectWrapperfromdeephaven.tableimportTablefromdeephaven.timeimportInstantLike_JReplayer=jpy.get_type("io.deephaven.engine.table.impl.replay.Replayer")
[docs]classTableReplayer(JObjectWrapper):"""The TableReplayer is used to replay historical data. Tables to be replayed are registered with the replayer. The resulting dynamic replay tables all update in sync, using the same simulated clock. Each registered table must contain a timestamp column. """j_object_type=_JReplayerdef__init__(self,start_time:InstantLike,end_time:InstantLike):"""Initializes the replayer. Args: start_time (InstantLike): replay start time. Integer values are nanoseconds since the Epoch. end_time (InstantLike): replay end time. Integer values are nanoseconds since the Epoch. Raises: DHError """start_time=time.to_j_instant(start_time)end_time=time.to_j_instant(end_time)self.start_time=start_timeself.end_time=end_timetry:self._j_replayer=_JReplayer(start_time,end_time)exceptExceptionase:raiseDHError(e,"failed to create a replayer.")frome@propertydefj_object(self)->jpy.JType:returnself._j_replayer
[docs]defadd_table(self,table:Table,col:str)->Table:"""Registers a table for replaying and returns the associated replay table. Args: table (Table): the table to be replayed col (str): column in the table containing timestamps Returns: a replay Table Raises: DHError """try:replay_table=Table(j_table=self._j_replayer.replay(table.j_table,col))returnreplay_tableexceptExceptionase:raiseDHError(e,"failed to add a historical table.")frome
[docs]defstart(self)->None:"""Starts replaying. Raises: DHError """try:self._j_replayer.start()exceptExceptionase:raiseDHError(e,"failed to start the replayer.")frome
[docs]defshutdown(self)->None:"""Shuts down and invalidates the replayer. After this call, the replayer can no longer be used."""try:self._j_replayer.shutdown()exceptExceptionase:raiseDHError(e,"failed to shutdown the replayer.")frome