Compare commits
2 Commits
nilmtools-
...
nilmtools-
Author | SHA1 | Date | |
---|---|---|---|
d23fa9ee78 | |||
2b9ecc6697 |
36
nilmtools/copy.py
Normal file
36
nilmtools/copy.py
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import nilmtools.filter
|
||||||
|
import nilmdb.client
|
||||||
|
import numpy as np
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def main():
|
||||||
|
f = nilmtools.filter.Filter()
|
||||||
|
parser = f.setup_parser("Copy a stream")
|
||||||
|
|
||||||
|
# Parse arguments
|
||||||
|
try:
|
||||||
|
args = f.parse_args()
|
||||||
|
except nilmtools.filter.MissingDestination as e:
|
||||||
|
print "Source is %s (%s)" % (e.src, e.layout)
|
||||||
|
print "Destination %s doesn't exist" % (e.dest)
|
||||||
|
print "You could make it with a command like:"
|
||||||
|
print " nilmtool create", e.dest, e.layout
|
||||||
|
raise SystemExit(1)
|
||||||
|
|
||||||
|
# Copy metadata
|
||||||
|
meta = f.client.stream_get_metadata(args.srcpath)
|
||||||
|
f.check_dest_metadata(meta)
|
||||||
|
|
||||||
|
# Copy all rows of data as ASCII strings
|
||||||
|
extractor = nilmdb.client.Client(args.url).stream_extract
|
||||||
|
inserter = nilmdb.client.Client(args.url).stream_insert_context
|
||||||
|
for (start, end) in f.intervals():
|
||||||
|
print "Processing", f.interval_string((start, end))
|
||||||
|
with inserter(args.destpath, start, end) as insert_ctx:
|
||||||
|
for row in extractor(args.srcpath, start, end):
|
||||||
|
insert_ctx.insert(row + "\n")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
@@ -145,7 +145,7 @@ class Filter(object):
|
|||||||
self._client.stream_update_metadata(self._args.destpath, data)
|
self._client.stream_update_metadata(self._args.destpath, data)
|
||||||
|
|
||||||
# Main processing helper
|
# Main processing helper
|
||||||
def process(self, function, rows, partial = True, args = None):
|
def process(self, function, rows, args = None, partial = False):
|
||||||
"""Process data in chunks of 'rows' data at a time.
|
"""Process data in chunks of 'rows' data at a time.
|
||||||
|
|
||||||
function: function to process the data
|
function: function to process the data
|
||||||
@@ -169,7 +169,6 @@ class Filter(object):
|
|||||||
inserter = nilmdb.client.Client(self._args.url).stream_insert_context
|
inserter = nilmdb.client.Client(self._args.url).stream_insert_context
|
||||||
src = self._args.srcpath
|
src = self._args.srcpath
|
||||||
dest = self._args.destpath
|
dest = self._args.destpath
|
||||||
islice = itertools.islice
|
|
||||||
|
|
||||||
# Figure out how to format output data
|
# Figure out how to format output data
|
||||||
dest_layout = self.destinfo[1].split('_')[1]
|
dest_layout = self.destinfo[1].split('_')[1]
|
||||||
|
1
setup.py
1
setup.py
@@ -69,6 +69,7 @@ setup(name='nilmtools',
|
|||||||
'console_scripts': [
|
'console_scripts': [
|
||||||
'nilm-decimate = nilmtools.decimate:main',
|
'nilm-decimate = nilmtools.decimate:main',
|
||||||
'nilm-insert = nilmtools.insert:main',
|
'nilm-insert = nilmtools.insert:main',
|
||||||
|
'nilm-copy = nilmtools.copy:main',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
zip_safe = False,
|
zip_safe = False,
|
||||||
|
Reference in New Issue
Block a user