Skip to content

Commit fce04bf

Browse files
committed
fix smart_size in _win.py, stream_snapshot method
1 parent 665f926 commit fce04bf

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

python/tosdb/_win.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -532,16 +532,22 @@ def stream_snapshot(self, item, topic, date_time=False, end=-1, beg=0,
532532
if end < 0:
533533
end += self._block_size
534534
if beg < 0:
535-
beg += self._block_size
536-
if smart_size:
537-
end = min(end, self.stream_occupancy(item, topic) - 1)
535+
beg += self._block_size
538536
size = (end - beg) + 1
539537
if beg < 0 \
540538
or end < 0 \
541539
or beg >= self._block_size \
542540
or end >= self._block_size \
543541
or size <= 0:
544542
raise TOSDB_IndexError("invalid 'beg' and/or 'end' index value(s)")
543+
544+
if smart_size:
545+
so = self.stream_occupancy(item, topic)
546+
if so == 0 or so <= beg:
547+
return []
548+
end = min(end, so - 1)
549+
beg = min(beg, so - 1)
550+
size = (end - beg) + 1
545551

546552
dtss = (_DateTimeStamp * size)()
547553
tbits = type_bits(topic)
@@ -635,7 +641,7 @@ def stream_snapshot_from_marker(self, item, topic, date_time=False, beg=0,
635641
date_time: (True/False) attempt to retrieve a TOSDB_DateTime object
636642
beg: index of most recent data-point (beginning of the snapshot)
637643
margin_of_safety: (True/False) error margin for async stream growth
638-
throw_if_data_loss: (True/False) how to handle error states (see above)
644+
throw_if_data_lost: (True/False) how to handle error states (see above)
639645
data_str_max: the maximum length of string data returned
640646
641647
if beg > internal marker value: returns -> None

0 commit comments

Comments
 (0)