Browse Source

Add nilm-copy tool

tags/nilmtools-0.3
Jim Paris 8 years ago
parent
commit
2b9ecc6697
3 changed files with 39 additions and 2 deletions
  1. +37
    -0
      nilmtools/copy.py
  2. +1
    -2
      nilmtools/filter.py
  3. +1
    -0
      setup.py

+ 37
- 0
nilmtools/copy.py View File

@@ -0,0 +1,37 @@
#!/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")
group = parser.add_argument_group("Copy options")

# 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()

+ 1
- 2
nilmtools/filter.py View File

@@ -145,7 +145,7 @@ class Filter(object):
self._client.stream_update_metadata(self._args.destpath, data)

# 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.

function: function to process the data
@@ -169,7 +169,6 @@ class Filter(object):
inserter = nilmdb.client.Client(self._args.url).stream_insert_context
src = self._args.srcpath
dest = self._args.destpath
islice = itertools.islice

# Figure out how to format output data
dest_layout = self.destinfo[1].split('_')[1]


+ 1
- 0
setup.py View File

@@ -69,6 +69,7 @@ setup(name='nilmtools',
'console_scripts': [
'nilm-decimate = nilmtools.decimate:main',
'nilm-insert = nilmtools.insert:main',
'nilm-copy = nilmtools.copy:main',
],
},
zip_safe = False,


Loading…
Cancel
Save