Skip to content
Snippets Groups Projects
Commit 57464b06 authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

get_current_value added

parent 1e8ecdd5
No related branches found
No related tags found
No related merge requests found
......@@ -17,7 +17,7 @@ jobs:
name: Install necessary modules
- run:
command: |
sudo python setup.py test
sudo coverage run setup.py test
name: Test
workflows:
......
[run]
branch=1
plugins = Cython.Coverage
source=
tempsdb
concurrency=thread
omit=
tests/*
.eggs/*
setup.py
tempsdb/__init__.py
[report]
include=
tempsdb/*
......@@ -5,7 +5,7 @@ __pycache__/
# C extensions
*.so
tempsdb/__bootstrap__.pyx
# Distribution / packaging
.Python
build/
......
......@@ -16,7 +16,7 @@ So no variable encoding for you!
## v0.3
* _TBA_
* added `TimeSeries.get_current_value`
## v0.2
......
......@@ -19,15 +19,16 @@ def find_pyx(*path) -> tp.List[str]:
# Extension('tempsdb.series', ['tempsdb/series.pyx']),
# Extension('tempsdb.iterators', ['tempsdb/iterators.pyx'])]
#
directives = {'language_level': '3'}
if 'CI' in os.environ:
directives.update(profile=True, linetrace=True)
setup(name='tempsdb',
version='0.3_a1',
packages=['tempsdb'],
install_requires=['satella>=2.14.21', 'ujson'],
ext_modules=build([Multibuild('tempsdb', find_pyx('tempsdb')), ],
compiler_directives={
'language_level': '3',
}),
compiler_directives=directives),
# ext_modules=cythonize(extensions,
# gdb_debug=True,
# compiler_directives={
......
......@@ -8,6 +8,14 @@ cdef class Iterator:
"""
Iterator that allows iterating through result.
Can be used as a context manager:
>>> with series.iterate_range(0, 5000) as it:
>>> for timestamp, value in it:
>>> ...
It will close itself automatically.
At most basic this implements an iterator interface, iterating over
tp.Tuple[int, bytes] - timestamp and data
......@@ -25,6 +33,12 @@ cdef class Iterator:
self.is_first = False
self.is_last = False
def __enter__(self):
return self
def __exit__(self, exc_type, exc_val, exc_tb):
self.close()
def __del__(self):
self.close()
......
......@@ -37,6 +37,7 @@ cdef class TimeSeries:
cdef unsigned int get_index_of_chunk_for(self, unsigned long long timestamp)
cpdef int trim(self, unsigned long long timestamp) except -1
cpdef unsigned long open_chunks_ram_size(self)
cpdef tuple get_current_value(self)
cdef inline int get_references_for(self, unsigned long long timestamp):
return self.refs_chunks.get(timestamp, 0)
......
......@@ -23,6 +23,26 @@ cdef class TimeSeries:
:ivar name: name of the series (str)
"""
cpdef tuple get_current_value(self):
"""
Return latest value of this series
.. versionadded:: 0.3
:return: tuple of (timestamp, value)
:rtype: tp.Tuple[int, bytes]
:raises ValueError: series has no data
"""
if self.last_chunk is None:
raise ValueError('No data in series')
cdef:
Iterator it = self.iterate_range(self.last_chunk.max_ts, self.last_chunk.max_ts)
tuple tpl = it.next()
try:
return tpl
finally:
it.close()
def __init__(self, path: str, name: str, use_descriptor_based_access: bool = False):
self.descriptor_based_access = use_descriptor_based_access
self.mpm = None
......
......@@ -10,6 +10,14 @@ class TestDB(unittest.TestCase):
series = create_series('test3', 'test3', 10, 4096)
for i in range(8000):
series.append(i, b'\x00'*10)
self.assertEqual(series.get_current_value(), (i, b'\x00'*10))
with series.iterate_range(i, i) as it:
lst = list(it)
self.assertEqual(len(lst), 1)
self.assertEqual(lst[0][0], i)
series.trim(4100)
self.assertEqual(len(os.listdir('test3')), 2)
......
FROM python:3.8
RUN pip install satella snakehouse nose2 wheel ujson
RUN pip install satella snakehouse nose2 wheel ujson coverage
ADD tempsdb /app/tempsdb
ADD setup.py /app/setup.py
ADD .coveragerc /app/.coveragerc
ADD setup.cfg /app/setup.cfg
WORKDIR /app
ENV CI=true
RUN python setup.py build_ext --inplace
ADD tests /app/tests
CMD ["nose2", "-vv"]
CMD ["coverage", "run", "-m", "nose2", "-vv"]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment