nilmdb/pytables-test/test-indexing.py
Jim Paris ef2db81d11 Misc
git-svn-id: https://bucket.mit.edu/svn/nilm/nilmdb@10367 ddd99763-3ecb-0310-9145-efcb8ce7c51f
2012-02-08 18:01:05 +00:00

55 lines
1.3 KiB
Python

#!/usr/bin/python
from tables import *
import re
import time
# A class to describe our data
class PrepData(IsDescription):
timestamp = Int64Col()
p1 = Float32Col()
q1 = Float32Col()
p3 = Float32Col()
q3 = Float32Col()
p5 = Float32Col()
q5 = Float32Col()
p7 = Float32Col()
q7 = Float32Col()
filename = "test.h5"
h5file = openFile(filename, mode = "w", title = "NILM Test")
group = h5file.createGroup("/", "newton", "Newton school")
table = h5file.createTable(group, "prep", PrepData, "Prep Data", expectedrows = 120 * 86400 * 90)
table.cols.timestamp.createIndex()
for i in range(0, 80):
# Open file
data = open("data/alldata")
count = 0
oldtime = time.time()
prep = table.row
for line in data:
count = count + 1
if count % 1000000 == 0:
print str(i) + ": " + str((time.time() - oldtime)) + ", total " + str(count/1000000) + "m lines"
oldtime = time.time()
v = re.split('\s+', line)
prep['timestamp'] = int(v[0]) + 500000000 * i
prep['p1'] = v[1]
prep['q1'] = v[2]
prep['p3'] = v[3]
prep['q3'] = v[4]
prep['p5'] = v[5]
prep['q5'] = v[6]
prep['p7'] = v[7]
prep['q7'] = v[8]
prep.append()
data.close()
h5file.close()