Move indices to dedicated attribute

This commit is contained in:
Marko Durkovic 2022-04-12 17:03:04 +02:00
parent b924fd4642
commit 42243eac2d
3 changed files with 10 additions and 10 deletions

View File

@ -87,7 +87,6 @@ def downgrade_connection(rconn: Connection2) -> Connection1:
md5sum, md5sum,
None, None,
int('durability: 1' in rconn.offered_qos_profiles), int('durability: 1' in rconn.offered_qos_profiles),
[],
) )
@ -140,7 +139,7 @@ def convert_2to1(src: Path, dst: Path) -> None:
None, None,
) )
# yapf: enable # yapf: enable
connmap[rconn.id] = existing if existing else writer.add_connection(*candidate[1:-1]) connmap[rconn.id] = existing if existing else writer.add_connection(*candidate[1:])
for rconn, timestamp, data in reader.messages(): for rconn, timestamp, data in reader.messages():
data = cdr_to_ros1(data, rconn.msgtype) data = cdr_to_ros1(data, rconn.msgtype)

View File

@ -60,7 +60,6 @@ class Connection(NamedTuple):
md5sum: str md5sum: str
callerid: Optional[str] callerid: Optional[str]
latching: Optional[int] latching: Optional[int]
indexes: list[IndexData]
class ChunkInfo(NamedTuple): class ChunkInfo(NamedTuple):
@ -348,6 +347,8 @@ class Reader:
""" """
# pylint: disable=too-many-instance-attributes
def __init__(self, path: Union[str, Path]): def __init__(self, path: Union[str, Path]):
"""Initialize. """Initialize.
@ -364,12 +365,13 @@ class Reader:
self.bio: Optional[BinaryIO] = None self.bio: Optional[BinaryIO] = None
self.connections: dict[int, Connection] = {} self.connections: dict[int, Connection] = {}
self.indexes: dict[int, list[IndexData]]
self.chunk_infos: list[ChunkInfo] = [] self.chunk_infos: list[ChunkInfo] = []
self.chunks: dict[int, Chunk] = {} self.chunks: dict[int, Chunk] = {}
self.current_chunk: tuple[int, BinaryIO] = (-1, BytesIO()) self.current_chunk: tuple[int, BinaryIO] = (-1, BytesIO())
self.topics: dict[str, TopicInfo] = {} self.topics: dict[str, TopicInfo] = {}
def open(self) -> None: # pylint: disable=too-many-branches,too-many-locals def open(self) -> None: # pylint: disable=too-many-locals
"""Open rosbag and read metadata.""" """Open rosbag and read metadata."""
try: try:
self.bio = self.path.open('rb') self.bio = self.path.open('rb')
@ -420,9 +422,10 @@ class Reader:
cid, index = self.read_index_data(chunk_info.pos) cid, index = self.read_index_data(chunk_info.pos)
indexes[cid].append(index) indexes[cid].append(index)
for cid, connection in self.connections.items(): self.indexes = {
connection.indexes.extend(heapq.merge(*indexes[cid], key=lambda x: x.time)) cid: list(heapq.merge(*x, key=lambda x: x.time)) for cid, x in indexes.items()
assert connection.indexes }
assert all(self.indexes[x] for x in self.connections)
self.topics = {} self.topics = {}
for topic, group in groupby( for topic, group in groupby(
@ -498,7 +501,6 @@ class Reader:
md5sum, md5sum,
callerid, callerid,
latching, latching,
[],
) )
def read_chunk_info(self) -> ChunkInfo: def read_chunk_info(self) -> ChunkInfo:
@ -605,7 +607,7 @@ class Reader:
if not connections: if not connections:
connections = self.connections.values() connections = self.connections.values()
indexes = [x.indexes for x in connections] indexes = [self.indexes[x.cid] for x in connections]
for entry in heapq.merge(*indexes): for entry in heapq.merge(*indexes):
if start and entry.time < start: if start and entry.time < start:
continue continue

View File

@ -251,7 +251,6 @@ class Writer:
md5sum, md5sum,
callerid, callerid,
latching, latching,
[],
) )
if any(x[1:] == connection[1:] for x in self.connections.values()): if any(x[1:] == connection[1:] for x in self.connections.values()):