|
@@ -142,6 +142,13 @@ class NilmDB(object): |
|
|
with self.con: |
|
|
with self.con: |
|
|
cur.execute("PRAGMA user_version = {v:d}".format(v=version)) |
|
|
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) |
|
|
@nilmdb.utils.lru_cache(size = 16) |
|
|
def _get_intervals(self, stream_id): |
|
|
def _get_intervals(self, stream_id): |
|
|
""" |
|
|
""" |
|
@@ -303,7 +310,8 @@ class NilmDB(object): |
|
|
""" |
|
|
""" |
|
|
stream_id = self._stream_id(path) |
|
|
stream_id = self._stream_id(path) |
|
|
intervals = self._get_intervals(stream_id) |
|
|
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 = [] |
|
|
result = [] |
|
|
for n, i in enumerate(intervals.intersection(requested)): |
|
|
for n, i in enumerate(intervals.intersection(requested)): |
|
|
if n >= self.max_results: |
|
|
if n >= self.max_results: |
|
@@ -475,7 +483,8 @@ class NilmDB(object): |
|
|
stream_id = self._stream_id(path) |
|
|
stream_id = self._stream_id(path) |
|
|
table = self.data.getnode(path) |
|
|
table = self.data.getnode(path) |
|
|
intervals = self._get_intervals(stream_id) |
|
|
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 = [] |
|
|
result = [] |
|
|
matched = 0 |
|
|
matched = 0 |
|
|
remaining = self.max_results |
|
|
remaining = self.max_results |
|
@@ -521,12 +530,10 @@ class NilmDB(object): |
|
|
stream_id = self._stream_id(path) |
|
|
stream_id = self._stream_id(path) |
|
|
table = self.data.getnode(path) |
|
|
table = self.data.getnode(path) |
|
|
intervals = self._get_intervals(stream_id) |
|
|
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 |
|
|
removed = 0 |
|
|
|
|
|
|
|
|
if start == end: |
|
|
|
|
|
return 0 |
|
|
|
|
|
|
|
|
|
|
|
# Can't remove intervals from within the iterator, so we need to |
|
|
# Can't remove intervals from within the iterator, so we need to |
|
|
# remember what's currently in the intersection now. |
|
|
# remember what's currently in the intersection now. |
|
|
all_candidates = list(intervals.intersection(to_remove, orig = True)) |
|
|
all_candidates = list(intervals.intersection(to_remove, orig = True)) |
|
|