|
|
@@ -383,30 +383,18 @@ class NilmDB(object): |
|
|
|
con.execute("DELETE FROM ranges WHERE stream_id=?", (stream_id,)) |
|
|
|
con.execute("DELETE FROM streams WHERE id=?", (stream_id,)) |
|
|
|
|
|
|
|
def stream_insert(self, path, parser, old_timestamp = None): |
|
|
|
def stream_insert(self, path, start, end, data): |
|
|
|
"""Insert new data into the database. |
|
|
|
path: Path at which to add the data |
|
|
|
parser: nilmdb.layout.Parser instance full of data to insert |
|
|
|
start: Starting timestamp |
|
|
|
end: Ending timestamp |
|
|
|
data: Rows of data, to be passed to PyTable's table.append |
|
|
|
method. E.g. nilmdb.layout.Parser.data |
|
|
|
""" |
|
|
|
if (not parser.min_timestamp or not parser.max_timestamp or |
|
|
|
not len(parser.data)): |
|
|
|
raise StreamError("no data provided") |
|
|
|
|
|
|
|
# If we were provided with an old timestamp, the expectation |
|
|
|
# is that the client has a contiguous block of time it is sending, |
|
|
|
# but it's doing it over multiple calls to stream_insert. |
|
|
|
# old_timestamp is the max_timestamp of the previous insert. |
|
|
|
# To make things continuous, use that as our starting timestamp |
|
|
|
# instead of what the parser found. |
|
|
|
if old_timestamp: |
|
|
|
min_timestamp = old_timestamp |
|
|
|
else: |
|
|
|
min_timestamp = parser.min_timestamp |
|
|
|
|
|
|
|
# First check for basic overlap using timestamp info given. |
|
|
|
stream_id = self._stream_id(path) |
|
|
|
iset = self._get_intervals(stream_id) |
|
|
|
interval = Interval(min_timestamp, parser.max_timestamp) |
|
|
|
interval = Interval(start, end) |
|
|
|
if iset.intersects(interval): |
|
|
|
raise OverlapError("new data overlaps existing data at range: " |
|
|
|
+ str(iset & interval)) |
|
|
@@ -414,7 +402,7 @@ class NilmDB(object): |
|
|
|
# Insert the data into pytables |
|
|
|
table = self.h5file.getNode(path) |
|
|
|
row_start = table.nrows |
|
|
|
table.append(parser.data) |
|
|
|
table.append(data) |
|
|
|
row_end = table.nrows |
|
|
|
table.flush() |
|
|
|
|
|
|
|