You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

34 lines
1.1 KiB

  1. """NilmDB
  2. Object that represents a NILM database file"""
  3. import tables
  4. import time
  5. class NilmDB(object):
  6. def __init__(self, filename):
  7. # Open or create the file
  8. self.h5file = tables.openFile(filename, "a", "NILM Database")
  9. def close(self):
  10. self.h5file.close()
  11. def stream_list(self):
  12. """Return list of paths to all Tables in the database"""
  13. iterator = self.h5file.walkNodes('/', 'Table')
  14. paths = [ x._v_pathname for x in iterator ]
  15. return sorted(paths)
  16. def stream_create(self, path, cls):
  17. """Create a table at the given path, with the contents matching the
  18. given class description (e.g. nilmdb.PrepData)"""
  19. [ group, table ] = path.rsplit("/", 1)
  20. try:
  21. self.h5file.getNode(group)
  22. except tables.NoSuchNodeError as e:
  23. self.h5file.createGroup("/", group.lstrip('/'))
  24. self.h5file.createTable(group, table, cls)
  25. # group = h5file.createGroup("/", "newton", "Newton school")
  26. # table = h5file.createTable(group, "prep", PrepData, "Prep Data")