Skip to content

Replay

JsonReplaySource

JsonReplaySource replays a recorded json dataset

__init__(self, file_path, **kwargs) special

Initializes the source

Parameters:

Name Type Description Default
file_path str

file path to the json file

required
Source code in multisensor_pipeline/modules/persistence/replay.py
def __init__(self, file_path: str, **kwargs):
    """
    Initializes the source
    Args:
        file_path: file path to the json file
    """
    super(JsonReplaySource, self).__init__(**kwargs)
    self._file_path = file_path
    self._file_handle = None

on_start(self)

Custom initialization

Source code in multisensor_pipeline/modules/persistence/replay.py
def on_start(self):
    self._file_handle = open(self._file_path, mode="r")

on_stop(self)

Stopping and cleanup

Source code in multisensor_pipeline/modules/persistence/replay.py
def on_stop(self):
    """
    Stopping and cleanup
    """
    self._file_handle.close()

on_update(self)

Iterates over the entries in the json file and returns a dataframe. Stops if EOF is reached

Source code in multisensor_pipeline/modules/persistence/replay.py
def on_update(self) -> Optional[MSPDataFrame]:
    """
    Iterates over the entries in the json file and returns a dataframe. Stops if EOF is reached
    """
    line = self._file_handle.readline()
    if line != '':
        return MSPDataFrame(**json.loads(s=line, cls=MSPDataFrame.JsonDecoder))

    # EOF is reached -> auto-stop (you can alternatively return None)
    self._auto_stop()