|
|
@@ -0,0 +1,33 @@ |
|
|
|
"""NilmDB |
|
|
|
|
|
|
|
Object that represents a NILM database file""" |
|
|
|
|
|
|
|
import tables |
|
|
|
import time |
|
|
|
|
|
|
|
class NilmDB(object): |
|
|
|
def __init__(self, filename): |
|
|
|
# Open or create the file |
|
|
|
self.h5file = tables.openFile(filename, "a", "NILM Database") |
|
|
|
|
|
|
|
def close(self): |
|
|
|
self.h5file.close() |
|
|
|
|
|
|
|
def stream_list(self): |
|
|
|
"""Return list of paths to all Tables in the database""" |
|
|
|
iterator = self.h5file.walkNodes('/', 'Table') |
|
|
|
paths = [ x._v_pathname for x in iterator ] |
|
|
|
return sorted(paths) |
|
|
|
|
|
|
|
def stream_create(self, path, cls): |
|
|
|
"""Create a table at the given path, with the contents matching the |
|
|
|
given class description (e.g. nilmdb.PrepData)""" |
|
|
|
[ group, table ] = path.rsplit("/", 1) |
|
|
|
try: |
|
|
|
self.h5file.getNode(group) |
|
|
|
except tables.NoSuchNodeError as e: |
|
|
|
self.h5file.createGroup("/", group.lstrip('/')) |
|
|
|
|
|
|
|
self.h5file.createTable(group, table, cls) |
|
|
|
# group = h5file.createGroup("/", "newton", "Newton school") |
|
|
|
# table = h5file.createTable(group, "prep", PrepData, "Prep Data") |