Browse Source

Mics

git-svn-id: https://bucket.mit.edu/svn/nilm/nilmdb-new@10326 ddd99763-3ecb-0310-9145-efcb8ce7c51f
tags/bxinterval-last
Jim Paris 10 years ago
commit
dfaeddefa2
8 changed files with 133 additions and 0 deletions
  1. +5
    -0
      Makefile
  2. +4
    -0
      README.txt
  3. +3
    -0
      nilmdb/__init__.py
  4. +34
    -0
      nilmdb/layout.py
  5. +33
    -0
      nilmdb/nilmdb.py
  6. +9
    -0
      setup.cfg
  7. BIN
      tests/test.db
  8. +45
    -0
      tests/test_nilmdb.py

+ 5
- 0
Makefile View File

@@ -0,0 +1,5 @@
all:
nosetests

clean:
find . -name '*pyc' | xargs rm

+ 4
- 0
README.txt View File

@@ -0,0 +1,4 @@
To install,

python setup.py install


+ 3
- 0
nilmdb/__init__.py View File

@@ -0,0 +1,3 @@
# empty
from nilmdb import NilmDB
from layout import *

+ 34
- 0
nilmdb/layout.py View File

@@ -0,0 +1,34 @@
import tables

# Table description for typical prep output
PrepData = {
'timestamp': tables.Int64Col(),
'p1': tables.Float32Col(),
'q1': tables.Float32Col(),
'p3': tables.Float32Col(),
'q3': tables.Float32Col(),
'p5': tables.Float32Col(),
'q5': tables.Float32Col(),
'p7': tables.Float32Col(),
'q7': tables.Float32Col(),
}

# Table description for raw data
RawData = {
'timestamp': tables.Int64Col(),
'va': tables.Int16Col(),
'vb': tables.Int16Col(),
'vc': tables.Int16Col(),
'ia': tables.Int16Col(),
'ib': tables.Int16Col(),
'ic': tables.Int16Col(),
}

# Table description for raw data plus 60 Hz notched current
RawNotchedData = dict(RawData)
RawNotchedData.update({
'notch_ia': tables.Int16Col(),
'notch_ib': tables.Int16Col(),
'notch_ic': tables.Int16Col(),
})


+ 33
- 0
nilmdb/nilmdb.py View File

@@ -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")

+ 9
- 0
setup.cfg View File

@@ -0,0 +1,9 @@
[nosetests]
nocapture=1
with-coverage=1
cover-inclusive=1
cover-package=nilmdb
cover-erase=1
stop=1
verbosity=2


BIN
tests/test.db View File


+ 45
- 0
tests/test_nilmdb.py View File

@@ -0,0 +1,45 @@
import nilmdb
from nilmdb import NilmDB

from nose.tools import assert_raises
import itertools
import os
import sys
import atexit

testdb = "tests/test.db"

#@atexit.register
#def cleanup():
# os.unlink(testdb)

def test_NilmDB():
try:
os.unlink(testdb)
except:
pass

with assert_raises(IOError):
nilmdb.NilmDB("/nonexistant-db/foo")

db = nilmdb.NilmDB(testdb)
db.close()
db = nilmdb.NilmDB(testdb)

def test_stream():
db = nilmdb.NilmDB(testdb)
assert(db.stream_list() == [])

db.stream_create("/newton/prep", nilmdb.layout.PrepData)
db.stream_create("/newton/raw", nilmdb.layout.RawData)
db.stream_create("/newton/rawnotch", nilmdb.layout.RawNotchedData)

# Verify we got 3 streams
assert(db.stream_list() == [ "/newton/prep",
"/newton/raw",
"/newton/rawnotch" ])

# Verify that columns were made right
assert(len(db.h5file.getNode("/newton/prep").cols) == 9)
assert(len(db.h5file.getNode("/newton/raw").cols) == 7)
assert(len(db.h5file.getNode("/newton/rawnotch").cols) == 10)

Loading…
Cancel
Save