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

added `get_first_entry_for`

parent 2d1dc33c
No related branches found
No related tags found
No related merge requests found
......@@ -18,6 +18,8 @@ So no variable encoding for you!
* added `get_open_series`
* added `get_all_series`
* added `get_first_entry_for`
* added `close_all_open_series`
## v0.1
......
......@@ -21,7 +21,7 @@ def find_pyx(*path) -> tp.List[str]:
#
setup(name='tempsdb',
version='0.2_a4',
version='0.2_a5',
packages=['tempsdb'],
install_requires=['satella>=2.14.21', 'ujson'],
ext_modules=build([Multibuild('tempsdb', find_pyx('tempsdb')), ],
......
......@@ -17,6 +17,7 @@ cdef class Database:
cpdef list get_open_series(self)
cpdef list get_all_series(self)
cpdef int close_all_open_series(self) except -1
cpdef unsigned long long get_first_entry_for(self, str name)
cpdef Database create_database(str path)
......@@ -88,6 +88,38 @@ cdef class Database:
self.open_series = {}
return 0
cpdef unsigned long long get_first_entry_for(self, str name):
"""
Get first timestamp stored in a particular series without opening it
.. versionadded:: 0.2
:param name: series name
:type name: str
:return: first timestamp stored in this series
:rtype: int
:raises DoesNotExist: series does not exist
:raises ValueError: timestamp does not have any data
"""
cdef str path = os.path.join(self.path, name)
if not os.path.isdir(path):
raise DoesNotExist('series does not exist')
cdef:
unsigned long long minimum_ts = 0xFFFFFFFFFFFFFFFF
str name
list files = os.listdir(path)
unsigned long long candidate_ts
if len(files) == 1:
raise ValueError('Timestamp does not have any data')
for name in files:
try:
candidate_ts = int(name)
except ValueError:
continue
if candidate_ts < minimum_ts:
minimum_ts = candidate_ts
return minimum_ts
cpdef list get_all_series(self):
"""
Stream all series available within this database
......
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