Browse Source

Fix errors with calculating limits when start==end==None

This also has the effect of now handling negative timestamps
correctly.
tags/nilmdb-1.1^2
Jim Paris 9 years ago
parent
commit
c6d57cf5c3
1 changed files with 13 additions and 6 deletions
  1. +13
    -6
      nilmdb/server/nilmdb.py

+ 13
- 6
nilmdb/server/nilmdb.py View File

@@ -142,6 +142,13 @@ class NilmDB(object):
with self.con:
cur.execute("PRAGMA user_version = {v:d}".format(v=version))

def _fill_in_limits(self, start, end):
if start is None:
start = -1e12
if end is None:
end = 1e12
return (start, end)

@nilmdb.utils.lru_cache(size = 16)
def _get_intervals(self, stream_id):
"""
@@ -303,7 +310,8 @@ class NilmDB(object):
"""
stream_id = self._stream_id(path)
intervals = self._get_intervals(stream_id)
requested = Interval(start or 0, end or 1e12)
(start, end) = self._fill_in_limits(start, end)
requested = Interval(start, end)
result = []
for n, i in enumerate(intervals.intersection(requested)):
if n >= self.max_results:
@@ -475,7 +483,8 @@ class NilmDB(object):
stream_id = self._stream_id(path)
table = self.data.getnode(path)
intervals = self._get_intervals(stream_id)
requested = Interval(start or 0, end or 1e12)
(start, end) = self._fill_in_limits(start, end)
requested = Interval(start, end)
result = []
matched = 0
remaining = self.max_results
@@ -521,12 +530,10 @@ class NilmDB(object):
stream_id = self._stream_id(path)
table = self.data.getnode(path)
intervals = self._get_intervals(stream_id)
to_remove = Interval(start or 0, end or 1e12)
(start, end) = self._fill_in_limits(start, end)
to_remove = Interval(start, end)
removed = 0

if start == end:
return 0

# Can't remove intervals from within the iterator, so we need to
# remember what's currently in the intersection now.
all_candidates = list(intervals.intersection(to_remove, orig = True))


Loading…
Cancel
Save