2012-01-20 17:41:32 -05:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
from tables import *
|
|
|
|
import re
|
|
|
|
import time
|
|
|
|
|
|
|
|
# A class to describe our data
|
|
|
|
class PrepData(IsDescription):
|
2012-02-08 13:01:05 -05:00
|
|
|
timestamp = Int64Col()
|
2012-01-20 17:41:32 -05:00
|
|
|
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")
|
2012-02-08 13:01:05 -05:00
|
|
|
table = h5file.createTable(group, "prep", PrepData, "Prep Data", expectedrows = 120 * 86400 * 90)
|
2012-01-20 17:41:32 -05:00
|
|
|
|
|
|
|
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)
|
2012-02-08 13:01:05 -05:00
|
|
|
prep['timestamp'] = int(v[0]) + 500000000 * i
|
2012-01-20 17:41:32 -05:00
|
|
|
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()
|
|
|
|
|
|
|
|
|
|
|
|
|