Browse Source

Have server verify that start <= end before creating intervals

Also rename _fill_in_limits to _check_user_times
tags/nilmdb-1.1^2
Jim Paris 9 years ago
parent
commit
db7211c3a9
1 changed files with 6 additions and 4 deletions
  1. +6
    -4
      nilmdb/server/nilmdb.py

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

@@ -142,11 +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):
def _check_user_times(self, start, end):
if start is None:
start = -1e12
if end is None:
end = 1e12
if start >= end:
raise NilmDBError("start must precede end")
return (start, end)

@nilmdb.utils.lru_cache(size = 16)
@@ -310,7 +312,7 @@ class NilmDB(object):
"""
stream_id = self._stream_id(path)
intervals = self._get_intervals(stream_id)
(start, end) = self._fill_in_limits(start, end)
(start, end) = self._check_user_times(start, end)
requested = Interval(start, end)
result = []
for n, i in enumerate(intervals.intersection(requested)):
@@ -483,7 +485,7 @@ class NilmDB(object):
stream_id = self._stream_id(path)
table = self.data.getnode(path)
intervals = self._get_intervals(stream_id)
(start, end) = self._fill_in_limits(start, end)
(start, end) = self._check_user_times(start, end)
requested = Interval(start, end)
result = []
matched = 0
@@ -530,7 +532,7 @@ class NilmDB(object):
stream_id = self._stream_id(path)
table = self.data.getnode(path)
intervals = self._get_intervals(stream_id)
(start, end) = self._fill_in_limits(start, end)
(start, end) = self._check_user_times(start, end)
to_remove = Interval(start, end)
removed = 0



Loading…
Cancel
Save