Use half-open intervals for time ranges

This commit is contained in:
Marko Durkovic 2021-07-04 22:27:52 +02:00
parent 5175c349aa
commit 12acb677e6
5 changed files with 12 additions and 12 deletions

View File

@ -94,7 +94,7 @@ class Chunk(NamedTuple):
class TopicInfo(NamedTuple):
"""Topic information."""
conn_count: int
conncount: int
msgcount: int
msgdef: str
msgtype: str
@ -472,7 +472,7 @@ class Reader:
@property
def end_time(self) -> int:
"""Timestamp in nanoseconds of the latest message."""
"""Timestamp in nanoseconds after the latest message."""
return max(x.end_time for x in self.chunk_infos)
@property
@ -517,7 +517,7 @@ class Reader:
chunk_pos = header.get_uint64('chunk_pos')
start_time = header.get_time('start_time')
end_time = header.get_time('end_time')
end_time = header.get_time('end_time') + 1
count = header.get_uint32('count')
self.bio.seek(4, os.SEEK_CUR)

View File

@ -121,7 +121,7 @@ class Reader:
@property
def duration(self) -> int:
"""Duration in nanoseconds between earliest and latest messages."""
return self.metadata['duration']['nanoseconds']
return self.metadata['duration']['nanoseconds'] + 1
@property
def start_time(self) -> int:
@ -130,7 +130,7 @@ class Reader:
@property
def end_time(self) -> int:
"""Timestamp in nanoseconds of the latest message."""
"""Timestamp in nanoseconds after the latest message."""
return self.start_time + self.duration
@property

View File

@ -185,7 +185,7 @@ class Writer: # pylint: disable=too-many-instance-attributes
self.cursor = None
duration, start, count = self.conn.execute(
'SELECT max(timestamp) - min(timestamp) + 1, min(timestamp), count(*) FROM messages',
'SELECT max(timestamp) - min(timestamp), min(timestamp), count(*) FROM messages',
).fetchone()
self.conn.commit()

View File

@ -120,9 +120,9 @@ def bag(request: SubRequest, tmp_path: Path) -> Path:
def test_reader(bag: Path):
"""Test reader and deserializer on simple bag."""
with Reader(bag) as reader:
assert reader.duration == 42
assert reader.duration == 43
assert reader.start_time == 666
assert reader.end_time == 708
assert reader.end_time == 709
assert reader.message_count == 4
if reader.compression_mode:
assert reader.compression_format == 'zstd'

View File

@ -198,9 +198,9 @@ def test_reader(tmp_path): # pylint: disable=too-many-statements
)
with Reader(bag) as reader:
assert reader.message_count == 1
assert reader.duration == 0
assert reader.duration == 1
assert reader.start_time == 42 * 10**9
assert reader.end_time == 42 * 10**9
assert reader.end_time == 42 * 10**9 + 1
assert len(reader.topics.keys()) == 1
assert reader.topics['/topic0'].msgcount == 1
msgs = list(reader.messages())
@ -220,9 +220,9 @@ def test_reader(tmp_path): # pylint: disable=too-many-statements
)
with Reader(bag) as reader:
assert reader.message_count == 2
assert reader.duration == 5 * 10**9
assert reader.duration == 5 * 10**9 + 1
assert reader.start_time == 5 * 10**9
assert reader.end_time == 10 * 10**9
assert reader.end_time == 10 * 10**9 + 1
assert len(reader.topics.keys()) == 1
assert reader.topics['/topic0'].msgcount == 2
msgs = list(reader.messages())